Permalink
Browse files

DATAJPA-1116 - Polishing.

Guard consistently paged/unpaged handling. Fix javadoc.

Original pull request: #203.
1 parent 34d3f81 commit ec9722b2a500d74527ecb93ada25d2f528997f10 @mp911de mp911de committed May 23, 2017
@@ -34,8 +34,8 @@
/**
* 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.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 boolean existsById(ID id) {
*/
public Page<T> findAll(Pageable pageable) {
- if (null == pageable) {
+ if (isUnpaged(pageable)) {
return new PageImpl<T>(findAll());
}
@@ -381,7 +380,7 @@ public boolean existsById(ID id) {
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 boolean existsById(ID id) {
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 long count(Specification<T> spec) {
*/
@Transactional
public void flush() {
-
em.flush();
}
@@ -740,6 +739,10 @@ private static Long executeCountQuery(TypedQuery<Long> query) {
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

0 comments on commit ec9722b

Please sign in to comment.