Skip to content

Commit

Permalink
JdbcAggregateOperations returns List as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
schauder committed Sep 25, 2024
1 parent dd4da8a commit 3753f63
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
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 @@ -73,7 +73,7 @@ public <S extends T> S save(S instance) {
@Transactional
@Override
public <S extends T> List<S> saveAll(Iterable<S> entities) {
return asList(entityOperations.saveAll(entities));
return entityOperations.saveAll(entities);
}

@Override
Expand All @@ -88,12 +88,12 @@ public boolean existsById(ID id) {

@Override
public List<T> findAll() {
return asList(entityOperations.findAll(entity.getType()));
return entityOperations.findAll(entity.getType());
}

@Override
public List<T> findAllById(Iterable<ID> ids) {
return asList(entityOperations.findAllById(ids, entity.getType()));
return entityOperations.findAllById(ids, entity.getType());
}

@Override
Expand Down Expand Up @@ -133,7 +133,7 @@ public void deleteAll() {

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

@Override
Expand Down Expand Up @@ -163,8 +163,8 @@ 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");

return asList(this.entityOperations.findAll(this.exampleMapper.getMappedExample(example).sort(sort),
example.getProbeType()));
return this.entityOperations.findAll(this.exampleMapper.getMappedExample(example).sort(sort),
example.getProbeType());
}

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

return queryFunction.apply(fluentQuery);
}


private <S extends T> List<S> asList(Iterable<S> iterable) {

if (iterable instanceof List<S> list) {
return list;
}
return Streamable.of(iterable).stream().toList();
}

}

0 comments on commit 3753f63

Please # to comment.