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

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

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

Query.setLimit介绍

[英]Sets the maximum size of the result set to limit.
[中]将结果集的最大大小设置为[$0$]。

代码示例

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

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

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

@Override
public void setLimit(long limit) {
  delegate.setLimit(limit);
}

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

public void execute() throws Exception {
    getDelegate().setLimit(limit);
  }
});

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

public void setLimit(long limit) {
  getDelegate().setLimit(limit);
}

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

/**
 * @inheritDoc
 */
@Override
public Node findNode(Name nodeName, Name ntName) throws RepositoryException {
  Query query = buildQuery(nodeName, ntName);
  query.setLimit(1);        
  NodeIterator res = query.execute().getNodes();
  if (res.hasNext()) {
    return res.nextNode();
  }
  return null;
}

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

/**
 * @inheritDoc
 */
@Override
public Node findNode(Name nodeName, Name ntName) throws RepositoryException {
  Query query = buildQuery(nodeName, ntName);
  query.setLimit(1);        
  NodeIterator res = query.execute().getNodes();
  if (res.hasNext()) {
    return res.nextNode();
  }
  return null;
}

代码示例来源: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: apache/jackrabbit-oak

protected void processResultsKeysetPagination(@NotNull final QueryManager qm,
    ExecutionContext context) throws RepositoryException {
  Calendar now = Calendar.getInstance();
  now.setTimeZone(TimeZone.getTimeZone("GMT"));
  context.getMap().put(KEYSET_VAL_PROP, now);
  for (int page = 0; page < PAGES; page++) {
    Query query = getQuery(qm, context);
    query.setLimit(LIMIT);
    Node lastNode = iterate(query);
    if (lastNode != null) {
      Property prop =
          lastNode.getProperty(ScalabilityNodeSuite.CTX_PAGINATION_KEY_PROP);
      context.getMap().put(KEYSET_VAL_PROP, prop.getDate());
    }
  }
  context.getMap().remove(KEYSET_VAL_PROP);
}

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

protected void searchCommon(QueryManager qm, ExecutionContext context)
  throws RepositoryException {
  /** Execute standard query */
  Query stdQuery = getStandardQuery(qm, context);
  stdQuery.setLimit(LIMIT);
  QueryResult stdResult = stdQuery.execute();
  RowIterator stdIt = stdResult.getRows();
  // Iterate the standard shown first
  for (int rows = 0; stdIt.hasNext() && rows < LIMIT; rows++) {
    Node node = stdIt.nextRow().getNode();
    LOG.debug(node.getPath());
  }
}

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

protected void searchCommon(QueryManager qm, ExecutionContext
  context) throws RepositoryException {
  /** Execute standard query */
  Query stdQuery = getStandardQuery(qm, context);
  stdQuery.setLimit(LIMIT);
  QueryResult stdResult = stdQuery.execute();
  RowIterator stdIt = stdResult.getRows();
  // Iterate the standard shown first
  for (int rows = 0; stdIt.hasNext() && rows < LIMIT; rows++) {
    Node node = stdIt.nextRow().getNode();
    LOG.debug(node.getPath());
  }
}

代码示例来源:origin: stackoverflow.com

Query q = pm.newQuery (...);
q.setWhere(...);
q.setRange (...);
q.setOrdering (...);
q.setLimit(...);
q.newParameter(...); // declare a query parameter

q.execute(34.5); // execute the SQL query with a parameter

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

public void testLimit() throws Exception {
  query.setLimit(1);
  QueryResult result = query.execute();
  checkResult(result, new Node[] { node1 });
  query.setLimit(2);
  result = query.execute();
  checkResult(result, new Node[] { node1, node2 });
  query.setLimit(3);
  result = query.execute();
  checkResult(result, new Node[] { node1, node2, 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

/**
 * https://issues.apache.org/jira/browse/JCR-2543
 */
public void testSQL2Limit() throws Exception {
  Query q = qm.createQuery("SELECT * FROM [nt:unstructured]",
      Query.JCR_SQL2);
  q.setLimit(1);
  QueryResult r = q.execute();
  NodeIterator it = r.getNodes();
  assertTrue(it.hasNext());
  it.next();
  assertFalse(it.hasNext());
}

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

@Test
public void shouldBeAbleToQueryWithLimitOnNonJoin() throws RepositoryException {
  // Try with the LIMIT expression ...
  String sql = "SELECT [jcr:path] FROM [car:Car] LIMIT 2";
  Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2);
  QueryResult result = query.execute();
  validateQuery().rowCount(2).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.setLimit(2);
  result = query.execute();
  validateQuery().rowCount(2).hasColumns("jcr:path").validate(query, result);
}

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

@Test
public void shouldBeAbleToQueryWithTooLargeLimitOnNonJoin() throws RepositoryException {
  // Try with the LIMIT expression ...
  String sql = "SELECT [jcr:path] FROM [car:Car] LIMIT 100";
  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.setLimit(100);
  result = query.execute();
  validateQuery().rowCount(13).hasColumns("jcr:path").validate(query, result);
}

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

@Test
public void shouldBeAbleToQueryWithLimitOfZeroOnNonJoin() throws RepositoryException {
  // Try with the LIMIT expression ...
  String sql = "SELECT [jcr:path] FROM [car:Car] LIMIT 0";
  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.setLimit(0);
  result = query.execute();
  validateQuery().rowCount(0).hasColumns("jcr:path").validate(query, result);
}

相关文章