Skip to content

Commit a9b9655

Browse files
committed
Consider sort order for unpaged Pageable in Querydsl.
We now apply sorting using Querydsl for Pageable that is sorted but not paged. Closes #3761
1 parent 33d3724 commit a9b9655

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/Querydsl.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,11 @@ public <T> JPQLQuery<T> applyPagination(Pageable pageable, JPQLQuery<T> query) {
124124
Assert.notNull(pageable, "Pageable must not be null");
125125
Assert.notNull(query, "JPQLQuery must not be null");
126126

127-
if (pageable.isUnpaged()) {
128-
return query;
129-
}
127+
if (pageable.isPaged()) {
130128

131-
query.offset(pageable.getOffset());
132-
query.limit(pageable.getPageSize());
129+
query.offset(pageable.getOffset());
130+
query.limit(pageable.getPageSize());
131+
}
133132

134133
return applySorting(pageable.getSort(), query);
135134
}

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java

-2
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,6 @@ protected <S extends T> Page<S> readPage(TypedQuery<S> query, Class<S> domainCla
738738
* @param pageable must not be {@literal null}.
739739
*/
740740
protected TypedQuery<T> getQuery(Specification<T> spec, Pageable pageable) {
741-
742741
return getQuery(spec, getDomainClass(), pageable.getSort());
743742
}
744743

@@ -750,7 +749,6 @@ protected TypedQuery<T> getQuery(Specification<T> spec, Pageable pageable) {
750749
* @param pageable must not be {@literal null}.
751750
*/
752751
protected <S extends T> TypedQuery<S> getQuery(Specification<S> spec, Class<S> domainClass, Pageable pageable) {
753-
754752
return getQuery(spec, domainClass, pageable.getSort());
755753
}
756754

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/support/QuerydslJpaPredicateExecutorUnitTests.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,15 @@ void shouldSupportFindAllWithPredicateAndSort() {
282282
assertThat(users).contains(carter, dave, oliver);
283283
}
284284

285-
@Test // DATAJPA-585
285+
@Test // DATAJPA-585, 3761
286286
void worksWithUnpagedPageable() {
287+
287288
assertThat(predicateExecutor.findAll(user.dateOfBirth.isNull(), Pageable.unpaged()).getContent()).hasSize(3);
289+
290+
Page<User> users = predicateExecutor.findAll(user.dateOfBirth.isNull(),
291+
Pageable.unpaged(Sort.by(Direction.ASC, "firstname")));
292+
293+
assertThat(users).containsExactly(carter, dave, oliver);
288294
}
289295

290296
@Test // DATAJPA-912

0 commit comments

Comments
 (0)