Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return List instead of Iterable from JdbcAggregateOperations and SimpleJdbcRepository #1897

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0-1623-return-lists-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data Relational Parent</name>
Expand Down
2 changes: 1 addition & 1 deletion spring-data-jdbc-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0-1623-return-lists-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
4 changes: 2 additions & 2 deletions spring-data-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-jdbc</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0-1623-return-lists-SNAPSHOT</version>

<name>Spring Data JDBC</name>
<description>Spring Data module for JDBC repositories.</description>
Expand All @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0-1623-return-lists-SNAPSHOT</version>
</parent>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.springframework.data.jdbc.core;

import java.util.List;
import java.util.Optional;

import org.springframework.dao.IncorrectUpdateSemanticsDataAccessException;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -207,15 +208,15 @@ 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}.
* @return a non-null sorted list with all the matching results.
* @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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
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;
Expand Down Expand Up @@ -171,7 +172,7 @@ public <T> T save(T instance) {
}

@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");

Expand Down Expand Up @@ -204,7 +205,7 @@ public <T> T insert(T instance) {
}

@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");

Expand Down Expand Up @@ -239,7 +240,7 @@ public <T> T update(T instance) {
}

@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");

Expand Down Expand Up @@ -298,7 +299,7 @@ public <T> T findById(Object id, Class<T> domainType) {
}

@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");

Expand All @@ -323,8 +324,13 @@ public <T> Optional<T> findOne(Query query, Class<T> domainType) {
}

@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
Expand All @@ -337,7 +343,7 @@ public <T> Page<T> findAll(Query query, Class<T> domainType, Pageable pageable)
}

@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");

Expand All @@ -346,7 +352,7 @@ public <T> Iterable<T> findAll(Class<T> domainType) {
}

@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");
Expand Down Expand Up @@ -607,7 +613,7 @@ private MutableAggregateChange<?> createDeletingChange(Class<?> domainType) {
return aggregateChange;
}

private <T> Iterable<T> triggerAfterConvert(Iterable<T> all) {
private <T> List<T> triggerAfterConvert(Iterable<T> all) {

List<T> result = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.springframework.data.jdbc.repository.support;

import java.util.List;
import java.util.Optional;
import java.util.function.Function;

Expand All @@ -30,6 +31,7 @@
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;

Expand Down Expand Up @@ -70,7 +72,7 @@ public <S extends T> S save(S instance) {

@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);
}

Expand All @@ -85,12 +87,12 @@ public boolean existsById(ID 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());
}

Expand Down Expand Up @@ -130,7 +132,7 @@ public void deleteAll() {
}

@Override
public Iterable<T> findAll(Sort sort) {
public List<T> findAll(Sort sort) {
return entityOperations.findAll(entity.getType(), sort);
}

Expand All @@ -148,15 +150,15 @@ public <S extends T> Optional<S> findOne(Example<S> example) {
}

@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");

return findAll(example, Sort.unsorted());
}

@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");
Expand Down
4 changes: 2 additions & 2 deletions spring-data-r2dbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-r2dbc</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0-1623-return-lists-SNAPSHOT</version>

<name>Spring Data R2DBC</name>
<description>Spring Data module for R2DBC</description>
Expand All @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0-1623-return-lists-SNAPSHOT</version>
</parent>

<properties>
Expand Down
4 changes: 2 additions & 2 deletions spring-data-relational/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-relational</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0-1623-return-lists-SNAPSHOT</version>

<name>Spring Data Relational</name>
<description>Spring Data Relational support</description>

<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0-1623-return-lists-SNAPSHOT</version>
</parent>

<properties>
Expand Down
Loading