Skip to content

Commit

Permalink
DATAJPA-1116 - Polishing.
Browse files Browse the repository at this point in the history
Remove whitespaces and update JavaDoc.
Use Pageable.isUnpaged() & Sort.isUnsorted() where possible.
  • Loading branch information
christophstrobl committed May 12, 2017
1 parent 8f97cff commit 836a56f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@

/**
* Interface to allow execution of {@link Specification}s based on the JPA criteria API.
*
*
* @author Oliver Gierke
* @author Christoph Strobl
*/
public interface JpaSpecificationExecutor<T> {

/**
* Returns a single entity matching the given {@link Specification} or {@link Optional#empty()} if none found.
*
*
* @param spec can be @literal {@null}.
* @return
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException if more than one entity found.
Expand All @@ -42,35 +42,35 @@ public interface JpaSpecificationExecutor<T> {

/**
* Returns all entities matching the given {@link Specification}.
*
* @param spec
* @return
*
* @param spec can be {@literal null}.
* @return never {@literal null}.
*/
List<T> findAll(Specification<T> spec);

/**
* Returns a {@link Page} of entities matching the given {@link Specification}.
*
* @param spec
* @param pageable
* @return
*
* @param spec can be {@literal null}.
* @param pageable can be {@literal null}.
* @return never {@literal null}.
*/
Page<T> findAll(Specification<T> spec, Pageable pageable);

/**
* Returns all entities matching the given {@link Specification} and {@link Sort}.
*
* @param spec
* @param sort
* @return
*
* @param spec can be {@literal null}.
* @param sort can be {@literal null}.
* @return never {@literal null}.
*/
List<T> findAll(Specification<T> spec, Sort sort);

/**
* Returns the number of instances that the given {@link Specification} will return.
*
* @param spec the {@link Specification} to count instances for
* @return the number of instances
*
* @param spec the {@link Specification} to count instances for. Can be {@literal null}.
* @return the number of instances.
*/
long count(Specification<T> spec);
}
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ public List<T> findAll(Specification<T> spec) {
public Page<T> findAll(Specification<T> spec, Pageable pageable) {

TypedQuery<T> query = getQuery(spec, pageable);
return pageable == null ? new PageImpl<T>(query.getResultList())
return (pageable == null || pageable.isUnpaged()) ? new PageImpl<T>(query.getResultList())
: readPage(query, getDomainClass(), pageable, spec);
}

Expand Down Expand Up @@ -452,11 +452,11 @@ public <S extends T> List<S> findAll(Example<S> example, Sort sort) {
@Override
public <S extends T> Page<S> findAll(Example<S> example, Pageable pageable) {

ExampleSpecification<S> spec = new ExampleSpecification<S>(example);
ExampleSpecification<S> spec = new ExampleSpecification<>(example);
Class<S> probeType = example.getProbeType();
TypedQuery<S> query = getQuery(new ExampleSpecification<S>(example), probeType, pageable);
TypedQuery<S> query = getQuery(new ExampleSpecification<>(example), probeType, pageable);

return pageable == null ? new PageImpl<S>(query.getResultList()) : readPage(query, probeType, pageable, spec);
return pageable == null ? new PageImpl<>(query.getResultList()) : readPage(query, probeType, pageable, spec);
}

/*
Expand Down Expand Up @@ -624,7 +624,7 @@ protected <S extends T> TypedQuery<S> getQuery(Specification<S> spec, Class<S> d
Root<S> root = applySpecificationToCriteria(spec, domainClass, query);
query.select(root);

if (sort != null && !ObjectUtils.nullSafeEquals(sort, Sort.unsorted())) {
if (sort != null && !sort.isUnsorted()) {
query.orderBy(toOrders(sort, root, builder));
}

Expand Down

0 comments on commit 836a56f

Please sign in to comment.