congrats Icon
New! Announcing our next generation AI code completions
Read here
Tabnine Logo
PageableExecutionUtils
Code IndexAdd Tabnine to your IDE (free)

How to use
PageableExecutionUtils
in
org.springframework.data.repository.support

Best Java code snippets using org.springframework.data.repository.support.PageableExecutionUtils (Showing top 20 results out of 315)

origin: spring-projects/spring-data-mongodb

@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);
}
origin: spring-projects/spring-data-jpa

@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));
}
origin: spring-projects/spring-data-jpa

@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);
}
origin: spring-projects/spring-data-jpa

@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);
}
origin: spring-projects/spring-data-jpa

/**
 * 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)));
}
origin: spring-projects/spring-data-mongodb

@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()));
}
origin: spring-projects/spring-data-mongodb

  @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;
    });
  }
}
origin: spring-projects/spring-data-mongodb

  @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());
  }
}
origin: org.springframework.data/spring-data-mongodb

@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);
}
origin: spring-projects/spring-data-neo4j

  @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));
  }
}
origin: org.springframework.data/spring-data-mongodb

@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()));
}
origin: org.springframework.data/spring-data-mongodb

  @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;
    });
  }
}
origin: org.springframework.data/spring-data-mongodb

  @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());
  }
}
origin: spring-projects/spring-data-neo4j

@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);
}
origin: com.epam.reportportal/commons-dao

private <T> Page<T> pageByQuery(Query q,Pageable p, Class<T> clazz) {
  List<T> content = mongoTemplate.find(q, clazz);
  return PageableExecutionUtils.getPage(content, p, () -> mongoTemplate.count(q, clazz));
}
origin: org.springframework.data/spring-data-jpa

@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));
}
origin: alibaba/sca-best-practice

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)));
}
origin: org.springframework.data/spring-data-jpa

@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);
}
origin: org.springframework.data/spring-data-jpa

/**
 * 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)));
}
origin: org.springframework.data/spring-data-jpa

@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);
}
org.springframework.data.repository.supportPageableExecutionUtils

Javadoc

Support for query execution using Pageable. Using PageableExecutionUtils assumes that data queries are cheaper than COUNT queries and so some cases can take advantage of optimizations.

Most used methods

  • getPage

Popular in Java

  • Start an intent from android
  • getExternalFilesDir (Context)
  • onCreateOptionsMenu (Activity)
  • setRequestProperty (URLConnection)
  • URLConnection (java.net)
    A connection to a URL for reading or writing. For HTTP connections, see HttpURLConnection for docume
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • Enumeration (java.util)
    A legacy iteration interface.New code should use Iterator instead. Iterator replaces the enumeration
  • PriorityQueue (java.util)
    A PriorityQueue holds elements on a priority heap, which orders the elements according to their natu
  • ZipFile (java.util.zip)
    This class provides random read access to a zip file. You pay more to read the zip file's central di
  • DataSource (javax.sql)
    An interface for the creation of Connection objects which represent a connection to a database. This
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now