DATAJPA-1116 - Polishing.
Guard consistently paged/unpaged handling. Fix javadoc. Original pull request: #203.
This commit is contained in:
@@ -34,8 +34,8 @@ 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
|
||||
* @param spec can be {@literal null}.
|
||||
* @return never {@literal null}.
|
||||
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException if more than one entity found.
|
||||
*/
|
||||
Optional<T> findOne(Specification<T> spec);
|
||||
|
||||
@@ -56,7 +56,6 @@ import org.springframework.data.repository.support.PageableExecutionUtils;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Default implementation of the {@link org.springframework.data.repository.CrudRepository} interface. This will offer
|
||||
@@ -346,7 +345,7 @@ public class SimpleJpaRepository<T, ID> implements JpaRepository<T, ID>, JpaSpec
|
||||
*/
|
||||
public Page<T> findAll(Pageable pageable) {
|
||||
|
||||
if (null == pageable) {
|
||||
if (isUnpaged(pageable)) {
|
||||
return new PageImpl<T>(findAll());
|
||||
}
|
||||
|
||||
@@ -381,7 +380,7 @@ public class SimpleJpaRepository<T, ID> implements JpaRepository<T, ID>, JpaSpec
|
||||
public Page<T> findAll(Specification<T> spec, Pageable pageable) {
|
||||
|
||||
TypedQuery<T> query = getQuery(spec, pageable);
|
||||
return (pageable == null || pageable.isUnpaged()) ? new PageImpl<T>(query.getResultList())
|
||||
return isUnpaged(pageable) ? new PageImpl<T>(query.getResultList())
|
||||
: readPage(query, getDomainClass(), pageable, spec);
|
||||
}
|
||||
|
||||
@@ -456,7 +455,8 @@ public class SimpleJpaRepository<T, ID> implements JpaRepository<T, ID>, JpaSpec
|
||||
Class<S> probeType = example.getProbeType();
|
||||
TypedQuery<S> query = getQuery(new ExampleSpecification<>(example), probeType, pageable);
|
||||
|
||||
return pageable == null ? new PageImpl<>(query.getResultList()) : readPage(query, probeType, pageable, spec);
|
||||
return isUnpaged(pageable) ? new PageImpl<>(query.getResultList())
|
||||
: readPage(query, probeType, pageable, spec);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -529,7 +529,6 @@ public class SimpleJpaRepository<T, ID> implements JpaRepository<T, ID>, JpaSpec
|
||||
*/
|
||||
@Transactional
|
||||
public void flush() {
|
||||
|
||||
em.flush();
|
||||
}
|
||||
|
||||
@@ -740,6 +739,10 @@ public class SimpleJpaRepository<T, ID> implements JpaRepository<T, ID>, JpaSpec
|
||||
return total;
|
||||
}
|
||||
|
||||
private static boolean isUnpaged(Pageable pageable) {
|
||||
return pageable == null || pageable.isUnpaged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Specification that gives access to the {@link Parameter} instance used to bind the ids for
|
||||
* {@link SimpleJpaRepository#findAllById(Iterable)}. Workaround for OpenJPA not binding collections to in-clauses
|
||||
|
||||
Reference in New Issue
Block a user