@Override public Page<T> findAll(Predicate predicate, Pageable pageable) { Assert.notNull(predicate, "Predicate must not be null!"); Assert.notNull(pageable, "Pageable must not be null!"); SpringDataMongodbQuery<T> query = createQueryFor(predicate); return PageableExecutionUtils.getPage(applyPagination(query, pageable).fetch(), pageable, query::fetchCount); }
@Override @SuppressWarnings("unchecked") protected Object doExecute(final AbstractJpaQuery repositoryQuery, final Object[] values) { ParameterAccessor accessor = new ParametersParameterAccessor(parameters, values); Query query = repositoryQuery.createQuery(values); return PageableExecutionUtils.getPage(query.getResultList(), accessor.getPageable(), () -> count(repositoryQuery, values)); }
@Override public Page<T> findAll(Predicate predicate, Pageable pageable) { Assert.notNull(pageable, "Pageable must not be null!"); final JPQLQuery<?> countQuery = createCountQuery(predicate); JPQLQuery<T> query = querydsl.applyPagination(pageable, createQuery(predicate).select(path)); return PageableExecutionUtils.getPage(query.fetch(), pageable, countQuery::fetchCount); }
@Override public Page<T> findAll(Predicate predicate, Pageable pageable) { Assert.notNull(pageable, "Pageable must not be null!"); final JPQLQuery<?> countQuery = createCountQuery(predicate); JPQLQuery<T> query = querydsl.applyPagination(pageable, createQuery(predicate).select(path)); return PageableExecutionUtils.getPage(query.fetch(), pageable, countQuery::fetchCount); }
/** * Reads the given {@link TypedQuery} into a {@link Page} applying the given {@link Pageable} and * {@link Specification}. * * @param query must not be {@literal null}. * @param domainClass must not be {@literal null}. * @param spec can be {@literal null}. * @param pageable can be {@literal null}. * @return */ protected <S extends T> Page<S> readPage(TypedQuery<S> query, final Class<S> domainClass, Pageable pageable, @Nullable Specification<S> spec) { if (pageable.isPaged()) { query.setFirstResult((int) pageable.getOffset()); query.setMaxResults(pageable.getPageSize()); } return PageableExecutionUtils.getPage(query.getResultList(), pageable, () -> executeCountQuery(getCountQuery(spec, domainClass))); }
@Override public <S extends T> Page<S> findAll(final Example<S> example, Pageable pageable) { Assert.notNull(example, "Sample must not be null!"); Assert.notNull(pageable, "Pageable must not be null!"); Query q = new Query(new Criteria().alike(example)).with(pageable); List<S> list = mongoOperations.find(q, example.getProbeType(), entityInformation.getCollectionName()); return PageableExecutionUtils.getPage(list, pageable, () -> mongoOperations.count(q, example.getProbeType(), entityInformation.getCollectionName())); }
@Override public Object execute(Query query) { int overallLimit = query.getLimit(); TerminatingFind<?> matching = operation.matching(query); // Apply raw pagination query.with(pageable); // Adjust limit if page would exceed the overall limit if (overallLimit != 0 && pageable.getOffset() + pageable.getPageSize() > overallLimit) { query.limit((int) (overallLimit - pageable.getOffset())); } return PageableExecutionUtils.getPage(matching.all(), pageable, () -> { long count = matching.count(); return overallLimit != 0 ? Math.min(count, overallLimit) : count; }); } }
@Override public Object execute(Query query) { GeoResults<Object> geoResults = doExecuteQuery(query); Page<GeoResult<Object>> page = PageableExecutionUtils.getPage(geoResults.getContent(), accessor.getPageable(), () -> { Query countQuery = mongoQuery.createCountQuery(accessor); countQuery = mongoQuery.applyQueryMetaAttributesWhenPresent(countQuery); return operation.matching(countQuery).count(); }); // transform to GeoPage after applying optimization return new GeoPage<>(geoResults, accessor.getPageable(), page.getTotalElements()); } }
@Override public Page<T> findAll(Predicate predicate, Pageable pageable) { Assert.notNull(predicate, "Predicate must not be null!"); Assert.notNull(pageable, "Pageable must not be null!"); SpringDataMongodbQuery<T> query = createQueryFor(predicate); return PageableExecutionUtils.getPage(applyPagination(query, pageable).fetch(), pageable, query::fetchCount); }
@Override public Page<T> findAll(Pageable pageable, int depth) { Pagination pagination = new Pagination(pageable.getPageNumber(), pageable.getPageSize()); Collection<T> data = session.loadAll(clazz, PagingAndSortingUtils.convert(pageable.getSort()), pagination, depth); return PageableExecutionUtils.getPage(new ArrayList<>(data), pageable, () -> session.countEntitiesOfType(clazz)); } }
@Override public <S extends T> Page<S> findAll(final Example<S> example, Pageable pageable) { Assert.notNull(example, "Sample must not be null!"); Assert.notNull(pageable, "Pageable must not be null!"); Query q = new Query(new Criteria().alike(example)).with(pageable); List<S> list = mongoOperations.find(q, example.getProbeType(), entityInformation.getCollectionName()); return PageableExecutionUtils.getPage(list, pageable, () -> mongoOperations.count(q, example.getProbeType(), entityInformation.getCollectionName())); }
@Override public Object execute(Query query) { int overallLimit = query.getLimit(); TerminatingFind<?> matching = operation.matching(query); // Apply raw pagination query.with(pageable); // Adjust limit if page would exceed the overall limit if (overallLimit != 0 && pageable.getOffset() + pageable.getPageSize() > overallLimit) { query.limit((int) (overallLimit - pageable.getOffset())); } return PageableExecutionUtils.getPage(matching.all(), pageable, () -> { long count = matching.count(); return overallLimit != 0 ? Math.min(count, overallLimit) : count; }); } }
@Override public Object execute(Query query) { GeoResults<Object> geoResults = doExecuteQuery(query); Page<GeoResult<Object>> page = PageableExecutionUtils.getPage(geoResults.getContent(), accessor.getPageable(), () -> { Query countQuery = mongoQuery.createCountQuery(accessor); countQuery = mongoQuery.applyQueryMetaAttributesWhenPresent(countQuery); return operation.matching(countQuery).count(); }); // transform to GeoPage after applying optimization return new GeoPage<>(geoResults, accessor.getPageable(), page.getTotalElements()); } }
@Override public Object execute(Query query, Class<?> type) { List<?> result; long count; if (query.isFilterQuery()) { result = (List<?>) session.loadAll(type, query.getFilters(), accessor.getOgmSort(), query.getPagination(pageable, false), accessor.getDepth()); count = session.count(type, query.getFilters()); } else { if (type.getAnnotation(QueryResult.class) != null) { result = (List<?>) session.query(query.getCypherQuery(pageable, false), query.getParameters()).queryResults(); } else { result = (List<?>) session.query(type, query.getCypherQuery(pageable, false), query.getParameters()); } count = (result.size() > 0) ? countTotalNumberOfElements(query) : 0; } return PageableExecutionUtils.getPage(result, pageable, (LongSupplier) () -> count); }
@Override @SuppressWarnings("unchecked") protected Object doExecute(final AbstractJpaQuery repositoryQuery, final Object[] values) { ParameterAccessor accessor = new ParametersParameterAccessor(parameters, values); Query query = repositoryQuery.createQuery(values); return PageableExecutionUtils.getPage(query.getResultList(), accessor.getPageable(), () -> count(repositoryQuery, values)); }
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))); }
@Override public Page<T> findAll(Predicate predicate, Pageable pageable) { Assert.notNull(pageable, "Pageable must not be null!"); final JPQLQuery<?> countQuery = createCountQuery(predicate); JPQLQuery<T> query = querydsl.applyPagination(pageable, createQuery(predicate).select(path)); return PageableExecutionUtils.getPage(query.fetch(), pageable, countQuery::fetchCount); }
@Override public Page<T> findAll(Predicate predicate, Pageable pageable) { Assert.notNull(pageable, "Pageable must not be null!"); final JPQLQuery<?> countQuery = createCountQuery(predicate); JPQLQuery<T> query = querydsl.applyPagination(pageable, createQuery(predicate).select(path)); return PageableExecutionUtils.getPage(query.fetch(), pageable, countQuery::fetchCount); }
@SuppressWarnings("unchecked") <E> Page<E> findPage(Pageable pageable) { if (queryType == QUERY) { PagedList<E> pagedList = ((Query<E>) queryInstance) .setFirstRow((int) pageable.getOffset()) .setMaxRows(pageable.getPageSize()) .findPagedList(); return PageableExecutionUtils.getPage(pagedList.getList(), pageable, pagedList::getTotalCount); } throw new IllegalArgumentException("query not supported!"); }
/** * Finds page by provided {@link Query} and {@link Pageable} criterias * * @param q Query for entity * @param p Pageable descriptor * @return Page of entities */ Page<T> findPage(Query q, Pageable p) { Class<T> entityType = getEntityInformation().getJavaType(); List<T> content = getMongoOperations().find(q, entityType); return PageableExecutionUtils.getPage(content, p, () -> getMongoOperations().count(q, entityType)); }