Allow empty Iterable arguments in JdbcAggregateTemplate again.
This also affects repositories since they delegate to the template. Closes #1401
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
package org.springframework.data.jdbc.core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -170,7 +171,11 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
@Override
|
||||
public <T> Iterable<T> saveAll(Iterable<T> instances) {
|
||||
|
||||
Assert.isTrue(instances.iterator().hasNext(), "Aggregate instances must not be empty");
|
||||
Assert.notNull(instances, "Aggregate instances must not be null");
|
||||
|
||||
if (!instances.iterator().hasNext()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return performSaveAll(instances);
|
||||
}
|
||||
@@ -327,7 +332,9 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
@Override
|
||||
public <T> void deleteAllById(Iterable<?> ids, Class<T> domainType) {
|
||||
|
||||
Assert.isTrue(ids.iterator().hasNext(), "Ids must not be empty");
|
||||
if (!ids.iterator().hasNext()) {
|
||||
return;
|
||||
}
|
||||
|
||||
BatchingAggregateChange<T, DeleteAggregateChange<T>> batchingAggregateChange = BatchingAggregateChange
|
||||
.forDelete(domainType);
|
||||
@@ -356,7 +363,9 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
@Override
|
||||
public <T> void deleteAll(Iterable<? extends T> instances) {
|
||||
|
||||
Assert.isTrue(instances.iterator().hasNext(), "Aggregate instances must not be empty");
|
||||
if (!instances.iterator().hasNext()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<Class, List<Object>> groupedByType = new HashMap<>();
|
||||
|
||||
|
||||
@@ -312,6 +312,21 @@ public class JdbcAggregateTemplateUnitTests {
|
||||
assertThat(all).containsExactly(alfred2, neumann2);
|
||||
}
|
||||
|
||||
@Test // GH-1401
|
||||
public void saveAllWithEmptyListDoesNothing() {
|
||||
assertThat(template.saveAll(emptyList())).isEmpty();
|
||||
}
|
||||
|
||||
@Test // GH-1401
|
||||
public void deleteAllWithEmptyListDoesNothing() {
|
||||
template.deleteAll(emptyList());
|
||||
}
|
||||
|
||||
@Test // GH-1401
|
||||
public void deleteAllByIdWithEmptyListDoesNothing() {
|
||||
template.deleteAllById(emptyList(), SampleEntity.class);
|
||||
}
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
private static class SampleEntity {
|
||||
|
||||
Reference in New Issue
Block a user