From bb9971cfb7fb688da4bd944d779e42d02c39cf9b Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Mon, 12 Sep 2016 17:02:25 +0200 Subject: [PATCH 1/2] DATAREDIS-551 - NPE when counting keys while invoking findBy(Pageable). Prepare issue branch. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2486f880c8..7ff262aaaa 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.data spring-data-redis - 1.8.0.BUILD-SNAPSHOT + 1.8.0.DATAREDIS-551-SNAPSHOT Spring Data Redis From ee25e7f2a50fe0da414332c46021c72333133bb2 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Tue, 6 Sep 2016 17:09:17 +0200 Subject: [PATCH 2/2] 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)`. --- .../data/redis/core/RedisQueryEngine.java | 5 +++++ .../RedisRepositoryIntegrationTestBase.java | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/main/java/org/springframework/data/redis/core/RedisQueryEngine.java b/src/main/java/org/springframework/data/redis/core/RedisQueryEngine.java index 60f4e7b795..a4e9c6c868 100644 --- a/src/main/java/org/springframework/data/redis/core/RedisQueryEngine.java +++ b/src/main/java/org/springframework/data/redis/core/RedisQueryEngine.java @@ -40,6 +40,7 @@ * Redis specific {@link QueryEngine} implementation. * * @author Christoph Strobl + * @author Mark Paluch * @since 1.7 */ class RedisQueryEngine extends QueryEngine> { @@ -156,6 +157,10 @@ public Collection execute(final RedisOperationChain criteria, Comparator s @Override public long count(final RedisOperationChain criteria, final Serializable keyspace) { + if(criteria == null) { + return this.getAdapter().count(keyspace); + } + return this.getAdapter().execute(new RedisCallback() { @Override diff --git a/src/test/java/org/springframework/data/redis/repository/RedisRepositoryIntegrationTestBase.java b/src/test/java/org/springframework/data/redis/repository/RedisRepositoryIntegrationTestBase.java index c8458e95fa..fe958180b7 100644 --- a/src/test/java/org/springframework/data/redis/repository/RedisRepositoryIntegrationTestBase.java +++ b/src/test/java/org/springframework/data/redis/repository/RedisRepositoryIntegrationTestBase.java @@ -222,6 +222,24 @@ public void shouldApplyPageableCorrectlyWhenUsingFindAll() { 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 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)); + } + /** * @see DATAREDIS-547 */ @@ -317,6 +335,8 @@ public static interface PersonRepository extends PagingAndSortingRepository findTop2By(); List findTop2ByLastname(String lastname); + + Page findBy(Pageable page); } /**