Skip to content

Commit 524417f

Browse files
committed
Adapt repository to List-based interface variants.
Closes #418
1 parent 0b22522 commit 524417f

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

src/main/java/org/springframework/data/keyvalue/repository/KeyValueRepository.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
*/
1616
package org.springframework.data.keyvalue.repository;
1717

18-
import org.springframework.data.repository.PagingAndSortingRepository;
18+
import org.springframework.data.repository.ListCrudRepository;
19+
import org.springframework.data.repository.ListPagingAndSortingRepository;
1920

2021
/**
2122
* @author Christoph Strobl
2223
* @param <T>
2324
* @param <ID>
2425
*/
25-
public interface KeyValueRepository<T, ID> extends PagingAndSortingRepository<T, ID> {
26+
public interface KeyValueRepository<T, ID> extends ListCrudRepository<T, ID>, ListPagingAndSortingRepository<T, ID> {
2627

2728
}

src/main/java/org/springframework/data/keyvalue/repository/support/QuerydslKeyValuePredicateExecutor.java

+9-7
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.springframework.data.domain.PageImpl;
3232
import org.springframework.data.domain.Pageable;
3333
import org.springframework.data.domain.Sort;
34+
import org.springframework.data.keyvalue.core.IterableConverter;
3435
import org.springframework.data.keyvalue.core.KeyValueOperations;
3536
import org.springframework.data.mapping.PersistentEntity;
3637
import org.springframework.data.mapping.PersistentProperty;
@@ -39,6 +40,7 @@
3940
import org.springframework.data.projection.ProjectionFactory;
4041
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
4142
import org.springframework.data.querydsl.EntityPathResolver;
43+
import org.springframework.data.querydsl.ListQuerydslPredicateExecutor;
4244
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
4345
import org.springframework.data.querydsl.SimpleEntityPathResolver;
4446
import org.springframework.data.repository.core.EntityInformation;
@@ -61,13 +63,13 @@
6163
* @author Mark Paluch
6264
* @since 2.6
6365
*/
64-
public class QuerydslKeyValuePredicateExecutor<T> implements QuerydslPredicateExecutor<T> {
66+
public class QuerydslKeyValuePredicateExecutor<T> implements ListQuerydslPredicateExecutor<T> {
6567

6668
private static final EntityPathResolver DEFAULT_ENTITY_PATH_RESOLVER = SimpleEntityPathResolver.INSTANCE;
6769

6870
private final MappingContext<? extends PersistentEntity<?, ?>, ? extends PersistentProperty<?>> context;
6971
private final PathBuilder<T> builder;
70-
private final Supplier<Iterable<T>> findAll;
72+
private final Supplier<List<T>> findAll;
7173
private final EntityInformation<T, ?> entityInformation;
7274
private final ProjectionFactory projectionFactory;
7375
private final EntityInstantiators entityInstantiators = new EntityInstantiators();
@@ -105,7 +107,7 @@ public QuerydslKeyValuePredicateExecutor(EntityInformation<T, ?> entityInformati
105107
EntityPath<T> path = resolver.createPath(entityInformation.getJavaType());
106108
this.builder = new PathBuilder<>(path.getType(), path.getMetadata());
107109
this.entityInformation = entityInformation;
108-
findAll = () -> operations.findAll(entityInformation.getJavaType());
110+
findAll = () -> IterableConverter.toList(operations.findAll(entityInformation.getJavaType()));
109111
}
110112

111113
@Override
@@ -121,15 +123,15 @@ public Optional<T> findOne(Predicate predicate) {
121123
}
122124

123125
@Override
124-
public Iterable<T> findAll(Predicate predicate) {
126+
public List<T> findAll(Predicate predicate) {
125127

126128
Assert.notNull(predicate, "Predicate must not be null!");
127129

128130
return prepareQuery(predicate).fetchResults().getResults();
129131
}
130132

131133
@Override
132-
public Iterable<T> findAll(Predicate predicate, OrderSpecifier<?>... orders) {
134+
public List<T> findAll(Predicate predicate, OrderSpecifier<?>... orders) {
133135

134136
Assert.notNull(predicate, "Predicate must not be null!");
135137
Assert.notNull(orders, "OrderSpecifiers must not be null!");
@@ -141,7 +143,7 @@ public Iterable<T> findAll(Predicate predicate, OrderSpecifier<?>... orders) {
141143
}
142144

143145
@Override
144-
public Iterable<T> findAll(Predicate predicate, Sort sort) {
146+
public List<T> findAll(Predicate predicate, Sort sort) {
145147

146148
Assert.notNull(predicate, "Predicate must not be null!");
147149
Assert.notNull(sort, "Sort must not be null!");
@@ -171,7 +173,7 @@ public Page<T> findAll(Predicate predicate, Pageable pageable) {
171173
}
172174

173175
@Override
174-
public Iterable<T> findAll(OrderSpecifier<?>... orders) {
176+
public List<T> findAll(OrderSpecifier<?>... orders) {
175177

176178
Assert.notNull(orders, "OrderSpecifiers must not be null!");
177179

src/main/java/org/springframework/data/keyvalue/repository/support/SimpleKeyValueRepository.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public <S extends T> S save(S entity) {
7777
}
7878

7979
@Override
80-
public <S extends T> Iterable<S> saveAll(Iterable<S> entities) {
80+
public <S extends T> List<S> saveAll(Iterable<S> entities) {
8181

8282
Assert.notNull(entities, "The given Iterable of entities must not be null!");
8383

@@ -109,7 +109,7 @@ public List<T> findAll() {
109109
}
110110

111111
@Override
112-
public Iterable<T> findAllById(Iterable<ID> ids) {
112+
public List<T> findAllById(Iterable<ID> ids) {
113113

114114
Assert.notNull(ids, "The given Iterable of id's must not be null!");
115115

@@ -167,11 +167,11 @@ public void deleteAll() {
167167
// -------------------------------------------------------------------------
168168

169169
@Override
170-
public Iterable<T> findAll(Sort sort) {
170+
public List<T> findAll(Sort sort) {
171171

172172
Assert.notNull(sort, "Sort must not be null!");
173173

174-
return operations.findAll(sort, entityInformation.getJavaType());
174+
return IterableConverter.toList(operations.findAll(sort, entityInformation.getJavaType()));
175175
}
176176

177177
@Override

0 commit comments

Comments
 (0)