Consider sort order for unpaged Pageable in Querydsl.

We now apply sorting using Querydsl for Pageable that is sorted but not paged.

Closes #3761
This commit is contained in:
Mark Paluch
2025-02-05 08:54:33 +01:00
parent 0037b813c9
commit 412e5eee28
3 changed files with 11 additions and 8 deletions

View File

@@ -108,12 +108,11 @@ public class Querydsl {
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);
}

View File

@@ -723,7 +723,6 @@ public class SimpleJpaRepository<T, ID> implements JpaRepositoryImplementation<T
* @param pageable must not be {@literal null}.
*/
protected TypedQuery<T> getQuery(@Nullable Specification<T> spec, Pageable pageable) {
return getQuery(spec, getDomainClass(), pageable.getSort());
}
@@ -736,7 +735,6 @@ public class SimpleJpaRepository<T, ID> implements JpaRepositoryImplementation<T
*/
protected <S extends T> TypedQuery<S> getQuery(@Nullable Specification<S> spec, Class<S> domainClass,
Pageable pageable) {
return getQuery(spec, domainClass, pageable.getSort());
}

View File

@@ -282,9 +282,15 @@ class QuerydslJpaPredicateExecutorUnitTests {
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