DATAREDIS-551 - Fix pageable query execution when derived criteria is empty.
We now make sure to count records without using criteria when derived criteria is empty. This allows usage of declared query methods using `Pageable` without criteria like `findBy(Pageable page)`. Original Pull Request: #220
This commit is contained in:
committed by
Christoph Strobl
parent
6280bd20b9
commit
a47bd23cef
@@ -40,6 +40,7 @@ import org.springframework.util.CollectionUtils;
|
||||
* Redis specific {@link QueryEngine} implementation.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
* @since 1.7
|
||||
*/
|
||||
class RedisQueryEngine extends QueryEngine<RedisKeyValueAdapter, RedisOperationChain, Comparator<?>> {
|
||||
@@ -156,6 +157,10 @@ class RedisQueryEngine extends QueryEngine<RedisKeyValueAdapter, RedisOperationC
|
||||
@Override
|
||||
public long count(final RedisOperationChain criteria, final Serializable keyspace) {
|
||||
|
||||
if(criteria == null) {
|
||||
return this.getAdapter().count(keyspace);
|
||||
}
|
||||
|
||||
return this.getAdapter().execute(new RedisCallback<Long>() {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -203,8 +203,26 @@ public abstract class RedisRepositoryIntegrationTestBase {
|
||||
repo.save(Arrays.asList(eddard, robb, jon));
|
||||
|
||||
Page<Person> firstPage = repo.findAll(new PageRequest(0, 2));
|
||||
assertThat(firstPage.getContent(), hasSize(2));
|
||||
assertThat(repo.findAll(firstPage.nextPageable()).getContent(), hasSize(1));
|
||||
assertThat(firstPage.getContent(), hasSize(2));
|
||||
assertThat(repo.findAll(firstPage.nextPageable()).getContent(), hasSize(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-551
|
||||
*/
|
||||
@Test
|
||||
public void shouldApplyPageableCorrectlyWhenUsingFindByWithoutCriteria() {
|
||||
|
||||
Person eddard = new Person("eddard", "stark");
|
||||
Person robb = new Person("robb", "stark");
|
||||
Person jon = new Person("jon", "snow");
|
||||
|
||||
repo.save(Arrays.asList(eddard, robb, jon));
|
||||
|
||||
Page<Person> firstPage = repo.findBy(new PageRequest(0, 2));
|
||||
assertThat(firstPage.getContent(), hasSize(2));
|
||||
assertThat(firstPage.getTotalElements(), is(equalTo(3L)));
|
||||
assertThat(repo.findBy(firstPage.nextPageable()).getContent(), hasSize(1));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -280,6 +298,8 @@ public abstract class RedisRepositoryIntegrationTestBase {
|
||||
List<Person> findByFirstnameOrLastname(String firstname, String lastname);
|
||||
|
||||
List<Person> findBy();
|
||||
|
||||
Page<Person> findBy(Pageable page);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user