Skip to content

Commit

Permalink
support Pageable.unpaged(sort)
Browse files Browse the repository at this point in the history
Resolves: spring-projects#3476
Original pull request: spring-projects#3514
  • Loading branch information
yoa1226 committed Jun 18, 2024
1 parent 3351350 commit 835aba0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,9 @@ public List<T> findAll(Sort sort) {
public Page<T> findAll(Pageable pageable) {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1727,6 +1727,22 @@ void pageableQueryReportsTotalFromCount() {
assertThat(secondPage.getTotalElements()).isEqualTo(4L);
}

@Test // GH-3476
void unPageableQueryUnPagedSorted() {

flushTestUsers();

Page<User> firstPage = repository.findAll(PageRequest.of(0, 10));
assertThat(firstPage.getContent()).hasSize(4);
assertThat(firstPage.getTotalElements()).isEqualTo(4L);


Page<User> secondPage = repository.findAll(Pageable.unpaged(Sort.by(DESC, "age")));
assertThat(secondPage.getContent()).hasSize(4);
assertThat(secondPage.getContent()).containsExactly(thirdUser, secondUser, fourthUser, firstUser);
assertThat(secondPage.getTotalElements()).isEqualTo(4L);
}

@Test // DATAJPA-506
void invokesQueryWithWrapperType() {

Expand Down

0 comments on commit 835aba0

Please sign in to comment.