|
16 | 16 | package org.springframework.data.jdbc.core; |
17 | 17 |
|
18 | 18 | import java.util.ArrayList; |
| 19 | +import java.util.Collections; |
19 | 20 | import java.util.HashMap; |
20 | 21 | import java.util.Iterator; |
21 | 22 | import java.util.LinkedHashMap; |
@@ -171,7 +172,10 @@ public <T> T save(T instance) { |
171 | 172 | public <T> Iterable<T> saveAll(Iterable<T> instances) { |
172 | 173 |
|
173 | 174 | Assert.notNull(instances, "Aggregate instances must not be null"); |
174 | | - Assert.isTrue(instances.iterator().hasNext(), "Aggregate instances must not be empty"); |
| 175 | + |
| 176 | + if (!instances.iterator().hasNext()) { |
| 177 | + return Collections.emptyList(); |
| 178 | + } |
175 | 179 |
|
176 | 180 | List<EntityAndChangeCreator<T>> entityAndChangeCreators = new ArrayList<>(); |
177 | 181 | for (T instance : instances) { |
@@ -200,7 +204,10 @@ public <T> T insert(T instance) { |
200 | 204 | public <T> Iterable<T> insertAll(Iterable<T> instances) { |
201 | 205 |
|
202 | 206 | Assert.notNull(instances, "Aggregate instances must not be null"); |
203 | | - Assert.isTrue(instances.iterator().hasNext(), "Aggregate instances must not be empty"); |
| 207 | + |
| 208 | + if (!instances.iterator().hasNext()) { |
| 209 | + return Collections.emptyList(); |
| 210 | + } |
204 | 211 |
|
205 | 212 | List<EntityAndChangeCreator<T>> entityAndChangeCreators = new ArrayList<>(); |
206 | 213 | for (T instance : instances) { |
@@ -232,7 +239,10 @@ public <T> T update(T instance) { |
232 | 239 | public <T> Iterable<T> updateAll(Iterable<T> instances) { |
233 | 240 |
|
234 | 241 | Assert.notNull(instances, "Aggregate instances must not be null"); |
235 | | - Assert.isTrue(instances.iterator().hasNext(), "Aggregate instances must not be empty"); |
| 242 | + |
| 243 | + if (!instances.iterator().hasNext()) { |
| 244 | + return Collections.emptyList(); |
| 245 | + } |
236 | 246 |
|
237 | 247 | List<EntityAndChangeCreator<T>> entityAndChangeCreators = new ArrayList<>(); |
238 | 248 | for (T instance : instances) { |
@@ -366,7 +376,9 @@ public <S> void deleteById(Object id, Class<S> domainType) { |
366 | 376 | @Override |
367 | 377 | public <T> void deleteAllById(Iterable<?> ids, Class<T> domainType) { |
368 | 378 |
|
369 | | - Assert.isTrue(ids.iterator().hasNext(), "Ids must not be empty"); |
| 379 | + if (!ids.iterator().hasNext()) { |
| 380 | + return; |
| 381 | + } |
370 | 382 |
|
371 | 383 | BatchingAggregateChange<T, DeleteAggregateChange<T>> batchingAggregateChange = BatchingAggregateChange |
372 | 384 | .forDelete(domainType); |
@@ -395,7 +407,9 @@ public void deleteAll(Class<?> domainType) { |
395 | 407 | @Override |
396 | 408 | public <T> void deleteAll(Iterable<? extends T> instances) { |
397 | 409 |
|
398 | | - Assert.isTrue(instances.iterator().hasNext(), "Aggregate instances must not be empty"); |
| 410 | + if (!instances.iterator().hasNext()) { |
| 411 | + return; |
| 412 | + } |
399 | 413 |
|
400 | 414 | Map<Class, List<Object>> groupedByType = new HashMap<>(); |
401 | 415 |
|
|
0 commit comments