diff --git a/src/main/antora/modules/ROOT/pages/redis/redis-repositories/query-by-example.adoc b/src/main/antora/modules/ROOT/pages/redis/redis-repositories/query-by-example.adoc index 4b90baeb0..e12b6eb6d 100644 --- a/src/main/antora/modules/ROOT/pages/redis/redis-repositories/query-by-example.adoc +++ b/src/main/antora/modules/ROOT/pages/redis/redis-repositories/query-by-example.adoc @@ -9,7 +9,7 @@ The following example uses Query by Example against a repository: ==== [source, java] ---- -interface PersonRepository extends QueryByExampleExecutor { +interface PersonRepository extends ListQueryByExampleExecutor { } class PersonService { 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 ae1691a47..07b946d2b 100644 --- a/src/main/java/org/springframework/data/redis/core/RedisQueryEngine.java +++ b/src/main/java/org/springframework/data/redis/core/RedisQueryEngine.java @@ -81,7 +81,7 @@ class RedisQueryEngine extends QueryEngine Collection execute(RedisOperationChain criteria, Comparator sort, long offset, int rows, + public List execute(RedisOperationChain criteria, Comparator sort, long offset, int rows, String keyspace, Class type) { List result = doFind(criteria, offset, rows, keyspace, type); @@ -199,7 +199,7 @@ class RedisQueryEngine extends QueryEngine execute(RedisOperationChain criteria, Comparator sort, long offset, int rows, + public List execute(RedisOperationChain criteria, Comparator sort, long offset, int rows, String keyspace) { return execute(criteria, sort, offset, rows, keyspace, Object.class); } diff --git a/src/main/java/org/springframework/data/redis/repository/support/QueryByExampleRedisExecutor.java b/src/main/java/org/springframework/data/redis/repository/support/QueryByExampleRedisExecutor.java index 0a58c9f7d..6a3a9584d 100644 --- a/src/main/java/org/springframework/data/redis/repository/support/QueryByExampleRedisExecutor.java +++ b/src/main/java/org/springframework/data/redis/repository/support/QueryByExampleRedisExecutor.java @@ -44,6 +44,7 @@ import org.springframework.data.redis.repository.query.ExampleQueryMapper; import org.springframework.data.redis.repository.query.RedisOperationChain; import org.springframework.data.repository.core.EntityInformation; import org.springframework.data.repository.query.FluentQuery; +import org.springframework.data.repository.query.ListQueryByExampleExecutor; import org.springframework.data.repository.query.QueryByExampleExecutor; import org.springframework.data.support.PageableExecutionUtils; import org.springframework.data.util.Streamable; @@ -62,7 +63,7 @@ import org.springframework.util.Assert; */ @SuppressWarnings("unchecked") public class QueryByExampleRedisExecutor - implements QueryByExampleExecutor, BeanFactoryAware, BeanClassLoaderAware { + implements ListQueryByExampleExecutor, BeanFactoryAware, BeanClassLoaderAware { private final EntityInformation entityInformation; private final RedisKeyValueTemplate keyValueTemplate; @@ -147,15 +148,17 @@ public class QueryByExampleRedisExecutor } @Override - public Iterable findAll(Example example) { + public List findAll(Example example) { RedisOperationChain operationChain = createQuery(example); - return (Iterable) keyValueTemplate.find(new KeyValueQuery<>(operationChain), entityInformation.getJavaType()); + Iterable result = keyValueTemplate.find(new KeyValueQuery<>(operationChain), entityInformation.getJavaType()); + + return (List) (result instanceof List list ? list : Streamable.of(result).toList()); } @Override - public Iterable findAll(Example example, Sort sort) { + public List findAll(Example example, Sort sort) { throw new UnsupportedOperationException("Ordering is not supported"); } diff --git a/src/test/java/org/springframework/data/redis/repository/support/QueryByExampleRedisExecutorIntegrationTests.java b/src/test/java/org/springframework/data/redis/repository/support/QueryByExampleRedisExecutorIntegrationTests.java index c9b0d2055..ebcec9b87 100644 --- a/src/test/java/org/springframework/data/redis/repository/support/QueryByExampleRedisExecutorIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/repository/support/QueryByExampleRedisExecutorIntegrationTests.java @@ -15,9 +15,7 @@ */ package org.springframework.data.redis.repository.support; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assertions.*; import java.util.Arrays; import java.util.List; @@ -57,7 +55,7 @@ import org.springframework.data.repository.query.FluentQuery; * @author Christoph Strobl * @author John Blum */ -public class QueryByExampleRedisExecutorIntegrationTests { +class QueryByExampleRedisExecutorIntegrationTests { private static JedisConnectionFactory connectionFactory; private RedisMappingContext mappingContext = new RedisMappingContext(); @@ -129,7 +127,7 @@ public class QueryByExampleRedisExecutorIntegrationTests { assertThat(result).isEmpty(); } - @Test // DATAREDIS-605 + @Test // DATAREDIS-605, GH-2880 void shouldFindAllByExample() { QueryByExampleRedisExecutor executor = new QueryByExampleRedisExecutor<>(getEntityInformation(Person.class), @@ -138,7 +136,7 @@ public class QueryByExampleRedisExecutorIntegrationTests { Person person = new Person(); person.setHometown(walt.getHometown()); - Iterable result = executor.findAll(Example.of(person)); + List result = executor.findAll(Example.of(person)); assertThat(result).contains(walt, gus, hank); }