|
40 | 40 | import java.util.Optional; |
41 | 41 | import java.util.function.BiConsumer; |
42 | 42 | import java.util.function.Function; |
43 | | -import java.util.stream.Collectors; |
44 | | -import java.util.stream.StreamSupport; |
45 | 43 |
|
46 | 44 | import org.springframework.data.domain.Example; |
47 | 45 | import org.springframework.data.domain.KeysetScrollPosition; |
@@ -246,14 +244,8 @@ public void deleteAllByIdInBatch(Iterable<ID> ids) { |
246 | 244 | /* |
247 | 245 | * Some JPA providers require {@code ids} to be a {@link Collection} so we must convert if it's not already. |
248 | 246 | */ |
249 | | - |
250 | | - if (ids instanceof Collection) { |
251 | | - query.setParameter("ids", ids); |
252 | | - } else { |
253 | | - Collection<ID> idsCollection = StreamSupport.stream(ids.spliterator(), false) |
254 | | - .collect(Collectors.toCollection(ArrayList::new)); |
255 | | - query.setParameter("ids", idsCollection); |
256 | | - } |
| 247 | + Collection<ID> idCollection = toCollection(ids); |
| 248 | + query.setParameter("ids", idCollection); |
257 | 249 |
|
258 | 250 | applyQueryHints(query); |
259 | 251 |
|
@@ -414,7 +406,7 @@ public List<T> findAllById(Iterable<ID> ids) { |
414 | 406 | return results; |
415 | 407 | } |
416 | 408 |
|
417 | | - Collection<ID> idCollection = Streamable.of(ids).toList(); |
| 409 | + Collection<ID> idCollection = toCollection(ids); |
418 | 410 |
|
419 | 411 | ByIdsSpecification<T> specification = new ByIdsSpecification<>(entityInformation); |
420 | 412 | TypedQuery<T> query = getQuery(specification, Sort.unsorted()); |
@@ -918,6 +910,11 @@ private ProjectionFactory getProjectionFactory() { |
918 | 910 | return projectionFactory; |
919 | 911 | } |
920 | 912 |
|
| 913 | + @SuppressWarnings({ "rawtypes", "unchecked" }) |
| 914 | + private static <T> Collection<T> toCollection(Iterable<T> ids) { |
| 915 | + return ids instanceof Collection c ? c : Streamable.of(ids).toList(); |
| 916 | + } |
| 917 | + |
921 | 918 | /** |
922 | 919 | * Executes a count query and transparently sums up all values returned. |
923 | 920 | * |
|
0 commit comments