|
17 | 17 |
|
18 | 18 | import static org.assertj.core.api.Assertions.*;
|
19 | 19 |
|
20 |
| -import java.util.Arrays; |
21 |
| -import java.util.Optional; |
22 |
| - |
23 | 20 | import jakarta.persistence.EntityManager;
|
24 | 21 | import jakarta.persistence.PersistenceContext;
|
25 | 22 |
|
| 23 | +import java.util.Arrays; |
| 24 | +import java.util.Iterator; |
| 25 | +import java.util.List; |
| 26 | +import java.util.Optional; |
| 27 | + |
| 28 | +import org.jetbrains.annotations.NotNull; |
26 | 29 | import org.junit.jupiter.api.BeforeEach;
|
27 | 30 | import org.junit.jupiter.api.Test;
|
28 | 31 | import org.junit.jupiter.api.extension.ExtendWith;
|
29 |
| - |
30 | 32 | import org.springframework.data.jpa.domain.sample.PersistableWithIdClass;
|
31 | 33 | import org.springframework.data.jpa.domain.sample.PersistableWithIdClassPK;
|
32 | 34 | import org.springframework.data.jpa.domain.sample.SampleEntity;
|
@@ -128,6 +130,38 @@ void deleteAllByIdInBatch() {
|
128 | 130 | assertThat(repository.findAll()).containsExactly(two);
|
129 | 131 | }
|
130 | 132 |
|
| 133 | + @Test // GH-2242 |
| 134 | + void deleteAllByIdInBatchShouldConvertAnIterableToACollection() { |
| 135 | + |
| 136 | + SampleEntity one = new SampleEntity("one", "eins"); |
| 137 | + SampleEntity two = new SampleEntity("two", "zwei"); |
| 138 | + SampleEntity three = new SampleEntity("three", "drei"); |
| 139 | + repository.saveAll(Arrays.asList(one, two, three)); |
| 140 | + repository.flush(); |
| 141 | + |
| 142 | + // List<SampleEntityPK> ids = Arrays.asList(new SampleEntityPK("one", "eins"), |
| 143 | + // new SampleEntityPK("three", "drei")); |
| 144 | + |
| 145 | + Iterable<SampleEntityPK> ids = new Iterable<SampleEntityPK>() { |
| 146 | + |
| 147 | + /** |
| 148 | + * Wrap a {@link List} inside an {@link Iterable} to verify that {@link SimpleJpaRepository} can properly |
| 149 | + * convert a pure {@link Iterable} to a {@link Collection}. |
| 150 | + **/ |
| 151 | + private List<SampleEntityPK> ids = Arrays.asList(new SampleEntityPK("one", "eins"), |
| 152 | + new SampleEntityPK("three", "drei")); |
| 153 | + |
| 154 | + @NotNull |
| 155 | + @Override |
| 156 | + public Iterator<SampleEntityPK> iterator() { |
| 157 | + return ids.iterator(); |
| 158 | + } |
| 159 | + }; |
| 160 | + |
| 161 | + repository.deleteAllByIdInBatch(ids); |
| 162 | + assertThat(repository.findAll()).containsExactly(two); |
| 163 | + } |
| 164 | + |
131 | 165 | private interface SampleEntityRepository extends JpaRepository<SampleEntity, SampleEntityPK> {
|
132 | 166 |
|
133 | 167 | }
|
|
0 commit comments