diff --git a/src/main/java/org/springframework/data/jpa/repository/JpaSpecificationExecutor.java b/src/main/java/org/springframework/data/jpa/repository/JpaSpecificationExecutor.java index 612522bbd..ef749f6b5 100644 --- a/src/main/java/org/springframework/data/jpa/repository/JpaSpecificationExecutor.java +++ b/src/main/java/org/springframework/data/jpa/repository/JpaSpecificationExecutor.java @@ -25,7 +25,7 @@ import org.springframework.data.jpa.domain.Specification; /** * Interface to allow execution of {@link Specification}s based on the JPA criteria API. - * + * * @author Oliver Gierke * @author Christoph Strobl */ @@ -33,7 +33,7 @@ public interface JpaSpecificationExecutor { /** * 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. @@ -42,35 +42,35 @@ public interface JpaSpecificationExecutor { /** * Returns all entities matching the given {@link Specification}. - * - * @param spec - * @return + * + * @param spec can be {@literal null}. + * @return never {@literal null}. */ List findAll(Specification 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 findAll(Specification 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 findAll(Specification 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 spec); } diff --git a/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java b/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java index 2adb0584a..257d24488 100644 --- a/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java +++ b/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java @@ -381,7 +381,7 @@ public class SimpleJpaRepository implements JpaRepository, JpaSpec public Page findAll(Specification spec, Pageable pageable) { TypedQuery query = getQuery(spec, pageable); - return pageable == null ? new PageImpl(query.getResultList()) + return (pageable == null || pageable.isUnpaged()) ? new PageImpl(query.getResultList()) : readPage(query, getDomainClass(), pageable, spec); } @@ -452,11 +452,11 @@ public class SimpleJpaRepository implements JpaRepository, JpaSpec @Override public Page findAll(Example example, Pageable pageable) { - ExampleSpecification spec = new ExampleSpecification(example); + ExampleSpecification spec = new ExampleSpecification<>(example); Class probeType = example.getProbeType(); - TypedQuery query = getQuery(new ExampleSpecification(example), probeType, pageable); + TypedQuery query = getQuery(new ExampleSpecification<>(example), probeType, pageable); - return pageable == null ? new PageImpl(query.getResultList()) : readPage(query, probeType, pageable, spec); + return pageable == null ? new PageImpl<>(query.getResultList()) : readPage(query, probeType, pageable, spec); } /* @@ -624,7 +624,7 @@ public class SimpleJpaRepository implements JpaRepository, JpaSpec Root 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)); }