Skip to content

Commit

Permalink
Apply sort from unpaged Pageable to query.
Browse files Browse the repository at this point in the history
This commit makes sure to pass on a given Sort from an unpaged Pageable to the actual query.

Closes: #3476
Original Pull Request: #3517
  • Loading branch information
birariro authored and christophstrobl committed Jul 4, 2024
1 parent c0ae93c commit 38a11d0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,6 @@ public List<T> findAll(Sort sort) {

@Override
public Page<T> findAll(Pageable pageable) {

if (pageable.isUnpaged()) {
return new PageImpl<>(findAll());
}

return findAll((Specification<T>) null, pageable);
}

Expand Down Expand Up @@ -717,8 +712,7 @@ protected <S extends T> Page<S> readPage(TypedQuery<S> query, final Class<S> dom
*/
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());
}

/**
Expand All @@ -731,8 +725,7 @@ protected TypedQuery<T> getQuery(@Nullable Specification<T> spec, Pageable pagea
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());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2887,6 +2887,18 @@ void existsByExampleNegative() {
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() {

Expand Down

0 comments on commit 38a11d0

Please sign in to comment.