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

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

本文整理了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

// SQL: SELECT * FROM table LIMIT start, maxRows;

Query q = session.createQuery("FROM table");
q.setFirstResult(start);
q.setMaxResults(maxRows);

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

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

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

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

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

@Override
public SearchRedirect findSearchRedirectBySearchTerm(String searchTerm) {
  Query query = em.createQuery(buildFindSearchRedirectBySearchTermCriteria(searchTerm));
  query.setMaxResults(1);
  query.setHint(QueryHints.HINT_CACHEABLE, true);
  List<SearchRedirect> results = query.getResultList();
  if (results != null && !results.isEmpty()) {
    return results.get(0);
  } else {
    return null;
  }
}

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

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

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

query.setFirstResult((Integer) params.get(name));
    query.setMaxResults((Integer) params.get(name));
  continue;
query.setParameter(name, params.get(name));

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

@Transactional
<K> K _findValue() {
  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());
  done();
  K value = null;
  try {
    Query q = _dbf.getEntityManager().createQuery(_query);
    if (limit != null) {
      q.setMaxResults(limit);
    }
    value = (K)q.getSingleResult();
  } catch (NoResultException e) {
  } catch (EmptyResultDataAccessException e) {
  }
  
  return value;
}

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

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

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

@SuppressWarnings("unchecked")
@Override
public List<FulfillmentGroup> readFulfillmentGroupsByStatus(
    FulfillmentGroupStatusType status, int start, int maxResults, boolean ascending) {
  Query query = null;
  if (ascending) {
    query = em.createNamedQuery("BC_READ_FULFILLMENT_GROUP_BY_STATUS_ASC");
  } else {
    query = em.createNamedQuery("BC_READ_FULFILLMENT_GROUP_BY_STATUS_DESC");
  }
  query.setParameter("status", status.getType());
  query.setFirstResult(start);
  query.setMaxResults(maxResults);
  
  return query.getResultList();
}

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

private long timeQueryExecution(EntityManager em, CriteriaQuery query, Query realQuery, int total) { 
  
  if( realQuery == null ) { 
    realQuery = em.createQuery(query);
    realQuery.setMaxResults(2000);
  }
  
  long start = System.nanoTime(); 
  List<TaskSummary> results = realQuery.getResultList();
  long end = System.nanoTime(); 
    assertEquals( "query results", total, results.size() );
  
  return (end - start)/1000000; 
}

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

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

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

@SuppressWarnings("unchecked")
@Override
public List<FulfillmentGroup> readUnprocessedFulfillmentGroups(int start,
    int maxResults) {
  Query query = em.createNamedQuery("BC_READ_UNPROCESSED_FULFILLMENT_GROUP_ASC");
  query.setFirstResult(start);
  query.setMaxResults(maxResults);
  
  return query.getResultList();
}

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

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

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

@Transactional
Tuple _findTuple() {
  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());
  done();
  Tuple ret = null;
  try {
    Query q = _dbf.getEntityManager().createQuery(_query);
    if (limit != null) {
      q.setMaxResults(limit);
    }
    ret = (Tuple)q.getSingleResult();
  } catch (NoResultException e) {
  } catch (EmptyResultDataAccessException e) {
  }
  return ret;
}

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

protected void addPaging(Query response, Integer firstResult, Integer maxResults) {
  if (firstResult != null) {
    response.setFirstResult(firstResult);
  }
  if (maxResults != null) {
    response.setMaxResults(maxResults);
  }
}

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

@SuppressWarnings("unchecked")
@Override
public List<ExecutionError> listByActivity(String activityName, Integer page, Integer pageSize) {
  if (!isActive()) {
    return Collections.EMPTY_LIST;
  }
  int startPosition = page * pageSize;
  return call((EntityManager em) -> {
   
    return em.createQuery("from ExecutionErrorInfo where activityName =:activityName")
      .setParameter("activityName", activityName)
      .setFirstResult(startPosition)
      .setMaxResults(pageSize)
      .getResultList();
  });
}

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

Query q = em.createQuery(noClause);
List<PrimeUser> results = q.getResultList();
Assert.assertNotNull(results);
Assert.assertEquals(3, results.size());
q = em.createQuery(noClause);
q.setMaxResults(2);
results = q.getResultList();
Assert.assertNotNull(results);
Assert.assertEquals(2, results.size());

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

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

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

@SuppressWarnings("unchecked")
@Override
public List<FulfillmentGroup> readUnfulfilledFulfillmentGroups(int start,
    int maxResults) {
  Query query = em.createNamedQuery("BC_READ_UNFULFILLED_FULFILLMENT_GROUP_ASC");
  query.setFirstResult(start);
  query.setMaxResults(maxResults);
  return query.getResultList();
}

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

String value = paramsMap.get(paramName);
if (paramName.equalsIgnoreCase("firstResult")) {
  q.setFirstResult(Integer.parseInt(value));
} else if (paramName.equalsIgnoreCase("maxResult")) {
  q.setMaxResults(Integer.parseInt(value));
} else if (StringUtils.isNumeric(paramName)) {
  for (Parameter param : parameters) {
      PropertyAccessor accessor = PropertyAccessorFactory.getPropertyAccessor(paramClass);
      Object paramValue = accessor.fromString(paramClass, value);
      q.setParameter(Integer.parseInt(paramName), paramValue);
      break;
      PropertyAccessor accessor = PropertyAccessorFactory.getPropertyAccessor(paramClass);
      Object paramValue = accessor.fromString(paramClass, value);
      q.setParameter(paramName, paramValue);

相关文章