Let QueryByExampleRedisExecutor implement ListQueryByExampleExecutor.
Closes #2880
This commit is contained in:
@@ -9,7 +9,7 @@ The following example uses Query by Example against a repository:
|
||||
====
|
||||
[source, java]
|
||||
----
|
||||
interface PersonRepository extends QueryByExampleExecutor<Person> {
|
||||
interface PersonRepository extends ListQueryByExampleExecutor<Person> {
|
||||
}
|
||||
|
||||
class PersonService {
|
||||
|
||||
@@ -81,7 +81,7 @@ class RedisQueryEngine extends QueryEngine<RedisKeyValueAdapter, RedisOperationC
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> Collection<T> execute(RedisOperationChain criteria, Comparator<?> sort, long offset, int rows,
|
||||
public <T> List<T> execute(RedisOperationChain criteria, Comparator<?> sort, long offset, int rows,
|
||||
String keyspace, Class<T> type) {
|
||||
List<T> result = doFind(criteria, offset, rows, keyspace, type);
|
||||
|
||||
@@ -199,7 +199,7 @@ class RedisQueryEngine extends QueryEngine<RedisKeyValueAdapter, RedisOperationC
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<?> 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);
|
||||
}
|
||||
|
||||
@@ -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<T>
|
||||
implements QueryByExampleExecutor<T>, BeanFactoryAware, BeanClassLoaderAware {
|
||||
implements ListQueryByExampleExecutor<T>, BeanFactoryAware, BeanClassLoaderAware {
|
||||
|
||||
private final EntityInformation<T, ?> entityInformation;
|
||||
private final RedisKeyValueTemplate keyValueTemplate;
|
||||
@@ -147,15 +148,17 @@ public class QueryByExampleRedisExecutor<T>
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S extends T> Iterable<S> findAll(Example<S> example) {
|
||||
public <S extends T> List<S> findAll(Example<S> example) {
|
||||
|
||||
RedisOperationChain operationChain = createQuery(example);
|
||||
|
||||
return (Iterable<S>) keyValueTemplate.find(new KeyValueQuery<>(operationChain), entityInformation.getJavaType());
|
||||
Iterable<T> result = keyValueTemplate.find(new KeyValueQuery<>(operationChain), entityInformation.getJavaType());
|
||||
|
||||
return (List<S>) (result instanceof List<?> list ? list : Streamable.of(result).toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S extends T> Iterable<S> findAll(Example<S> example, Sort sort) {
|
||||
public <S extends T> List<S> findAll(Example<S> example, Sort sort) {
|
||||
throw new UnsupportedOperationException("Ordering is not supported");
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Person> executor = new QueryByExampleRedisExecutor<>(getEntityInformation(Person.class),
|
||||
@@ -138,7 +136,7 @@ public class QueryByExampleRedisExecutorIntegrationTests {
|
||||
Person person = new Person();
|
||||
person.setHometown(walt.getHometown());
|
||||
|
||||
Iterable<Person> result = executor.findAll(Example.of(person));
|
||||
List<Person> result = executor.findAll(Example.of(person));
|
||||
assertThat(result).contains(walt, gus, hank);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user