Skip to content

Commit 5f3671f

Browse files
committed
DATAMONGO-996 - Fixed boundary detection in pagination.
The fix for DATAMONGO-950 introduced a tiny glitch so that retrieving pages after the first one was broken in the repository query execution. We now correctly use the previously detected number of elements to detect whether the Pageable given is out of scope. Related ticket: DATAMONGO-950.
1 parent 1335cb6 commit 5f3671f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/AbstractMongoQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ Object execute(Query query) {
260260
long count = operations.count(query, metadata.getCollectionName());
261261
count = overallLimit != 0 ? Math.min(count, query.getLimit()) : count;
262262

263-
boolean pageableOutOfScope = pageable.getOffset() > query.getLimit();
263+
boolean pageableOutOfScope = pageable.getOffset() > count;
264264

265265
if (pageableOutOfScope) {
266266
return new PageImpl<Object>(Collections.emptyList(), pageable, count);

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,19 @@ public void shouldReturnEmptyWhenPageRequestedPageIsTotallyOutOfScopeForLimit()
969969
assertThat(result.getContent().size(), is(0));
970970
}
971971

972+
/**
973+
* @see DATAMONGO-996, DATAMONGO-950
974+
*/
975+
@Test
976+
public void gettingNonFirstPageWorksWithoutLimitBeingSet() {
977+
978+
Page<Person> slice = repository.findByLastnameLike("Matthews", new PageRequest(1, 1));
979+
980+
assertThat(slice.getContent(), hasSize(1));
981+
assertThat(slice.hasPrevious(), is(true));
982+
assertThat(slice.hasNext(), is(false));
983+
}
984+
972985
/**
973986
* Ignored for now as this requires Querydsl 3.4.1 to succeed.
974987
*

0 commit comments

Comments
 (0)