Skip to content

Commit 3753f63

Browse files
committed
JdbcAggregateOperations returns List as well.
1 parent dd4da8a commit 3753f63

File tree

2 files changed

+14
-23
lines changed

2 files changed

+14
-23
lines changed

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateOperations.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.data.jdbc.core;
1717

18+
import java.util.List;
1819
import java.util.Optional;
1920

2021
import org.springframework.dao.IncorrectUpdateSemanticsDataAccessException;
@@ -58,7 +59,7 @@ public interface JdbcAggregateOperations {
5859
* resulting update does not update any rows.
5960
* @since 3.0
6061
*/
61-
<T> Iterable<T> saveAll(Iterable<T> instances);
62+
<T> List<T> saveAll(Iterable<T> instances);
6263

6364
/**
6465
* Dedicated insert function. This skips the test if the aggregate root is new and makes an insert.
@@ -103,7 +104,7 @@ public interface JdbcAggregateOperations {
103104
* @return the saved instances.
104105
* @since 3.1
105106
*/
106-
<T> Iterable<T> updateAll(Iterable<T> instances);
107+
<T> List<T> updateAll(Iterable<T> instances);
107108

108109
/**
109110
* Counts the number of aggregates of a given type.
@@ -162,7 +163,7 @@ public interface JdbcAggregateOperations {
162163
* @param <T> the type of the aggregate roots. Must not be {@code null}.
163164
* @return Guaranteed to be not {@code null}.
164165
*/
165-
<T> Iterable<T> findAllById(Iterable<?> ids, Class<T> domainType);
166+
<T> List<T> findAllById(Iterable<?> ids, Class<T> domainType);
166167

167168
/**
168169
* Load all aggregates of a given type.
@@ -171,7 +172,7 @@ public interface JdbcAggregateOperations {
171172
* @param <T> the type of the aggregate roots. Must not be {@code null}.
172173
* @return Guaranteed to be not {@code null}.
173174
*/
174-
<T> Iterable<T> findAll(Class<T> domainType);
175+
<T> List<T> findAll(Class<T> domainType);
175176

176177
/**
177178
* Load all aggregates of a given type, sorted.
@@ -182,7 +183,7 @@ public interface JdbcAggregateOperations {
182183
* @return Guaranteed to be not {@code null}.
183184
* @since 2.0
184185
*/
185-
<T> Iterable<T> findAll(Class<T> domainType, Sort sort);
186+
<T> List<T> findAll(Class<T> domainType, Sort sort);
186187

187188
/**
188189
* Load a page of (potentially sorted) aggregates of a given type.
@@ -207,15 +208,15 @@ public interface JdbcAggregateOperations {
207208
<T> Optional<T> findOne(Query query, Class<T> domainType);
208209

209210
/**
210-
* Execute a {@code SELECT} query and convert the resulting items to a {@link Iterable} that is sorted.
211+
* Execute a {@code SELECT} query and convert the resulting items to a {@link List} that is sorted.
211212
*
212213
* @param query must not be {@literal null}.
213214
* @param domainType the entity type must not be {@literal null}.
214215
* @return a non-null sorted list with all the matching results.
215216
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException if more than one match found.
216217
* @since 3.0
217218
*/
218-
<T> Iterable<T> findAll(Query query, Class<T> domainType);
219+
<T> List<T> findAll(Query query, Class<T> domainType);
219220

220221
/**
221222
* Returns a {@link Page} of entities matching the given {@link Query}. In case no match could be found, an empty

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/SimpleJdbcRepository.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public <S extends T> S save(S instance) {
7373
@Transactional
7474
@Override
7575
public <S extends T> List<S> saveAll(Iterable<S> entities) {
76-
return asList(entityOperations.saveAll(entities));
76+
return entityOperations.saveAll(entities);
7777
}
7878

7979
@Override
@@ -88,12 +88,12 @@ public boolean existsById(ID id) {
8888

8989
@Override
9090
public List<T> findAll() {
91-
return asList(entityOperations.findAll(entity.getType()));
91+
return entityOperations.findAll(entity.getType());
9292
}
9393

9494
@Override
9595
public List<T> findAllById(Iterable<ID> ids) {
96-
return asList(entityOperations.findAllById(ids, entity.getType()));
96+
return entityOperations.findAllById(ids, entity.getType());
9797
}
9898

9999
@Override
@@ -133,7 +133,7 @@ public void deleteAll() {
133133

134134
@Override
135135
public List<T> findAll(Sort sort) {
136-
return asList(entityOperations.findAll(entity.getType(), sort));
136+
return entityOperations.findAll(entity.getType(), sort);
137137
}
138138

139139
@Override
@@ -163,8 +163,8 @@ public <S extends T> List<S> findAll(Example<S> example, Sort sort) {
163163
Assert.notNull(example, "Example must not be null");
164164
Assert.notNull(sort, "Sort must not be null");
165165

166-
return asList(this.entityOperations.findAll(this.exampleMapper.getMappedExample(example).sort(sort),
167-
example.getProbeType()));
166+
return this.entityOperations.findAll(this.exampleMapper.getMappedExample(example).sort(sort),
167+
example.getProbeType());
168168
}
169169

170170
@Override
@@ -202,14 +202,4 @@ public <S extends T, R> R findBy(Example<S> example, Function<FluentQuery.Fetcha
202202

203203
return queryFunction.apply(fluentQuery);
204204
}
205-
206-
207-
private <S extends T> List<S> asList(Iterable<S> iterable) {
208-
209-
if (iterable instanceof List<S> list) {
210-
return list;
211-
}
212-
return Streamable.of(iterable).stream().toList();
213-
}
214-
215205
}

0 commit comments

Comments
 (0)