Java Code Examples for org.springframework.data.domain.Pageable#isPaged()
The following examples show how to use
org.springframework.data.domain.Pageable#isPaged() .
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: QuerydslKeyValueRepository.java From spring-data-keyvalue with Apache License 2.0 | 6 votes |
@Override public Page<T> findAll(Predicate predicate, Pageable pageable) { AbstractCollQuery<T, ?> query = prepareQuery(predicate); if (pageable.isPaged() || pageable.getSort().isSorted()) { query.offset(pageable.getOffset()); query.limit(pageable.getPageSize()); if (pageable.getSort().isSorted()) { query.orderBy(toOrderSpecifier(pageable.getSort(), builder)); } } return new PageImpl<>(query.fetchResults().getResults(), pageable, count(predicate)); }
Example 2
Source File: SpannerStatementQueryExecutor.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
private static void buildLimit(PartTree tree, StringBuilder stringBuilder, Pageable pageable) { if (tree.isExistsProjection()) { stringBuilder.append(" LIMIT 1"); } else if (pageable.isPaged()) { stringBuilder.append(" LIMIT ").append(pageable.getPageSize()) .append(" OFFSET ").append(pageable.getOffset()); } else if (tree.isLimiting()) { stringBuilder.append(" LIMIT ").append(tree.getMaxResults()); } }
Example 3
Source File: KeyValuePartTreeQuery.java From spring-data-keyvalue with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) protected KeyValueQuery<?> prepareQuery(KeyValueQuery<?> instance, Object[] parameters) { ParametersParameterAccessor accessor = new ParametersParameterAccessor(getQueryMethod().getParameters(), parameters); Object criteria = instance.getCriteria(); if (criteria instanceof SpelCriteria || criteria instanceof SpelExpression) { SpelExpression spelExpression = getSpelExpression(criteria); EvaluationContext context = this.evaluationContextProvider.getEvaluationContext(getQueryMethod().getParameters(), parameters); criteria = new SpelCriteria(spelExpression, context); } KeyValueQuery<?> query = new KeyValueQuery(criteria); Pageable pageable = accessor.getPageable(); Sort sort = accessor.getSort(); query.setOffset(pageable.toOptional().map(Pageable::getOffset).orElse(-1L)); if (pageable.isPaged()) { query.setRows(pageable.getPageSize()); } else if (instance.getRows() >= 0) { query.setRows(instance.getRows()); } query.setSort(sort.isUnsorted() ? instance.getSort() : sort); return query; }
Example 4
Source File: IgniteRepositoryQuery.java From ignite with Apache License 2.0 | 5 votes |
/** * Validates operations that requires Pageable parameter * * @param returnStgy Return stgy. * @param prmtrs Prmtrs. */ private void checkRequiredPageable(ReturnStrategy returnStgy, Object[] prmtrs) { try { if (returnStgy == ReturnStrategy.PAGE_OF_VALUES || returnStgy == ReturnStrategy.SLICE_OF_VALUES || returnStgy == ReturnStrategy.SLICE_OF_CACHE_ENTRIES) { Pageable page = (Pageable)prmtrs[prmtrs.length - 1]; page.isPaged(); } } catch (NullPointerException | IndexOutOfBoundsException | ClassCastException e) { throw new IllegalStateException( "For " + returnStgy.name() + " you must provide on last method parameter a non null Pageable instance"); } }
Example 5
Source File: IgniteRepositoryQuery.java From ignite with Apache License 2.0 | 5 votes |
/** * Validates operations that requires Pageable parameter * * @param returnStgy Return stgy. * @param prmtrs Prmtrs. */ private void checkRequiredPageable(ReturnStrategy returnStgy, Object[] prmtrs) { try { if (returnStgy == ReturnStrategy.PAGE_OF_VALUES || returnStgy == ReturnStrategy.SLICE_OF_VALUES || returnStgy == ReturnStrategy.SLICE_OF_CACHE_ENTRIES) { Pageable page = (Pageable)prmtrs[prmtrs.length - 1]; page.isPaged(); } } catch (NullPointerException | IndexOutOfBoundsException | ClassCastException e) { throw new IllegalStateException( "For " + returnStgy.name() + " you must provide on last method parameter a non null Pageable instance"); } }
Example 6
Source File: JpaSpecificationExecutorWithProjectionImpl.java From specification-with-projection with MIT License | 5 votes |
@Override public <R> Page<R> findAll(Specification<T> spec, Class<R> projectionType, Pageable pageable) { final ReturnedType returnedType = ReturnTypeWarpper.of(projectionType, getDomainClass(), projectionFactory); final TypedQuery<Tuple> query = getTupleQuery(spec, pageable.isPaged() ? pageable.getSort() : Sort.unsorted(), returnedType); final MyResultProcessor resultProcessor = new MyResultProcessor(projectionFactory,returnedType); if (pageable.isPaged()) { query.setFirstResult((int)pageable.getOffset()); query.setMaxResults(pageable.getPageSize()); } final List<R> resultList = resultProcessor.processResult(query.getResultList(), new TupleConverter(returnedType)); final Page<R> page = PageableExecutionUtils.getPage(resultList, pageable, () -> executeCountQuery(this.getCountQuery(spec, getDomainClass()))); return pageable.isUnpaged() ? new PageImpl(resultList) : page; }
Example 7
Source File: PartTreeFirestoreQuery.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Override public Object execute(Object[] parameters) { StructuredQuery.Builder builder = createBuilderWithFilter(parameters); // Handle Pageable parameters. if (!getQueryMethod().getParameters().isEmpty()) { ParameterAccessor paramAccessor = new ParametersParameterAccessor(getQueryMethod().getParameters(), parameters); Pageable pageable = paramAccessor.getPageable(); if (pageable != null && pageable.isPaged()) { builder.setOffset((int) Math.min(Integer.MAX_VALUE, pageable.getOffset())); builder.setLimit(Int32Value.newBuilder().setValue(pageable.getPageSize())); } Sort sort = paramAccessor.getSort(); if (sort != null) { builder.addAllOrderBy(createFirestoreSortOrders(sort)); } } if (this.tree.isCountProjection()) { return this.reactiveOperations.count(this.persistentEntity.getType(), builder); } else { return this.reactiveOperations.execute(builder, this.persistentEntity.getType()); } }
Example 8
Source File: SqlSpannerQuery.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
private List executeReadSql(Pageable pageable, Sort sort, QueryTagValue queryTagValue) { SpannerPageableQueryOptions spannerQueryOptions = new SpannerPageableQueryOptions() .setAllowPartialRead(true); if (sort != null && sort.isSorted()) { spannerQueryOptions.setSort(sort); } if (pageable != null && pageable.isPaged()) { spannerQueryOptions.setOffset(pageable.getOffset()).setLimit(pageable.getPageSize()); } final Class<?> returnedType = getReturnedType(); final SpannerPersistentEntity<?> entity = returnedType == null ? null : this.spannerMappingContext.getPersistentEntity(returnedType); queryTagValue.sql = SpannerStatementQueryExecutor .applySortingPagingQueryOptions(this.entityType, spannerQueryOptions, queryTagValue.sql, this.spannerMappingContext, entity != null && entity.hasEagerlyLoadedProperties()); Statement statement = buildStatementFromQueryAndTags(queryTagValue); return (getReturnedSimpleConvertableItemType() != null) ? this.spannerTemplate.query( (struct) -> new StructAccessor(struct).getSingleValue(0), statement, spannerQueryOptions) : this.spannerTemplate.query(this.entityType, statement, spannerQueryOptions); }
Example 9
Source File: BaseRepositoryImpl.java From halo with GNU General Public License v3.0 | 5 votes |
protected <S extends DOMAIN> Page<S> readPage(TypedQuery<S> query, Class<S> domainClass, Pageable pageable, TypedQuery<Long> countQuery) { if (pageable.isPaged()) { query.setFirstResult((int) pageable.getOffset()); query.setMaxResults(pageable.getPageSize()); } return PageableExecutionUtils.getPage(query.getResultList(), pageable, () -> executeCountQuery(countQuery)); }
Example 10
Source File: PageableSpringEncoder.java From spring-cloud-openfeign with Apache License 2.0 | 5 votes |
@Override public void encode(Object object, Type bodyType, RequestTemplate template) throws EncodeException { if (supports(object)) { if (object instanceof Pageable) { Pageable pageable = (Pageable) object; if (pageable.isPaged()) { template.query(pageParameter, pageable.getPageNumber() + ""); template.query(sizeParameter, pageable.getPageSize() + ""); } if (pageable.getSort() != null) { applySort(template, pageable.getSort()); } } else if (object instanceof Sort) { Sort sort = (Sort) object; applySort(template, sort); } } else { if (delegate != null) { delegate.encode(object, bodyType, template); } else { throw new EncodeException( "PageableSpringEncoder does not support the given object " + object.getClass() + " and no delegate was provided for fallback!"); } } }
Example 11
Source File: PageInfo.java From base-admin with MIT License | 5 votes |
/** * 获取JPA的分页对象 */ public static Page readPage(Query query, Pageable pageable, Query countQuery) { if (pageable.isPaged()) { query.setFirstResult((int) pageable.getOffset()); query.setMaxResults(pageable.getPageSize()); } return PageableExecutionUtils.getPage(query.getResultList(), pageable, () -> executeCountQuery(countQuery)); }
Example 12
Source File: PageInfo.java From springBoot with MIT License | 5 votes |
/** * 获取JPA的分页对象 */ public static Page readPage(Query query, Pageable pageable, Query countQuery) { if (pageable.isPaged()) { query.setFirstResult((int) pageable.getOffset()); query.setMaxResults(pageable.getPageSize()); } return PageableExecutionUtils.getPage(query.getResultList(), pageable, () -> executeCountQuery(countQuery)); }
Example 13
Source File: PageInfo.java From springBoot with MIT License | 5 votes |
/** * 获取JPA的分页对象 */ public static Page readPage(Query query, Pageable pageable, Query countQuery) { if (pageable.isPaged()) { query.setFirstResult((int) pageable.getOffset()); query.setMaxResults(pageable.getPageSize()); } return PageableExecutionUtils.getPage(query.getResultList(), pageable, () -> executeCountQuery(countQuery)); }
Example 14
Source File: CodelessDaoProxy.java From sca-best-practice with Apache License 2.0 | 5 votes |
protected <T> Page<T> readPage(final Class<T> clazz, TypedQuery<T> query, Pageable pageable, @Nullable Specification<T> spec) { if (pageable.isPaged()) { query.setFirstResult((int)pageable.getOffset()); query.setMaxResults(pageable.getPageSize()); } return PageableExecutionUtils.getPage(query.getResultList(), pageable, () -> executeCountQuery(getCountQuery(clazz, spec))); }
Example 15
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 16
Source File: DerivedQueryCreator.java From spring-data with Apache License 2.0 | 4 votes |
/** * Builds a full AQL query from a built Disjunction, additional information from PartTree and special parameters * caught by ArangoParameterAccessor * * @param criteria * @param sort * @return */ @Override protected String complete(final Criteria criteria, final Sort sort) { if (tree.isDistinct() && !tree.isCountProjection()) { LOGGER.debug("Use of 'Distinct' is meaningful only in count queries"); } final StringBuilder query = new StringBuilder(); final String with = withCollections.stream().collect(Collectors.joining(", ")); if (!with.isEmpty()) { query.append("WITH ").append(with).append(" "); } query.append("FOR ").append("e").append(" IN ").append(collectionName); if (!criteria.getPredicate().isEmpty()) { query.append(" FILTER ").append(criteria.getPredicate()); } if (tree.isCountProjection() || tree.isExistsProjection()) { if (tree.isDistinct()) { query.append(" COLLECT entity = ").append("e"); } query.append(" COLLECT WITH COUNT INTO length"); } String sortString = " " + AqlUtils.buildSortClause(sort, "e"); if ((!this.geoFields.isEmpty() || isUnique != null && isUnique) && !tree.isDelete() && !tree.isCountProjection() && !tree.isExistsProjection()) { final String distanceSortKey = " SORT " + Criteria .distance(uniqueLocation, bind(getUniquePoint()[0]), bind(getUniquePoint()[1])).getPredicate(); if (sort.isUnsorted()) { sortString = distanceSortKey; } else { sortString = distanceSortKey + ", " + sortString.substring(5, sortString.length()); } } query.append(sortString); if (tree.isLimiting()) { query.append(" LIMIT ").append(tree.getMaxResults()); } final Pageable pageable = accessor.getPageable(); if (pageable != null && pageable.isPaged()) { query.append(" ").append(AqlUtils.buildLimitClause(pageable)); } if (tree.isDelete()) { query.append(" REMOVE e IN ").append(collectionName); } else if (tree.isCountProjection() || tree.isExistsProjection()) { query.append(" RETURN length"); } else { query.append(" RETURN "); if (this.geoFields.isEmpty()) { query.append("e"); } else { query.append(format("MERGE(e, { '_distance': %s })", Criteria.distance(uniqueLocation, bind(getUniquePoint()[0]), bind(getUniquePoint()[1])) .getPredicate())); } } return query.toString(); }
Example 17
Source File: CodelessDaoProxy.java From sca-best-practice with Apache License 2.0 | 4 votes |
protected <T> TypedQuery<T> getQuery(Class<T> clazz, @Nullable Specification<T> spec, Pageable pageable) { Sort sort = pageable.isPaged() ? pageable.getSort() : Sort.unsorted(); return getQuery(clazz, spec, sort); }
Example 18
Source File: CategoryRepositoryImpl.java From wallride with Apache License 2.0 | 4 votes |
@Override public Page<Category> search(CategorySearchRequest request, Pageable pageable) { FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager); QueryBuilder qb = fullTextEntityManager.getSearchFactory() .buildQueryBuilder() .forEntity(Category.class) .get(); @SuppressWarnings("rawtypes") BooleanJunction<BooleanJunction> junction = qb.bool(); junction.must(qb.all().createQuery()); if (StringUtils.hasText(request.getKeyword())) { Analyzer analyzer = fullTextEntityManager.getSearchFactory().getAnalyzer("synonyms"); String[] fields = new String[] { "name" }; MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, analyzer); parser.setDefaultOperator(QueryParser.Operator.AND); Query query = null; try { query = parser.parse(request.getKeyword()); } catch (ParseException e1) { try { query = parser.parse(QueryParser.escape(request.getKeyword())); } catch (ParseException e2) { throw new RuntimeException(e2); } } junction.must(query); } if (StringUtils.hasText(request.getLanguage())) { junction.must(qb.keyword().onField("language").matching(request.getLanguage()).createQuery()); } Query searchQuery = junction.createQuery(); Session session = (Session) entityManager.getDelegate(); Criteria criteria = session.createCriteria(Category.class); Sort sort = new Sort(new SortField("sortName", SortField.Type.STRING)); FullTextQuery persistenceQuery = fullTextEntityManager .createFullTextQuery(searchQuery, Category.class) .setCriteriaQuery(criteria) .setSort(sort); if (pageable.isPaged()) { persistenceQuery.setFirstResult((int) pageable.getOffset()); persistenceQuery.setMaxResults(pageable.getPageSize()); } int resultSize = persistenceQuery.getResultSize(); @SuppressWarnings("unchecked") List<Category> results = persistenceQuery.getResultList(); return new PageImpl<>(results, pageable, resultSize); }
Example 19
Source File: UserRepositoryImpl.java From wallride with Apache License 2.0 | 4 votes |
private FullTextQuery buildFullTextQuery(UserSearchRequest request, Pageable pageable, Criteria criteria) { FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager); QueryBuilder qb = fullTextEntityManager.getSearchFactory() .buildQueryBuilder() .forEntity(User.class) .get(); @SuppressWarnings("rawtypes") BooleanJunction<BooleanJunction> junction = qb.bool(); junction.must(qb.all().createQuery()); if (StringUtils.hasText(request.getKeyword())) { Analyzer analyzer = fullTextEntityManager.getSearchFactory().getAnalyzer("synonyms"); String[] fields = new String[] { "loginId", "name.firstName", "name.lastName", }; MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, analyzer); parser.setDefaultOperator(QueryParser.Operator.AND); Query query = null; try { query = parser.parse(request.getKeyword()); } catch (ParseException e1) { try { query = parser.parse(QueryParser.escape(request.getKeyword())); } catch (ParseException e2) { throw new RuntimeException(e2); } } junction.must(query); } if (!CollectionUtils.isEmpty(request.getRoles())) { for (User.Role role : request.getRoles()) { junction.must(qb.keyword().onField("roles").matching(role).createQuery()); } } Query searchQuery = junction.createQuery(); Sort sort = new Sort(new SortField("sortId", SortField.Type.LONG, false)); FullTextQuery persistenceQuery = fullTextEntityManager .createFullTextQuery(searchQuery, User.class) .setCriteriaQuery(criteria) // .setProjection("id") .setSort(sort); if (pageable.isPaged()) { persistenceQuery.setFirstResult((int) pageable.getOffset()); persistenceQuery.setMaxResults(pageable.getPageSize()); } return persistenceQuery; }
Example 20
Source File: CustomFieldRepositoryImpl.java From wallride with Apache License 2.0 | 4 votes |
public FullTextQuery buildFullTextQuery(CustomFieldSearchRequest request, Pageable pageable, Criteria criteria) { FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager); QueryBuilder qb = fullTextEntityManager.getSearchFactory() .buildQueryBuilder() .forEntity(CustomField.class) .get(); @SuppressWarnings("rawtypes") BooleanJunction<BooleanJunction> junction = qb.bool(); junction.must(qb.all().createQuery()); if (StringUtils.hasText(request.getKeyword())) { Analyzer analyzer = fullTextEntityManager.getSearchFactory().getAnalyzer("synonyms"); String[] fields = new String[] { "name", "code", "description" }; MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, analyzer); parser.setDefaultOperator(QueryParser.Operator.AND); Query query = null; try { query = parser.parse(request.getKeyword()); } catch (ParseException e1) { try { query = parser.parse(QueryParser.escape(request.getKeyword())); } catch (ParseException e2) { throw new RuntimeException(e2); } } junction.must(query); } if (StringUtils.hasText(request.getLanguage())) { junction.must(qb.keyword().onField("language").matching(request.getLanguage()).createQuery()); } Query searchQuery = junction.createQuery(); Sort sort = new Sort(new SortField("idx", SortField.Type.INT)); FullTextQuery persistenceQuery = fullTextEntityManager .createFullTextQuery(searchQuery, CustomField.class) .setCriteriaQuery(criteria) .setSort(sort); if (pageable.isPaged()) { persistenceQuery.setFirstResult((int) pageable.getOffset()); persistenceQuery.setMaxResults(pageable.getPageSize()); } return persistenceQuery; }