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.
This commit is contained in:
Oliver Gierke
2014-07-18 19:01:44 +02:00
parent 1335cb699b
commit 5f3671f349
2 changed files with 14 additions and 1 deletions

View File

@@ -260,7 +260,7 @@ public abstract class AbstractMongoQuery implements RepositoryQuery {
long count = operations.count(query, metadata.getCollectionName());
count = overallLimit != 0 ? Math.min(count, query.getLimit()) : count;
boolean pageableOutOfScope = pageable.getOffset() > query.getLimit();
boolean pageableOutOfScope = pageable.getOffset() > count;
if (pageableOutOfScope) {
return new PageImpl<Object>(Collections.emptyList(), pageable, count);

View File

@@ -969,6 +969,19 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
assertThat(result.getContent().size(), is(0));
}
/**
* @see DATAMONGO-996, DATAMONGO-950
*/
@Test
public void gettingNonFirstPageWorksWithoutLimitBeingSet() {
Page<Person> slice = repository.findByLastnameLike("Matthews", new PageRequest(1, 1));
assertThat(slice.getContent(), hasSize(1));
assertThat(slice.hasPrevious(), is(true));
assertThat(slice.hasNext(), is(false));
}
/**
* Ignored for now as this requires Querydsl 3.4.1 to succeed.
*