Adapt repository to List-based interface variants.

Closes #418
This commit is contained in:
Mark Paluch
2022-02-11 10:45:11 +01:00
parent 0b22522c28
commit 524417fe5f
3 changed files with 16 additions and 13 deletions

View File

@@ -15,13 +15,14 @@
*/
package org.springframework.data.keyvalue.repository;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.ListCrudRepository;
import org.springframework.data.repository.ListPagingAndSortingRepository;
/**
* @author Christoph Strobl
* @param <T>
* @param <ID>
*/
public interface KeyValueRepository<T, ID> extends PagingAndSortingRepository<T, ID> {
public interface KeyValueRepository<T, ID> extends ListCrudRepository<T, ID>, ListPagingAndSortingRepository<T, ID> {
}

View File

@@ -31,6 +31,7 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.keyvalue.core.IterableConverter;
import org.springframework.data.keyvalue.core.KeyValueOperations;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.PersistentProperty;
@@ -39,6 +40,7 @@ import org.springframework.data.mapping.model.EntityInstantiators;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
import org.springframework.data.querydsl.EntityPathResolver;
import org.springframework.data.querydsl.ListQuerydslPredicateExecutor;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.querydsl.SimpleEntityPathResolver;
import org.springframework.data.repository.core.EntityInformation;
@@ -61,13 +63,13 @@ import com.querydsl.core.types.dsl.PathBuilder;
* @author Mark Paluch
* @since 2.6
*/
public class QuerydslKeyValuePredicateExecutor<T> implements QuerydslPredicateExecutor<T> {
public class QuerydslKeyValuePredicateExecutor<T> implements ListQuerydslPredicateExecutor<T> {
private static final EntityPathResolver DEFAULT_ENTITY_PATH_RESOLVER = SimpleEntityPathResolver.INSTANCE;
private final MappingContext<? extends PersistentEntity<?, ?>, ? extends PersistentProperty<?>> context;
private final PathBuilder<T> builder;
private final Supplier<Iterable<T>> findAll;
private final Supplier<List<T>> findAll;
private final EntityInformation<T, ?> entityInformation;
private final ProjectionFactory projectionFactory;
private final EntityInstantiators entityInstantiators = new EntityInstantiators();
@@ -105,7 +107,7 @@ public class QuerydslKeyValuePredicateExecutor<T> implements QuerydslPredicateEx
EntityPath<T> path = resolver.createPath(entityInformation.getJavaType());
this.builder = new PathBuilder<>(path.getType(), path.getMetadata());
this.entityInformation = entityInformation;
findAll = () -> operations.findAll(entityInformation.getJavaType());
findAll = () -> IterableConverter.toList(operations.findAll(entityInformation.getJavaType()));
}
@Override
@@ -121,7 +123,7 @@ public class QuerydslKeyValuePredicateExecutor<T> implements QuerydslPredicateEx
}
@Override
public Iterable<T> findAll(Predicate predicate) {
public List<T> findAll(Predicate predicate) {
Assert.notNull(predicate, "Predicate must not be null!");
@@ -129,7 +131,7 @@ public class QuerydslKeyValuePredicateExecutor<T> implements QuerydslPredicateEx
}
@Override
public Iterable<T> findAll(Predicate predicate, OrderSpecifier<?>... orders) {
public List<T> findAll(Predicate predicate, OrderSpecifier<?>... orders) {
Assert.notNull(predicate, "Predicate must not be null!");
Assert.notNull(orders, "OrderSpecifiers must not be null!");
@@ -141,7 +143,7 @@ public class QuerydslKeyValuePredicateExecutor<T> implements QuerydslPredicateEx
}
@Override
public Iterable<T> findAll(Predicate predicate, Sort sort) {
public List<T> findAll(Predicate predicate, Sort sort) {
Assert.notNull(predicate, "Predicate must not be null!");
Assert.notNull(sort, "Sort must not be null!");
@@ -171,7 +173,7 @@ public class QuerydslKeyValuePredicateExecutor<T> implements QuerydslPredicateEx
}
@Override
public Iterable<T> findAll(OrderSpecifier<?>... orders) {
public List<T> findAll(OrderSpecifier<?>... orders) {
Assert.notNull(orders, "OrderSpecifiers must not be null!");

View File

@@ -77,7 +77,7 @@ public class SimpleKeyValueRepository<T, ID> implements KeyValueRepository<T, ID
}
@Override
public <S extends T> Iterable<S> saveAll(Iterable<S> entities) {
public <S extends T> List<S> saveAll(Iterable<S> entities) {
Assert.notNull(entities, "The given Iterable of entities must not be null!");
@@ -109,7 +109,7 @@ public class SimpleKeyValueRepository<T, ID> implements KeyValueRepository<T, ID
}
@Override
public Iterable<T> findAllById(Iterable<ID> ids) {
public List<T> findAllById(Iterable<ID> ids) {
Assert.notNull(ids, "The given Iterable of id's must not be null!");
@@ -167,11 +167,11 @@ public class SimpleKeyValueRepository<T, ID> implements KeyValueRepository<T, ID
// -------------------------------------------------------------------------
@Override
public Iterable<T> findAll(Sort sort) {
public List<T> findAll(Sort sort) {
Assert.notNull(sort, "Sort must not be null!");
return operations.findAll(sort, entityInformation.getJavaType());
return IterableConverter.toList(operations.findAll(sort, entityInformation.getJavaType()));
}
@Override