Apply sort from unpaged Pageable to query.
This commit makes sure to pass on a given Sort from an unpaged Pageable to the actual query. Closes: #3476 Original Pull Request: #3517
This commit is contained in:
committed by
Christoph Strobl
parent
c0ae93c9af
commit
38a11d0445
@@ -426,11 +426,6 @@ public class SimpleJpaRepository<T, ID> implements JpaRepositoryImplementation<T
|
||||
|
||||
@Override
|
||||
public Page<T> findAll(Pageable pageable) {
|
||||
|
||||
if (pageable.isUnpaged()) {
|
||||
return new PageImpl<>(findAll());
|
||||
}
|
||||
|
||||
return findAll((Specification<T>) null, pageable);
|
||||
}
|
||||
|
||||
@@ -717,8 +712,7 @@ public class SimpleJpaRepository<T, ID> implements JpaRepositoryImplementation<T
|
||||
*/
|
||||
protected TypedQuery<T> getQuery(@Nullable Specification<T> spec, Pageable pageable) {
|
||||
|
||||
Sort sort = pageable.isPaged() ? pageable.getSort() : Sort.unsorted();
|
||||
return getQuery(spec, getDomainClass(), sort);
|
||||
return getQuery(spec, getDomainClass(), pageable.getSort());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -731,8 +725,7 @@ public class SimpleJpaRepository<T, ID> implements JpaRepositoryImplementation<T
|
||||
protected <S extends T> TypedQuery<S> getQuery(@Nullable Specification<S> spec, Class<S> domainClass,
|
||||
Pageable pageable) {
|
||||
|
||||
Sort sort = pageable.isPaged() ? pageable.getSort() : Sort.unsorted();
|
||||
return getQuery(spec, domainClass, sort);
|
||||
return getQuery(spec, domainClass, pageable.getSort());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2887,6 +2887,18 @@ class UserRepositoryTests {
|
||||
assertThat(exists).isFalse();
|
||||
}
|
||||
|
||||
@Test // GH-3476
|
||||
void unPagedSortedQuery() {
|
||||
|
||||
flushTestUsers();
|
||||
|
||||
Sort sort = Sort.by(DESC, "firstname");
|
||||
Page<User> firstPage = repository.findAll(PageRequest.of(0, 10, sort));
|
||||
Page<User> secondPage = repository.findAll(Pageable.unpaged(sort));
|
||||
assertThat(firstPage.getContent()).isEqualTo(secondPage.getContent());
|
||||
}
|
||||
|
||||
|
||||
@Test // DATAJPA-905
|
||||
void executesPagedSpecificationSettingAnOrder() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user