Java Code Examples for org.springframework.data.domain.Pageable#getOffset()
The following examples show how to use
org.springframework.data.domain.Pageable#getOffset() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PermissionService.java From spring-boot-practice with Apache License 2.0 | 6 votes |
public Page<Permission> findAllByRoleId(Integer id, Pageable pageable) { QRole role = QRole.role; Predicate predicate = role.id.eq(id); PathBuilder<Permission> builder = new PathBuilder<Permission>(Permission.class, QPermission.permission.getMetadata()); Querydsl querydsl = new Querydsl(em, builder); JPQLQuery countQuery = createQuery(predicate); JPQLQuery query = querydsl.applyPagination(pageable, createQuery(predicate)); Path<Permission> path = QPermission.permission; Long total = countQuery.count(); List<Permission> content = total > pageable.getOffset() ? query.list(path) : Collections.<Permission>emptyList(); return new PageImpl<Permission>(content, pageable, total); }
Example 2
Source File: AbstractSolrQuery.java From dubbox with Apache License 2.0 | 6 votes |
protected Pageable getLimitingPageable(final Pageable source, final int limit) { if (source == null) { return new SolrPageRequest(0, limit); } return new PageRequest(source.getPageNumber(), source.getPageSize(), source.getSort()) { private static final long serialVersionUID = 8100166028148948968L; @Override public int getOffset() { return source.getOffset(); } @Override public int getPageSize() { return limit; } }; }
Example 3
Source File: NonReactiveAggregateQueryProvider.java From mongodb-aggregate-query-support with Apache License 2.0 | 6 votes |
private void addPageableStages(List<Annotation> unwoundAnnotations) { // if this annotation is pageable - add a facet. if(isPageable()) { Pageable pageable = mongoParameterAccessor.getPageable(); Annotation pageableFacet = new PageableFacet(unwoundAnnotations.size(), pageable.getOffset(), pageable.getPageSize()); Annotation pageableUnwind = new PageableUnwind(unwoundAnnotations.size() + 1); Annotation pageableProject = new PageableProject(unwoundAnnotations.size() + 2); unwoundAnnotations.addAll(Arrays.asList(pageableFacet, pageableUnwind, pageableProject)); int outStageIndex = getOutPipelineStageIndex(unwoundAnnotations); if (outStageIndex >= 0) { Annotation outAnnotation = unwoundAnnotations.remove(outStageIndex); unwoundAnnotations.add(outAnnotation); } } }
Example 4
Source File: PermissionService.java From spring-boot-practice with Apache License 2.0 | 6 votes |
public Page<Permission> findAllByRoleId(Integer id, Pageable pageable) { QRole role = QRole.role; Predicate predicate = role.id.eq(id); PathBuilder<Permission> builder = new PathBuilder<Permission>(Permission.class, QPermission.permission.getMetadata()); Querydsl querydsl = new Querydsl(em, builder); JPQLQuery countQuery = createQuery(predicate); JPQLQuery query = querydsl.applyPagination(pageable, createQuery(predicate)); Path<Permission> path = QPermission.permission; Long total = countQuery.count(); List<Permission> content = total > pageable.getOffset() ? query.list(path) : Collections.<Permission>emptyList(); return new PageImpl<Permission>(content, pageable, total); }
Example 5
Source File: LinqImpl.java From bdf3 with Apache License 2.0 | 6 votes |
@Override public <T> List<T> list(Pageable pageable) { if (parent != null) { applyPredicateToCriteria(sq); return parent.list(pageable); } if (pageable == null) { return list(); } else { Sort sort = pageable.getSort(); orders.addAll(QueryUtils.toOrders(sort, root, cb)); applyPredicateToCriteria(criteria); TypedQuery<?> query = em.createQuery(criteria); Long offset = pageable.getOffset(); query.setFirstResult(offset.intValue()); query.setMaxResults(pageable.getPageSize()); return transform(query, false); } }
Example 6
Source File: AbstractDynamoDBQuery.java From spring-data-dynamodb with Apache License 2.0 | 6 votes |
private Page<T> createPage(List<T> allResults, Pageable pageable,AbstractDynamoDBQuery<T, ID> dynamoDBQuery,Object[] values) { Iterator<T> iterator = allResults.iterator(); int processedCount = 0; if (pageable.getOffset() > 0) { processedCount = scanThroughResults(iterator, pageable.getOffset()); if (processedCount < pageable.getOffset()) return new PageImpl<T>(new ArrayList<T>()); } List<T> results = readPageOfResultsRestrictMaxResultsIfNecessary(iterator, pageable.getPageSize()); Query<Long> countQuery = dynamoDBQuery.doCreateCountQueryWithPermissions(values,true); long count = countQuery.getSingleResult(); if (getResultsRestrictionIfApplicable() != null) { count = Math.min(count,getResultsRestrictionIfApplicable()); } return new PageImpl<T>(results, pageable, count); }
Example 7
Source File: PageableDataProvider.java From spring-data-provider with Apache License 2.0 | 5 votes |
private <T> Stream<T> fromPageable(Page<T> result, Pageable pageable, Query<T, ?> query) { List<T> items = result.getContent(); int firstRequested = query.getOffset(); int nrRequested = query.getLimit(); int firstReturned = (int) pageable.getOffset(); int firstReal = firstRequested - firstReturned; int afterLastReal = firstReal + nrRequested; if (afterLastReal > items.size()) { afterLastReal = items.size(); } return items.subList(firstReal, afterLastReal).stream(); }
Example 8
Source File: LinqImpl.java From bdf3 with Apache License 2.0 | 5 votes |
@Override public <T> org.springframework.data.domain.Page<T> paging(Pageable pageable) { if (parent != null) { beforeExecute(sq); return parent.paging(pageable); } List<T> list; if (pageable == null) { list = list(); return new PageImpl<T>(list); } else { Sort sort = pageable.getSort(); orders.addAll(QueryUtils.toOrders(sort, root, cb)); beforeExecute(criteria); TypedQuery<?> query = em.createQuery(criteria); Long offset = pageable.getOffset(); query.setFirstResult(offset.intValue()); query.setMaxResults(pageable.getPageSize()); Long total = JpaUtil.count(criteria); List<T> content = Collections.<T> emptyList(); if (total > pageable.getOffset()) { content = transform(query, false); } return new PageImpl<T>(content, pageable, total); } }
Example 9
Source File: RankingConfigServiceImpl.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
@Transactional @Override public Page<RankingInfo> getRankingInfos(long guildId, String search, Pageable pageable) { Page<Ranking> rankings = rankingRepository.findByGuildId(guildId, search != null ? search.toLowerCase() : "", pageable); AtomicLong rankCounter = new AtomicLong(pageable.getOffset()); return rankings.map(e -> { RankingInfo info = RankingUtils.calculateInfo(e); info.setRank(StringUtils.isEmpty(search) ? rankCounter.incrementAndGet() : rankingRepository.getRank(guildId, info.getTotalExp())); return info; }); }
Example 10
Source File: EbeanQueryWrapper.java From spring-data-ebean with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") <E> Slice<E> findSlice(Pageable pageable) { List<E> resultList = null; int pageSize = pageable.getPageSize(); int offset = (int) pageable.getOffset(); if (queryType == QUERY) { resultList = ((Query<E>) queryInstance).setFirstRow(offset).setMaxRows(pageSize + 1).findList(); boolean hasNext = resultList.size() > pageSize; return new SliceImpl<E>(hasNext ? resultList.subList(0, pageSize) : resultList, pageable, hasNext); } throw new IllegalArgumentException("query not supported!"); }
Example 11
Source File: OraclePagingQueryProvider.java From spring-cloud-task with Apache License 2.0 | 5 votes |
@Override public String getPageQuery(Pageable pageable) { long offset = pageable.getOffset() + 1; return generateRowNumSqlQueryWithNesting(getSelectClause(), false, "TMP_ROW_NUM >= " + offset + " AND TMP_ROW_NUM < " + (offset + pageable.getPageSize())); }
Example 12
Source File: SqlServerPagingQueryProvider.java From spring-cloud-task with Apache License 2.0 | 5 votes |
@Override public String getPageQuery(Pageable pageable) { long offset = pageable.getOffset() + 1; return generateRowNumSqlQueryWithNesting(getSelectClause(), false, "TMP_ROW_NUM >= " + offset + " AND TMP_ROW_NUM < " + (offset + pageable.getPageSize())); }
Example 13
Source File: SimpleQuery.java From dubbox with Apache License 2.0 | 5 votes |
@Override public final <T extends Query> T setPageRequest(Pageable pageable) { Assert.notNull(pageable); this.offset = pageable.getOffset(); this.rows = pageable.getPageSize(); return this.addSort(pageable.getSort()); }
Example 14
Source File: Db2PagingQueryProvider.java From spring-cloud-dataflow with Apache License 2.0 | 4 votes |
@Override public String getPageQuery(Pageable pageable) { long offset = pageable.getOffset() + 1; return generateRowNumSqlQueryWithNesting(getSelectClause(), false, "TMP_ROW_NUM BETWEEN " + offset + " AND " + (offset + pageable.getPageSize())); }
Example 15
Source File: DefaultTaskJobService.java From spring-cloud-dataflow with Apache License 2.0 | 4 votes |
private int getPageOffset(Pageable pageable) { if(pageable.getOffset() > (long)Integer.MAX_VALUE) { throw new OffsetOutOfBoundsException("The pageable offset requested for this query is greater than MAX_INT.") ; } return (int)pageable.getOffset(); }
Example 16
Source File: PartTreeDatastoreQuery.java From spring-cloud-gcp with Apache License 2.0 | 4 votes |
private StructuredQuery applyQueryBody(Object[] parameters, Builder builder, boolean total, boolean singularResult, Cursor cursor) { ParameterAccessor paramAccessor = new ParametersParameterAccessor(getQueryMethod().getParameters(), parameters); if (this.tree.hasPredicate()) { applySelectWithFilter(parameters, builder); } Pageable pageable = paramAccessor.getPageable(); Integer limit = null; Integer offset = null; if (singularResult || this.tree.isExistsProjection()) { limit = 1; } else if (this.tree.isLimiting()) { limit = this.tree.getMaxResults(); } if (!singularResult && !total && pageable.isPaged()) { limit = pageable.getPageSize(); } Sort sort = this.tree.getSort(); if (getQueryMethod().getParameters().hasPageableParameter()) { sort = sort.and(pageable.getSort()); } if (getQueryMethod().getParameters().hasSortParameter()) { sort = sort.and(paramAccessor.getSort()); } if (pageable.isPaged() && !total) { offset = (int) pageable.getOffset(); } Cursor cursorToApply = null; if (cursor != null) { cursorToApply = cursor; } else if (pageable instanceof DatastorePageable) { cursorToApply = ((DatastorePageable) pageable).toCursor(); } DatastoreTemplate.applyQueryOptions( builder, new DatastoreQueryOptions.Builder().setLimit(limit).setOffset(offset).setSort(sort) .setCursor(cursorToApply).build(), this.datastorePersistentEntity); return builder.build(); }
Example 17
Source File: Db2PagingQueryProvider.java From spring-cloud-dashboard with Apache License 2.0 | 4 votes |
@Override public String getPageQuery(Pageable pageable) { int offset = pageable.getOffset() + 1; return generateRowNumSqlQueryWithNesting(getSelectClause(), false, "TMP_ROW_NUM BETWEEN " + offset + " AND " + (offset + pageable.getPageSize())); }
Example 18
Source File: CosmosPageImpl.java From spring-data-cosmosdb with MIT License | 4 votes |
public CosmosPageImpl(List<T> content, Pageable pageable, long total) { super(content, pageable, total); this.offset = pageable.getOffset(); }
Example 19
Source File: OraclePagingQueryProvider.java From spring-cloud-dataflow with Apache License 2.0 | 4 votes |
@Override public String getPageQuery(Pageable pageable) { long offset = pageable.getOffset() + 1; return generateRowNumSqlQueryWithNesting(getSelectClause(), false, "TMP_ROW_NUM >= " + offset + " AND TMP_ROW_NUM < " + (offset + pageable.getPageSize())); }
Example 20
Source File: CypherAdapterUtils.java From sdn-rx with Apache License 2.0 | 3 votes |
public static StatementBuilder.BuildableStatement addPagingParameter( NodeDescription<?> nodeDescription, Pageable pageable, StatementBuilder.OngoingReadingAndReturn returning) { Sort sort = pageable.getSort(); long skip = pageable.getOffset(); int pageSize = pageable.getPageSize(); return returning.orderBy(toSortItems(nodeDescription, sort)).skip(skip).limit(pageSize); }