Skip to content

Commit c0d337d

Browse files
schaudermp911de
authored andcommitted
DATAJDBC-629 - Implements CrudRepository.deleteAllById(Iterable<ID>).
Original pull request: #252.
1 parent 636a81a commit c0d337d

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/SimpleJdbcRepository.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ public void deleteAll() {
155155
entityOperations.deleteAll(entity.getType());
156156
}
157157

158+
@Override
159+
public void deleteAllById(Iterable<? extends ID> ids) {
160+
ids.forEach(it -> entityOperations.deleteById(it, entity.getType()));
161+
}
162+
158163
/*
159164
* (non-Javadoc)
160165
* @see org.springframework.data.repository.PagingAndSortingRepository#findAll(org.springframework.data.domain.Sort sort)
@@ -172,4 +177,5 @@ public Iterable<T> findAll(Sort sort) {
172177
public Page<T> findAll(Pageable pageable) {
173178
return entityOperations.findAll(entity.getType(), pageable);
174179
}
180+
175181
}

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,20 @@ public void deleteByList() {
204204
.containsExactlyInAnyOrder(two.getIdProp());
205205
}
206206

207+
@Test // DATAJDBC-629
208+
public void deleteByIdList() {
209+
210+
DummyEntity one = repository.save(createDummyEntity());
211+
DummyEntity two = repository.save(createDummyEntity());
212+
DummyEntity three = repository.save(createDummyEntity());
213+
214+
repository.deleteAllById(asList(one.idProp, three.idProp));
215+
216+
assertThat(repository.findAll()) //
217+
.extracting(DummyEntity::getIdProp) //
218+
.containsExactlyInAnyOrder(two.getIdProp());
219+
}
220+
207221
@Test // DATAJDBC-97
208222
public void deleteAll() {
209223

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/config/EnableJdbcRepositoriesIntegrationTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,5 +228,10 @@ public void deleteAll(Iterable<? extends T> iterable) {
228228
public void deleteAll() {
229229

230230
}
231+
232+
@Override
233+
public void deleteAllById(Iterable<? extends ID> ids) {
234+
235+
}
231236
}
232237
}

0 commit comments

Comments
 (0)