javax.persistence.Query.setFirstResult()方法的使用及代码示例

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

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

Query.setFirstResult介绍

[英]Set the position of the first result to retrieve.
[中]设置要检索的第一个结果的位置。

代码示例

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

  1. // SQL: SELECT * FROM table LIMIT start, maxRows;
  2. Query q = session.createQuery("FROM table");
  3. q.setFirstResult(start);
  4. q.setMaxResults(maxRows);

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

  1. String sql = "SELECT t FROM table t";
  2. Query query = em.createQuery(sql);
  3. query.setFirstResult(firstPosition);
  4. query.setMaxResults(numberOfRecords);
  5. List result = query.getResultList();

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

  1. @SuppressWarnings("unchecked")
  2. @Override
  3. public List<FulfillmentGroup> readUnfulfilledFulfillmentGroups(int start,
  4. int maxResults) {
  5. Query query = em.createNamedQuery("BC_READ_UNFULFILLED_FULFILLMENT_GROUP_ASC");
  6. query.setFirstResult(start);
  7. query.setMaxResults(maxResults);
  8. return query.getResultList();
  9. }

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

  1. protected void addPaging(Query response, Integer firstResult, Integer maxResults) {
  2. if (firstResult != null) {
  3. response.setFirstResult(firstResult);
  4. }
  5. if (maxResults != null) {
  6. response.setMaxResults(maxResults);
  7. }
  8. }

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

  1. @SuppressWarnings("unchecked")
  2. @Override
  3. public List<FulfillmentGroup> readPartiallyFulfilledFulfillmentGroups(int start,
  4. int maxResults) {
  5. Query query = em.createNamedQuery("BC_READ_PARTIALLY_FULFILLED_FULFILLMENT_GROUP_ASC");
  6. query.setFirstResult(start);
  7. query.setMaxResults(maxResults);
  8. return query.getResultList();
  9. }

代码示例来源:origin: kiegroup/jbpm

  1. query.setFirstResult((Integer) params.get(name));
  2. query.setMaxResults((Integer) params.get(name));

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

  1. @SuppressWarnings("unchecked")
  2. @Override
  3. public List<FulfillmentGroup> readUnprocessedFulfillmentGroups(int start,
  4. int maxResults) {
  5. Query query = em.createNamedQuery("BC_READ_UNPROCESSED_FULFILLMENT_GROUP_ASC");
  6. query.setFirstResult(start);
  7. query.setMaxResults(maxResults);
  8. return query.getResultList();
  9. }

代码示例来源:origin: kiegroup/jbpm

  1. /**
  2. * Small method to apply the meta criteria from the {@link QueryWhere} instance to the {@link Query} instance
  3. * @param query The {@link Query} instance
  4. * @param queryWhere The {@link QueryWhere} instance, with the abstract information about the query
  5. */
  6. public static void applyMetaCriteriaToQuery(Query query, QueryWhere queryWhere) {
  7. if( queryWhere.getCount() != null ) {
  8. query.setMaxResults(queryWhere.getCount());
  9. }
  10. if( queryWhere.getOffset() != null ) {
  11. query.setFirstResult(queryWhere.getOffset());
  12. }
  13. }

代码示例来源:origin: spring-projects/spring-integration-samples

  1. @SuppressWarnings("unchecked")
  2. public static List<LoanShark> findLoanSharkEntries(int firstResult, int maxResults) {
  3. return entityManager().createQuery("select o from LoanShark o").setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
  4. }

代码示例来源:origin: spring-projects/spring-data-jpa

  1. /**
  2. * Binds the parameters to the given query and applies special parameter types (e.g. pagination).
  3. *
  4. * @param query must not be {@literal null}.
  5. * @param values values of method parameters to be assigned to the query parameters.
  6. */
  7. Query bindAndPrepare(Query query, Object[] values) {
  8. Assert.notNull(query, "Query must not be null!");
  9. ParametersParameterAccessor accessor = new ParametersParameterAccessor(parameters, values);
  10. Query result = bind(query, values);
  11. if (!useJpaForPaging || !parameters.hasPageableParameter() || accessor.getPageable().isUnpaged()) {
  12. return result;
  13. }
  14. result.setFirstResult((int) accessor.getPageable().getOffset());
  15. result.setMaxResults(accessor.getPageable().getPageSize());
  16. return result;
  17. }
  18. }

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

  1. @SuppressWarnings("unchecked")
  2. @Override
  3. public List<FulfillmentGroup> readFulfillmentGroupsByStatus(
  4. FulfillmentGroupStatusType status, int start, int maxResults, boolean ascending) {
  5. Query query = null;
  6. if (ascending) {
  7. query = em.createNamedQuery("BC_READ_FULFILLMENT_GROUP_BY_STATUS_ASC");
  8. } else {
  9. query = em.createNamedQuery("BC_READ_FULFILLMENT_GROUP_BY_STATUS_DESC");
  10. }
  11. query.setParameter("status", status.getType());
  12. query.setFirstResult(start);
  13. query.setMaxResults(maxResults);
  14. return query.getResultList();
  15. }

代码示例来源:origin: spring-projects/spring-data-jpa

  1. /**
  2. * Restricts the max results of the given {@link Query} if the current {@code tree} marks this {@code query} as
  3. * limited.
  4. */
  5. private Query restrictMaxResultsIfNecessary(Query query) {
  6. if (tree.isLimiting()) {
  7. if (query.getMaxResults() != Integer.MAX_VALUE) {
  8. /*
  9. * In order to return the correct results, we have to adjust the first result offset to be returned if:
  10. * - a Pageable parameter is present
  11. * - AND the requested page number > 0
  12. * - AND the requested page size was bigger than the derived result limitation via the First/Top keyword.
  13. */
  14. if (query.getMaxResults() > tree.getMaxResults() && query.getFirstResult() > 0) {
  15. query.setFirstResult(query.getFirstResult() - (query.getMaxResults() - tree.getMaxResults()));
  16. }
  17. }
  18. query.setMaxResults(tree.getMaxResults());
  19. }
  20. if (tree.isExistsProjection()) {
  21. query.setMaxResults(1);
  22. }
  23. return query;
  24. }

代码示例来源:origin: rapidoid/rapidoid

  1. public static <T> List<T> getPage(Query q, long skip, long limit) {
  2. U.must(skip < Integer.MAX_VALUE && skip >= 0);
  3. U.must(limit >= -1); // -1 means no limit
  4. limit = Math.min(limit, Integer.MAX_VALUE);
  5. q.setFirstResult((int) skip);
  6. q.setMaxResults(limit >= 0 ? (int) limit : Integer.MAX_VALUE);
  7. return q.getResultList();
  8. }

代码示例来源:origin: zstackio/zstack

  1. private void setPaging(Query q, SQLText st) {
  2. if (st.limit != null) {
  3. q.setMaxResults(st.limit);
  4. }
  5. if (st.offset != null) {
  6. q.setFirstResult(st.offset);
  7. }
  8. }
  9. }

代码示例来源:origin: kiegroup/jbpm

  1. @SuppressWarnings("unchecked")
  2. @Override
  3. public List<ExecutionError> list(Integer page, Integer pageSize) {
  4. if (!isActive()) {
  5. return Collections.EMPTY_LIST;
  6. }
  7. int startPosition = page * pageSize;
  8. return call((EntityManager em) -> {
  9. return em.createQuery("from ExecutionErrorInfo")
  10. .setFirstResult(startPosition)
  11. .setMaxResults(pageSize)
  12. .getResultList();
  13. });
  14. }

代码示例来源:origin: zstackio/zstack

  1. private void rebuildQueryInTransaction() {
  2. query = entityClass == null ? dbf.getEntityManager().createQuery(sql) : dbf.getEntityManager().createQuery(sql, entityClass);
  3. if (first != null) {
  4. query.setFirstResult(first);
  5. }
  6. if (lockMode != null) {
  7. query.setLockMode(lockMode);
  8. }
  9. if (max != null) {
  10. query.setMaxResults(max);
  11. }
  12. for (Map.Entry<String, Object> e : params.entrySet()) {
  13. query.setParameter(e.getKey(), e.getValue());
  14. }
  15. }

代码示例来源:origin: kiegroup/jbpm

  1. @SuppressWarnings("unchecked")
  2. @Override
  3. public List<ExecutionError> listByActivity(String activityName, Integer page, Integer pageSize) {
  4. if (!isActive()) {
  5. return Collections.EMPTY_LIST;
  6. }
  7. int startPosition = page * pageSize;
  8. return call((EntityManager em) -> {
  9. return em.createQuery("from ExecutionErrorInfo where activityName =:activityName")
  10. .setParameter("activityName", activityName)
  11. .setFirstResult(startPosition)
  12. .setMaxResults(pageSize)
  13. .getResultList();
  14. });
  15. }

代码示例来源:origin: xujeff/tianti

  1. qry.setFirstResult(rowsInPage * (currentPage - 1));
  2. qry.setMaxResults(rowsInPage);

代码示例来源:origin: kiegroup/jbpm

  1. @SuppressWarnings("unchecked")
  2. @Override
  3. public List<ExecutionError> listByProcessInstance(Long processInstanceId, Integer page, Integer pageSize) {
  4. if (!isActive()) {
  5. return Collections.EMPTY_LIST;
  6. }
  7. int startPosition = page * pageSize;
  8. return call((EntityManager em) -> {
  9. return em.createQuery("from ExecutionErrorInfo where processInstanceId =:processInstanceId")
  10. .setParameter("processInstanceId", processInstanceId)
  11. .setFirstResult(startPosition)
  12. .setMaxResults(pageSize)
  13. .getResultList();
  14. });
  15. }

代码示例来源:origin: Impetus/Kundera

  1. String value = paramsMap.get(paramName);
  2. if (paramName.equalsIgnoreCase("firstResult")) {
  3. q.setFirstResult(Integer.parseInt(value));
  4. } else if (paramName.equalsIgnoreCase("maxResult")) {
  5. q.setMaxResults(Integer.parseInt(value));
  6. } else if (StringUtils.isNumeric(paramName)) {
  7. for (Parameter param : parameters) {

相关文章