javax.jcr.query.Query.setOffset()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(217)

本文整理了Java中javax.jcr.query.Query.setOffset方法的一些代码示例,展示了Query.setOffset的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.setOffset方法的具体详情如下:
包路径:javax.jcr.query.Query
类名称:Query
方法名:setOffset

Query.setOffset介绍

[英]Sets the start offset of the result set to offset.
[中]将结果集的起始偏移量设置为[$0$]。

代码示例

代码示例来源:origin: apache/jackrabbit

/** {@inheritDoc} */
public void setOffset(long offset) throws RemoteException {
  query.setOffset(offset);
}

代码示例来源:origin: net.adamcin.oakpal/oakpal-core

@Override
public void setOffset(long offset) {
  delegate.setOffset(offset);
}

代码示例来源:origin: brix-cms/brix-cms

public void execute() throws Exception {
    getDelegate().setOffset(offset);
  }
});

代码示例来源:origin: brix-cms/brix-cms

public void setOffset(long offset) {
  getDelegate().setOffset(offset);
}

代码示例来源:origin: apache/jackrabbit-oak

protected void processResultsOffsetPagination(@NotNull final QueryManager qm,
    ExecutionContext context) throws RepositoryException {
  for (int page = 0; page < PAGES; page++) {
    Query query = getQuery(qm, context);
    query.setLimit(LIMIT);
    query.setOffset(page * LIMIT);
    iterate(query);
  }
}

代码示例来源:origin: info.magnolia.ui/magnolia-ui-framework

protected QueryResult executeQuery(String statement, String language, int limit, int offset) throws RepositoryException {
  final Session jcrSession = MgnlContext.getJCRSession(WORKSPACE_NAME);
  final QueryManager jcrQueryManager = jcrSession.getWorkspace().getQueryManager();
  final Query query = jcrQueryManager.createQuery(statement, language);
  if (limit > 0) {
    query.setLimit(limit);
  }
  if (offset >= 0) {
    query.setOffset(offset);
  }
  logger.debug("Executing query against workspace [{}] with statement [{}] and limit {} and offset {}...", new Object[]{WORKSPACE_NAME, statement, limit, offset});
  long start = System.currentTimeMillis();
  final QueryResult result = query.execute();
  logger.debug("Query execution took {} ms", System.currentTimeMillis() - start);
  return result;
}

代码示例来源:origin: info.magnolia/magnolia-module-standard-templating-kit

private QueryResult doQuery(String queryString, long limit, long offset) throws RepositoryException {
    try {
      final Session jcrSession = MgnlContext.getJCRSession(repository);
      final QueryManager jcrQueryManager = jcrSession.getWorkspace().getQueryManager();
      final Query query = jcrQueryManager.createQuery(queryString, Query.JCR_SQL2);
      query.setLimit(limit);
      query.setOffset(offset);

      log.debug("Executing query against workspace [{}] with statement [{}] and limit {} and offset {}...", repository, queryString, limit, offset);
      long start = System.currentTimeMillis();
      QueryResult qr = query.execute();
      log.debug("Query execution took {} ms", System.currentTimeMillis() - start);
      return qr;

    } catch (RepositoryException e) {
      log.error("An error occurred while performing a query against workspace [{}] with statement [{}] and limit {} and offset {}.", repository, queryString, limit, offset);
      throw new RepositoryException(e);
    }
  }
}

代码示例来源:origin: apache/jackrabbit

public void testSetOffset() throws RepositoryException {
    testRootNode.addNode(nodeName1, testNodeType);
    testRootNode.addNode(nodeName2, testNodeType);
    testRootNode.addNode(nodeName3, testNodeType);
    superuser.save();
    for (int i = 0; i < 5; i++) {
      Query query = qf.createQuery(
          qf.selector(testNodeType, "s"),
          qf.descendantNode("s", testRoot),
          null,
          null
      );
      query.setOffset(i);
      long expected = Math.max(3 - i, 0);
      assertEquals("Wrong numer of results", expected,
          getSize(query.execute().getNodes()));
    }
  }
}

代码示例来源:origin: apache/jackrabbit

public void testOffset() throws Exception {
  query.setOffset(0);
  QueryResult result = query.execute();
  checkResult(result, new Node[] { node1, node2, node3 });
  query.setOffset(1);
  result = query.execute();
  checkResult(result, new Node[] { node2, node3 });
  query.setOffset(2);
  result = query.execute();
  checkResult(result, new Node[] { node3 });
}

代码示例来源:origin: apache/jackrabbit

public void testSimplePagination() throws Exception {
  List<String> expected = new ArrayList<String>(c);
  Query q = newQuery();
  for (int i = 0; i < c.size(); i++) {
    q.setOffset(i);
    q.setLimit(1);
    List<String> out = qrToPaths(q.execute());
    assertEquals(1, out.size());
    assertTrue(expected.remove(out.get(0)));
  }
  assertTrue(expected.isEmpty());
}

代码示例来源:origin: apache/jackrabbit

public void testLimitGtSize() throws Exception {
  List<String> expected = new ArrayList<String>(c);
  Query q = newQuery();
  q.setOffset(0);
  q.setLimit(c.size() * 2);
  List<String> out = qrToPaths(q.execute());
  assertEquals(c.size(), out.size());
  for (String s : out) {
    assertTrue(expected.remove(s));
  }
  assertTrue(expected.isEmpty());
}

代码示例来源:origin: apache/jackrabbit

public void testLimitEqSize() throws Exception {
  List<String> expected = new ArrayList<String>(c);
  Query q = newQuery();
  q.setOffset(0);
  q.setLimit(c.size());
  List<String> out = qrToPaths(q.execute());
  assertEquals(c.size(), out.size());
  for (String s : out) {
    assertTrue(expected.remove(s));
  }
  assertTrue(expected.isEmpty());
}

代码示例来源:origin: apache/jackrabbit

public void testOffsetEqSize() throws Exception {
  Query q = newQuery();
  q.setOffset(c.size() - 1);
  List<String> out = qrToPaths(q.execute());
  assertEquals(1, out.size());
}

代码示例来源:origin: apache/jackrabbit

public void testOffsetGtSize() throws Exception {
  Query q = newQuery();
  q.setOffset(c.size() * 2);
  List<String> out = qrToPaths(q.execute());
  assertTrue(out.isEmpty());
}

代码示例来源:origin: org.apache.jackrabbit/jackrabbit-spi2jcr

/**
 * {@inheritDoc}
 */
public QueryInfo executeQuery(SessionInfo sessionInfo, String statement, String language, Map<String, String> namespaces, long limit, long offset, Map<String, QValue> values) throws RepositoryException {
  SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
  Query query = createQuery(sInfo.getSession(), statement,
      language, namespaces);
  if (limit != -1) {
    query.setLimit(limit);
  }
  if (offset != -1) {
    query.setOffset(offset);
  }
  if (values != null && !values.isEmpty()) {
    for (Map.Entry<String, QValue> entry : values.entrySet()) {
      Value value = ValueFormat.getJCRValue(entry.getValue(), sInfo.getNamePathResolver(), sInfo.getSession().getValueFactory());
      query.bindValue(entry.getKey(), value);
    }
  }
  return new QueryInfoImpl(query.execute(), idFactory,
      sInfo.getNamePathResolver(), getQValueFactory());
}

代码示例来源:origin: apache/jackrabbit

public void testOffsetAndSkip() throws Exception {
  query.setOffset(1);
  QueryResult result = query.execute();
  NodeIterator nodes = result.getNodes();
  nodes.skip(1);
  assertTrue(node3.isSame(nodes.nextNode()));
}

代码示例来源:origin: apache/jackrabbit

public void test2BigPages() throws Exception {
  List<String> expected = new ArrayList<String>(c);
  Query q = newQuery();
  int p1 = (int) (c.size() * 0.8);
  int p2 = c.size() - p1;
  q.setOffset(0);
  q.setLimit(p1);
  List<String> out1 = qrToPaths(q.execute());
  assertEquals(p1, out1.size());
  for (String s : out1) {
    assertTrue(expected.remove(s));
  }
  q.setOffset(p1);
  q.setLimit(p2);
  List<String> out2 = qrToPaths(q.execute());
  assertEquals(p2, out2.size());
  for (String s : out2) {
    assertTrue(expected.remove(s));
  }
  assertTrue(expected.isEmpty());
}

代码示例来源:origin: ModeShape/modeshape

@Test
public void shouldBeAbleToQueryWithZeroOffsetOnNonJoin() throws RepositoryException {
  // Try with the OFFSET expression ...
  String sql = "SELECT [jcr:path] FROM [car:Car] OFFSET 0";
  Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2);
  QueryResult result = query.execute();
  validateQuery().rowCount(13).hasColumns("jcr:path").validate(query, result);
  // Try with the method ...
  sql = "SELECT [jcr:path] FROM [car:Car]";
  query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2);
  query.setOffset(0);
  result = query.execute();
  validateQuery().rowCount(13).hasColumns("jcr:path").validate(query, result);
}

代码示例来源:origin: ModeShape/modeshape

@Test
public void shouldBeAbleToQueryWithOffsetOnNonJoin() throws RepositoryException {
  // Try with the OFFSET expression ...
  String sql = "SELECT [jcr:path] FROM [car:Car] OFFSET 2";
  Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2);
  QueryResult result = query.execute();
  validateQuery().rowCount(11).hasColumns("jcr:path").validate(query, result);
  // Try with the method ...
  sql = "SELECT [jcr:path] FROM [car:Car]";
  query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2);
  query.setOffset(2);
  result = query.execute();
  validateQuery().rowCount(11).hasColumns("jcr:path").validate(query, result);
}

代码示例来源:origin: ModeShape/modeshape

@Test
public void shouldBeAbleToQueryWithTooLargeOffsetOnNonJoin() throws RepositoryException {
  // Try with the OFFSET expression ...
  String sql = "SELECT [jcr:path] FROM [car:Car] OFFSET 100";
  Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2);
  QueryResult result = query.execute();
  validateQuery().rowCount(0).hasColumns("jcr:path").validate(query, result);
  // Try with the method ...
  sql = "SELECT [jcr:path] FROM [car:Car]";
  query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2);
  query.setOffset(100);
  result = query.execute();
  validateQuery().rowCount(0).hasColumns("jcr:path").validate(query, result);
}

相关文章