本文整理了Java中javax.persistence.Query.setFirstResult
方法的一些代码示例,展示了Query.setFirstResult
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.setFirstResult
方法的具体详情如下:
包路径:javax.persistence.Query
类名称:Query
方法名:setFirstResult
[英]Set the position of the first result 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: 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: BroadleafCommerce/BroadleafCommerce
protected void addPaging(Query response, Integer firstResult, Integer maxResults) {
if (firstResult != null) {
response.setFirstResult(firstResult);
}
if (maxResults != null) {
response.setMaxResults(maxResults);
}
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@SuppressWarnings("unchecked")
@Override
public List<FulfillmentGroup> readPartiallyFulfilledFulfillmentGroups(int start,
int maxResults) {
Query query = em.createNamedQuery("BC_READ_PARTIALLY_FULFILLED_FULFILLMENT_GROUP_ASC");
query.setFirstResult(start);
query.setMaxResults(maxResults);
return query.getResultList();
}
代码示例来源:origin: kiegroup/jbpm
query.setFirstResult((Integer) params.get(name));
query.setMaxResults((Integer) params.get(name));
代码示例来源: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: kiegroup/jbpm
/**
* Small method to apply the meta criteria from the {@link QueryWhere} instance to the {@link Query} instance
* @param query The {@link Query} instance
* @param queryWhere The {@link QueryWhere} instance, with the abstract information about the query
*/
public static void applyMetaCriteriaToQuery(Query query, QueryWhere queryWhere) {
if( queryWhere.getCount() != null ) {
query.setMaxResults(queryWhere.getCount());
}
if( queryWhere.getOffset() != null ) {
query.setFirstResult(queryWhere.getOffset());
}
}
代码示例来源: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: spring-projects/spring-data-jpa
/**
* Binds the parameters to the given query and applies special parameter types (e.g. pagination).
*
* @param query must not be {@literal null}.
* @param values values of method parameters to be assigned to the query parameters.
*/
Query bindAndPrepare(Query query, Object[] values) {
Assert.notNull(query, "Query must not be null!");
ParametersParameterAccessor accessor = new ParametersParameterAccessor(parameters, values);
Query result = bind(query, values);
if (!useJpaForPaging || !parameters.hasPageableParameter() || accessor.getPageable().isUnpaged()) {
return result;
}
result.setFirstResult((int) accessor.getPageable().getOffset());
result.setMaxResults(accessor.getPageable().getPageSize());
return result;
}
}
代码示例来源: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: spring-projects/spring-data-jpa
/**
* Restricts the max results of the given {@link Query} if the current {@code tree} marks this {@code query} as
* limited.
*/
private Query restrictMaxResultsIfNecessary(Query query) {
if (tree.isLimiting()) {
if (query.getMaxResults() != Integer.MAX_VALUE) {
/*
* In order to return the correct results, we have to adjust the first result offset to be returned if:
* - a Pageable parameter is present
* - AND the requested page number > 0
* - AND the requested page size was bigger than the derived result limitation via the First/Top keyword.
*/
if (query.getMaxResults() > tree.getMaxResults() && query.getFirstResult() > 0) {
query.setFirstResult(query.getFirstResult() - (query.getMaxResults() - tree.getMaxResults()));
}
}
query.setMaxResults(tree.getMaxResults());
}
if (tree.isExistsProjection()) {
query.setMaxResults(1);
}
return query;
}
代码示例来源:origin: rapidoid/rapidoid
public static <T> List<T> getPage(Query q, long skip, long limit) {
U.must(skip < Integer.MAX_VALUE && skip >= 0);
U.must(limit >= -1); // -1 means no limit
limit = Math.min(limit, Integer.MAX_VALUE);
q.setFirstResult((int) skip);
q.setMaxResults(limit >= 0 ? (int) limit : Integer.MAX_VALUE);
return q.getResultList();
}
代码示例来源:origin: zstackio/zstack
private void setPaging(Query q, SQLText st) {
if (st.limit != null) {
q.setMaxResults(st.limit);
}
if (st.offset != null) {
q.setFirstResult(st.offset);
}
}
}
代码示例来源:origin: kiegroup/jbpm
@SuppressWarnings("unchecked")
@Override
public List<ExecutionError> list(Integer page, Integer pageSize) {
if (!isActive()) {
return Collections.EMPTY_LIST;
}
int startPosition = page * pageSize;
return call((EntityManager em) -> {
return em.createQuery("from ExecutionErrorInfo")
.setFirstResult(startPosition)
.setMaxResults(pageSize)
.getResultList();
});
}
代码示例来源:origin: zstackio/zstack
private void rebuildQueryInTransaction() {
query = entityClass == null ? dbf.getEntityManager().createQuery(sql) : dbf.getEntityManager().createQuery(sql, entityClass);
if (first != null) {
query.setFirstResult(first);
}
if (lockMode != null) {
query.setLockMode(lockMode);
}
if (max != null) {
query.setMaxResults(max);
}
for (Map.Entry<String, Object> e : params.entrySet()) {
query.setParameter(e.getKey(), e.getValue());
}
}
代码示例来源: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: xujeff/tianti
qry.setFirstResult(rowsInPage * (currentPage - 1));
qry.setMaxResults(rowsInPage);
代码示例来源:origin: kiegroup/jbpm
@SuppressWarnings("unchecked")
@Override
public List<ExecutionError> listByProcessInstance(Long processInstanceId, Integer page, Integer pageSize) {
if (!isActive()) {
return Collections.EMPTY_LIST;
}
int startPosition = page * pageSize;
return call((EntityManager em) -> {
return em.createQuery("from ExecutionErrorInfo where processInstanceId =:processInstanceId")
.setParameter("processInstanceId", processInstanceId)
.setFirstResult(startPosition)
.setMaxResults(pageSize)
.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) {
内容来源于网络,如有侵权,请联系作者删除!