Skip to content

Commit 68370c1

Browse files
mp911dechristophstrobl
authored andcommitted
Run unpaged query using Pageable.unpaged() through QuerydslMongoPredicateExecutor.findAll(…).
We now correctly consider unpaged queries if the Pageable is unpaged. Closes: spring-projects#3751 Original Pull Request: spring-projects#3754
1 parent d2c9b47 commit 68370c1

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/QuerydslMongoPredicateExecutor.java

+4
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ private SpringDataMongodbQuery<T> createQuery() {
212212
*/
213213
private SpringDataMongodbQuery<T> applyPagination(SpringDataMongodbQuery<T> query, Pageable pageable) {
214214

215+
if (pageable.isUnpaged()) {
216+
return query;
217+
}
218+
215219
query = query.offset(pageable.getOffset()).limit(pageable.getPageSize());
216220
return applySorting(query, pageable.getSort());
217221
}

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/support/QuerydslMongoPredicateExecutorIntegrationTests.java

+16
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import org.springframework.beans.factory.annotation.Autowired;
2828
import org.springframework.dao.IncorrectResultSizeDataAccessException;
2929
import org.springframework.dao.PermissionDeniedDataAccessException;
30+
import org.springframework.data.domain.PageRequest;
31+
import org.springframework.data.domain.Pageable;
3032
import org.springframework.data.domain.Sort;
3133
import org.springframework.data.domain.Sort.Direction;
3234
import org.springframework.data.mongodb.MongoDatabaseFactory;
@@ -122,6 +124,20 @@ public void findUsingAndShouldWork() {
122124
.containsExactly(dave);
123125
}
124126

127+
@Test // GH-3751
128+
public void findPage() {
129+
130+
assertThat(repository
131+
.findAll(person.lastname.startsWith(oliver.getLastname()).and(person.firstname.startsWith(dave.getFirstname())),
132+
PageRequest.of(0, 10))
133+
.getContent()).containsExactly(dave);
134+
135+
assertThat(repository
136+
.findAll(person.lastname.startsWith(oliver.getLastname()).and(person.firstname.startsWith(dave.getFirstname())),
137+
Pageable.unpaged())
138+
.getContent()).containsExactly(dave);
139+
}
140+
125141
@Test // DATAMONGO-362, DATAMONGO-1848
126142
public void springDataMongodbQueryShouldAllowJoinOnDBref() {
127143

0 commit comments

Comments
 (0)