|
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;
|
|
43 | 45 | * @author Oliver Gierke
|
44 | 46 | * @author Thomas Darimont
|
45 | 47 | * @author Jens Schauder
|
| 48 | + * @author Greg Turnquist |
46 | 49 | */
|
47 | 50 | @ExtendWith(SpringExtension.class)
|
48 | 51 | @ContextConfiguration({ "classpath:infrastructure.xml" })
|
@@ -128,6 +131,35 @@ void deleteAllByIdInBatch() {
|
128 | 131 | assertThat(repository.findAll()).containsExactly(two);
|
129 | 132 | }
|
130 | 133 |
|
| 134 | + @Test // GH-2242 |
| 135 | + void deleteAllByIdInBatchShouldConvertAnIterableToACollection() { |
| 136 | + |
| 137 | + SampleEntity one = new SampleEntity("one", "eins"); |
| 138 | + SampleEntity two = new SampleEntity("two", "zwei"); |
| 139 | + SampleEntity three = new SampleEntity("three", "drei"); |
| 140 | + repository.saveAll(Arrays.asList(one, two, three)); |
| 141 | + repository.flush(); |
| 142 | + |
| 143 | + /** |
| 144 | + * Wrap a {@link List} inside an {@link Iterable} to verify that {@link SimpleJpaRepository} can properly convert a |
| 145 | + * pure {@link Iterable} to a {@link Collection}. |
| 146 | + **/ |
| 147 | + Iterable<SampleEntityPK> ids = new Iterable<SampleEntityPK>() { |
| 148 | + |
| 149 | + private List<SampleEntityPK> ids = Arrays.asList(new SampleEntityPK("one", "eins"), |
| 150 | + new SampleEntityPK("three", "drei")); |
| 151 | + |
| 152 | + @NotNull |
| 153 | + @Override |
| 154 | + public Iterator<SampleEntityPK> iterator() { |
| 155 | + return ids.iterator(); |
| 156 | + } |
| 157 | + }; |
| 158 | + |
| 159 | + repository.deleteAllByIdInBatch(ids); |
| 160 | + assertThat(repository.findAll()).containsExactly(two); |
| 161 | + } |
| 162 | + |
131 | 163 | private interface SampleEntityRepository extends JpaRepository<SampleEntity, SampleEntityPK> {
|
132 | 164 |
|
133 | 165 | }
|
|
0 commit comments