Return List instead of Iterable in JDBC Repositories and JdbcAggregateOperations.
Closes #1623 Original pull request: #1897
This commit is contained in:
committed by
Mark Paluch
parent
4d5a382a73
commit
c4f62e9f56
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.jdbc.core;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.dao.IncorrectUpdateSemanticsDataAccessException;
|
||||
@@ -58,7 +59,7 @@ public interface JdbcAggregateOperations {
|
||||
* resulting update does not update any rows.
|
||||
* @since 3.0
|
||||
*/
|
||||
<T> Iterable<T> saveAll(Iterable<T> instances);
|
||||
<T> List<T> saveAll(Iterable<T> instances);
|
||||
|
||||
/**
|
||||
* Dedicated insert function. This skips the test if the aggregate root is new and makes an insert.
|
||||
@@ -103,7 +104,7 @@ public interface JdbcAggregateOperations {
|
||||
* @return the saved instances.
|
||||
* @since 3.1
|
||||
*/
|
||||
<T> Iterable<T> updateAll(Iterable<T> instances);
|
||||
<T> List<T> updateAll(Iterable<T> instances);
|
||||
|
||||
/**
|
||||
* Counts the number of aggregates of a given type.
|
||||
@@ -162,7 +163,7 @@ public interface JdbcAggregateOperations {
|
||||
* @param <T> the type of the aggregate roots. Must not be {@code null}.
|
||||
* @return Guaranteed to be not {@code null}.
|
||||
*/
|
||||
<T> Iterable<T> findAllById(Iterable<?> ids, Class<T> domainType);
|
||||
<T> List<T> findAllById(Iterable<?> ids, Class<T> domainType);
|
||||
|
||||
/**
|
||||
* Load all aggregates of a given type.
|
||||
@@ -171,7 +172,7 @@ public interface JdbcAggregateOperations {
|
||||
* @param <T> the type of the aggregate roots. Must not be {@code null}.
|
||||
* @return Guaranteed to be not {@code null}.
|
||||
*/
|
||||
<T> Iterable<T> findAll(Class<T> domainType);
|
||||
<T> List<T> findAll(Class<T> domainType);
|
||||
|
||||
/**
|
||||
* Load all aggregates of a given type, sorted.
|
||||
@@ -182,7 +183,7 @@ public interface JdbcAggregateOperations {
|
||||
* @return Guaranteed to be not {@code null}.
|
||||
* @since 2.0
|
||||
*/
|
||||
<T> Iterable<T> findAll(Class<T> domainType, Sort sort);
|
||||
<T> List<T> findAll(Class<T> domainType, Sort sort);
|
||||
|
||||
/**
|
||||
* Load a page of (potentially sorted) aggregates of a given type.
|
||||
@@ -207,7 +208,7 @@ public interface JdbcAggregateOperations {
|
||||
<T> Optional<T> findOne(Query query, Class<T> domainType);
|
||||
|
||||
/**
|
||||
* Execute a {@code SELECT} query and convert the resulting items to a {@link Iterable} that is sorted.
|
||||
* Execute a {@code SELECT} query and convert the resulting items to a {@link List} that is sorted.
|
||||
*
|
||||
* @param query must not be {@literal null}.
|
||||
* @param domainType the entity type must not be {@literal null}.
|
||||
@@ -215,7 +216,7 @@ public interface JdbcAggregateOperations {
|
||||
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException if more than one match found.
|
||||
* @since 3.0
|
||||
*/
|
||||
<T> Iterable<T> findAll(Query query, Class<T> domainType);
|
||||
<T> List<T> findAll(Query query, Class<T> domainType);
|
||||
|
||||
/**
|
||||
* Returns a {@link Page} of entities matching the given {@link Query}. In case no match could be found, an empty
|
||||
|
||||
@@ -52,6 +52,7 @@ import org.springframework.data.relational.core.mapping.RelationalPersistentProp
|
||||
import org.springframework.data.relational.core.mapping.event.*;
|
||||
import org.springframework.data.relational.core.query.Query;
|
||||
import org.springframework.data.support.PageableExecutionUtils;
|
||||
import org.springframework.data.util.Streamable;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
@@ -171,7 +172,7 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Iterable<T> saveAll(Iterable<T> instances) {
|
||||
public <T> List<T> saveAll(Iterable<T> instances) {
|
||||
|
||||
Assert.notNull(instances, "Aggregate instances must not be null");
|
||||
|
||||
@@ -204,7 +205,7 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Iterable<T> insertAll(Iterable<T> instances) {
|
||||
public <T> List<T> insertAll(Iterable<T> instances) {
|
||||
|
||||
Assert.notNull(instances, "Aggregate instances must not be null");
|
||||
|
||||
@@ -239,7 +240,7 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Iterable<T> updateAll(Iterable<T> instances) {
|
||||
public <T> List<T> updateAll(Iterable<T> instances) {
|
||||
|
||||
Assert.notNull(instances, "Aggregate instances must not be null");
|
||||
|
||||
@@ -298,7 +299,7 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Iterable<T> findAll(Class<T> domainType, Sort sort) {
|
||||
public <T> List<T> findAll(Class<T> domainType, Sort sort) {
|
||||
|
||||
Assert.notNull(domainType, "Domain type must not be null");
|
||||
|
||||
@@ -323,8 +324,13 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Iterable<T> findAll(Query query, Class<T> domainType) {
|
||||
return accessStrategy.findAll(query, domainType);
|
||||
public <T> List<T> findAll(Query query, Class<T> domainType) {
|
||||
|
||||
Iterable<T> all = accessStrategy.findAll(query, domainType);
|
||||
if (all instanceof List<T> list) {
|
||||
return list;
|
||||
}
|
||||
return Streamable.of(all).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -337,7 +343,7 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Iterable<T> findAll(Class<T> domainType) {
|
||||
public <T> List<T> findAll(Class<T> domainType) {
|
||||
|
||||
Assert.notNull(domainType, "Domain type must not be null");
|
||||
|
||||
@@ -346,7 +352,7 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Iterable<T> findAllById(Iterable<?> ids, Class<T> domainType) {
|
||||
public <T> List<T> findAllById(Iterable<?> ids, Class<T> domainType) {
|
||||
|
||||
Assert.notNull(ids, "Ids must not be null");
|
||||
Assert.notNull(domainType, "Domain type must not be null");
|
||||
@@ -607,7 +613,7 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
return aggregateChange;
|
||||
}
|
||||
|
||||
private <T> Iterable<T> triggerAfterConvert(Iterable<T> all) {
|
||||
private <T> List<T> triggerAfterConvert(Iterable<T> all) {
|
||||
|
||||
List<T> result = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.jdbc.repository.support;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -30,6 +31,7 @@ import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
import org.springframework.data.repository.query.FluentQuery;
|
||||
import org.springframework.data.repository.query.QueryByExampleExecutor;
|
||||
import org.springframework.data.util.Streamable;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -70,7 +72,7 @@ public class SimpleJdbcRepository<T, ID>
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public <S extends T> Iterable<S> saveAll(Iterable<S> entities) {
|
||||
public <S extends T> List<S> saveAll(Iterable<S> entities) {
|
||||
return entityOperations.saveAll(entities);
|
||||
}
|
||||
|
||||
@@ -85,12 +87,12 @@ public class SimpleJdbcRepository<T, ID>
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<T> findAll() {
|
||||
public List<T> findAll() {
|
||||
return entityOperations.findAll(entity.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<T> findAllById(Iterable<ID> ids) {
|
||||
public List<T> findAllById(Iterable<ID> ids) {
|
||||
return entityOperations.findAllById(ids, entity.getType());
|
||||
}
|
||||
|
||||
@@ -130,7 +132,7 @@ public class SimpleJdbcRepository<T, ID>
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<T> findAll(Sort sort) {
|
||||
public List<T> findAll(Sort sort) {
|
||||
return entityOperations.findAll(entity.getType(), sort);
|
||||
}
|
||||
|
||||
@@ -148,7 +150,7 @@ public class SimpleJdbcRepository<T, ID>
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S extends T> Iterable<S> findAll(Example<S> example) {
|
||||
public <S extends T> List<S> findAll(Example<S> example) {
|
||||
|
||||
Assert.notNull(example, "Example must not be null");
|
||||
|
||||
@@ -156,7 +158,7 @@ public class SimpleJdbcRepository<T, ID>
|
||||
}
|
||||
|
||||
@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) {
|
||||
|
||||
Assert.notNull(example, "Example must not be null");
|
||||
Assert.notNull(sort, "Sort must not be null");
|
||||
|
||||
Reference in New Issue
Block a user