@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 <T> T invokeSave(T object) { return delegate.invokeSave(object); } }
@Override public Optional<Object> invokeQueryMethod(Method method, MultiValueMap<String, ? extends Object> parameters, Pageable pageable, Sort sort) { return delegate.invokeQueryMethod(method, parameters, pageable, sort); }
@Override public boolean supports(Class<?> delimiter) { return repositories.hasRepositoryFor(delimiter); }
@Override public void invokeDeleteById(Object id) { delegate.invokeDeleteById(id); }
@Override public Iterable<Object> invokeFindAll(Pageable pageable) { return delegate.invokeFindAll(pageable); }
@Override public boolean hasDeleteMethod() { return delegate.hasDeleteMethod(); }
@Override public boolean hasFindOneMethod() { return delegate.hasFindOneMethod(); }
@Override public boolean hasSaveMethod() { return delegate.hasSaveMethod(); }
@Override public boolean hasFindAllMethod() { return delegate.hasFindAllMethod(); }
private ReferencedProperty(PersistentProperty<?> property, Object propertyValue, PersistentPropertyAccessor wrapper) { this.property = property; this.propertyValue = propertyValue; this.accessor = wrapper; this.propertyType = property.getActualType(); this.entity = repositories.getPersistentEntity(propertyType); }
@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 boolean hasMappingFor(Class<?> type) { if (super.hasMappingFor(type)) { return true; } if (repositories.hasRepositoryFor(type)) { return true; } return false; }
@Override public Iterable<Object> invokeFindAll(Sort sort) { return delegate.invokeFindAll(sort); }
@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()); } }