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

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

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

Query.setMaxResults介绍

[英]Set the maximum number of results 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: 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: BroadleafCommerce/BroadleafCommerce

  1. @Override
  2. public SearchRedirect findSearchRedirectBySearchTerm(String searchTerm) {
  3. Query query = em.createQuery(buildFindSearchRedirectBySearchTermCriteria(searchTerm));
  4. query.setMaxResults(1);
  5. query.setHint(QueryHints.HINT_CACHEABLE, true);
  6. List<SearchRedirect> results = query.getResultList();
  7. if (results != null && !results.isEmpty()) {
  8. return results.get(0);
  9. } else {
  10. return null;
  11. }
  12. }

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

  1. Query query = this.em.createNamedQuery(namedQueryName);
  2. if(resultLimit > 0) {
  3. query.setMaxResults(resultLimit);
  4. query.setParameter(entry.getKey(), entry.getValue());
  5. return query.getResultList();

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

  1. query.setFirstResult((Integer) params.get(name));
  2. query.setMaxResults((Integer) params.get(name));
  3. continue;
  4. query.setParameter(name, params.get(name));

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

  1. @Transactional
  2. <K> K _findValue() {
  3. assert _selects.size() == 1 : String.format("findValue() only need one parameter in Query.Select(), you have put %s parameter in Query.select(..), either correcting the parameter or using find() or findTuple()", _selects.size());
  4. done();
  5. K value = null;
  6. try {
  7. Query q = _dbf.getEntityManager().createQuery(_query);
  8. if (limit != null) {
  9. q.setMaxResults(limit);
  10. }
  11. value = (K)q.getSingleResult();
  12. } catch (NoResultException e) {
  13. } catch (EmptyResultDataAccessException e) {
  14. }
  15. return value;
  16. }

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

  1. @Override
  2. @SuppressWarnings("unchecked")
  3. protected Object doExecute(AbstractJpaQuery query, Object[] values) {
  4. ParametersParameterAccessor accessor = new ParametersParameterAccessor(parameters, values);
  5. Pageable pageable = accessor.getPageable();
  6. Query createQuery = query.createQuery(values);
  7. int pageSize = pageable.getPageSize();
  8. createQuery.setMaxResults(pageSize + 1);
  9. List<Object> resultList = createQuery.getResultList();
  10. boolean hasNext = resultList.size() > pageSize;
  11. return new SliceImpl<Object>(hasNext ? resultList.subList(0, pageSize) : resultList, pageable, hasNext);
  12. }
  13. }

代码示例来源: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: kiegroup/jbpm

  1. private long timeQueryExecution(EntityManager em, CriteriaQuery query, Query realQuery, int total) {
  2. if( realQuery == null ) {
  3. realQuery = em.createQuery(query);
  4. realQuery.setMaxResults(2000);
  5. }
  6. long start = System.nanoTime();
  7. List<TaskSummary> results = realQuery.getResultList();
  8. long end = System.nanoTime();
  9. assertEquals( "query results", total, results.size() );
  10. return (end - start)/1000000;
  11. }

代码示例来源:origin: org.rhq/rhq-enterprise-server

  1. @SuppressWarnings("unchecked")
  2. private List<AlertDampeningEvent> getRecentAlertDampeningEvents(int alertDefinitionId, long maxResults) {
  3. Query query = entityManager.createNamedQuery(AlertDampeningEvent.QUERY_FIND_BY_ALERT_DEFINITION_ID);
  4. query.setParameter("alertDefinitionId", alertDefinitionId);
  5. query.setMaxResults((int) maxResults);
  6. List<AlertDampeningEvent> results = query.getResultList();
  7. return results;
  8. }

代码示例来源: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: xujeff/tianti

  1. List<Object> paramList = (List<Object>) params;
  2. for(int i = 0, size = paramList.size(); i < size; i++){
  3. qry.setParameter(i+1, paramList.get(i));
  4. qry.setParameter(key, paramMap.get(key));
  5. qry.setFirstResult(rowsInPage * (currentPage - 1));
  6. qry.setMaxResults(rowsInPage);

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

  1. @Transactional
  2. Tuple _findTuple() {
  3. assert _selects.size() > 1 : String.format("findTuple() needs more than one parameter in Query.Select(), you have put %s parameter in Query.select(..), either correcting the parameter or using find() or findValue()", _selects.size());
  4. done();
  5. Tuple ret = null;
  6. try {
  7. Query q = _dbf.getEntityManager().createQuery(_query);
  8. if (limit != null) {
  9. q.setMaxResults(limit);
  10. }
  11. ret = (Tuple)q.getSingleResult();
  12. } catch (NoResultException e) {
  13. } catch (EmptyResultDataAccessException e) {
  14. }
  15. return ret;
  16. }

代码示例来源: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: 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: Impetus/Kundera

  1. Query q = em.createQuery(noClause);
  2. List<PrimeUser> results = q.getResultList();
  3. Assert.assertNotNull(results);
  4. Assert.assertEquals(3, results.size());
  5. q = em.createQuery(noClause);
  6. q.setMaxResults(2);
  7. results = q.getResultList();
  8. Assert.assertNotNull(results);
  9. Assert.assertEquals(2, results.size());

代码示例来源:origin: com.atlassian.addon.connect.hercules/hercules-ac

  1. public List<VoteReport.Pattern> getVoteReport(final boolean showTop)
  2. {
  3. final List<VoteReport.Pattern> ret = Lists.newArrayList();
  4. @SuppressWarnings ("unchecked")
  5. final List<Object[]> result = JPA.em().
  6. createNamedQuery(showTop ? "HerculesPatternSource.topVoteReport" : "HerculesPatternSource.bottomVoteReport").
  7. setParameter("tenant", this.tenant).
  8. setParameter("source", this).setMaxResults(10).getResultList();
  9. addAll(ret, transform(result, columns -> new VoteReport.Pattern((String) columns[0], (Long) columns[1])));
  10. return ret;
  11. }

代码示例来源: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: 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) {
  8. PropertyAccessor accessor = PropertyAccessorFactory.getPropertyAccessor(paramClass);
  9. Object paramValue = accessor.fromString(paramClass, value);
  10. q.setParameter(Integer.parseInt(paramName), paramValue);
  11. break;
  12. PropertyAccessor accessor = PropertyAccessorFactory.getPropertyAccessor(paramClass);
  13. Object paramValue = accessor.fromString(paramClass, value);
  14. q.setParameter(paramName, paramValue);

相关文章