Skip to content

Commit

Permalink
Consider sort order for unpaged Pageable in Querydsl.
Browse files Browse the repository at this point in the history
We now apply sorting using Querydsl for Pageable that is sorted but not paged.

Closes #3761
  • Loading branch information
mp911de committed Feb 5, 2025
1 parent 0037b81 commit 412e5ee
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,11 @@ public <T> JPQLQuery<T> applyPagination(Pageable pageable, JPQLQuery<T> query) {
Assert.notNull(pageable, "Pageable must not be null");
Assert.notNull(query, "JPQLQuery must not be null");

if (pageable.isUnpaged()) {
return query;
}
if (pageable.isPaged()) {

query.offset(pageable.getOffset());
query.limit(pageable.getPageSize());
query.offset(pageable.getOffset());
query.limit(pageable.getPageSize());
}

return applySorting(pageable.getSort(), query);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,6 @@ protected <S extends T> Page<S> readPage(TypedQuery<S> query, final Class<S> dom
* @param pageable must not be {@literal null}.
*/
protected TypedQuery<T> getQuery(@Nullable Specification<T> spec, Pageable pageable) {

return getQuery(spec, getDomainClass(), pageable.getSort());
}

Expand All @@ -736,7 +735,6 @@ 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) {

return getQuery(spec, domainClass, pageable.getSort());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,15 @@ void shouldSupportFindAllWithPredicateAndSort() {
assertThat(users).contains(carter, dave, oliver);
}

@Test // DATAJPA-585
@Test // DATAJPA-585, 3761
void worksWithUnpagedPageable() {

assertThat(predicateExecutor.findAll(user.dateOfBirth.isNull(), Pageable.unpaged()).getContent()).hasSize(3);

Page<User> users = predicateExecutor.findAll(user.dateOfBirth.isNull(),
Pageable.unpaged(Sort.by(Direction.ASC, "firstname")));

assertThat(users).containsExactly(carter, dave, oliver);
}

@Test // DATAJPA-912
Expand Down

0 comments on commit 412e5ee

Please sign in to comment.