Skip to content

Commit 843c402

Browse files
schaudermp911de
authored andcommitted
#498 - Implements ReactiveCrudRepository.deleteAllById.
See also: DATACMNS-800. Original pull request: #501.
1 parent 1d5e5cc commit 843c402

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/main/java/org/springframework/data/r2dbc/repository/support/SimpleR2dbcRepository.java

+15
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*/
1616
package org.springframework.data.r2dbc.repository.support;
1717

18+
import org.springframework.data.util.StreamUtils;
19+
import org.springframework.data.util.Streamable;
20+
import org.springframework.util.CollectionUtils;
1821
import reactor.core.publisher.Flux;
1922
import reactor.core.publisher.Mono;
2023

@@ -35,6 +38,8 @@
3538
import org.springframework.transaction.annotation.Transactional;
3639
import org.springframework.util.Assert;
3740

41+
import java.util.List;
42+
3843
/**
3944
* Simple {@link ReactiveSortingRepository} implementation using R2DBC through {@link DatabaseClient}.
4045
*
@@ -304,6 +309,16 @@ public Mono<Void> deleteAll(Iterable<? extends T> iterable) {
304309
return deleteAll(Flux.fromIterable(iterable));
305310
}
306311

312+
@Override
313+
public Mono<Void> deleteAllById(Iterable<? extends ID> ids) {
314+
315+
Assert.notNull(ids, "The iterable of Id's must not be null!");
316+
317+
List<? extends ID> idsList = Streamable.of(ids).toList();
318+
String idProperty = getIdProperty().getName();
319+
return this.entityOperations.delete(Query.query(Criteria.where(idProperty).in(idsList)), this.entity.getJavaType()).then();
320+
}
321+
307322
/* (non-Javadoc)
308323
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#deleteAll(org.reactivestreams.Publisher)
309324
*/

src/test/java/org/springframework/data/r2dbc/repository/support/AbstractSimpleR2dbcRepositoryIntegrationTests.java

+16
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.springframework.data.r2dbc.repository.support;
1717

1818
import static org.assertj.core.api.Assertions.*;
19+
import static org.testcontainers.shaded.com.google.common.primitives.Ints.*;
1920

2021
import lombok.AllArgsConstructor;
2122
import lombok.Data;
@@ -57,6 +58,7 @@
5758
* @author Mark Paluch
5859
* @author Bogdan Ilchyshyn
5960
* @author Stephen Cohen
61+
* @author Jens Schauder
6062
*/
6163
public abstract class AbstractSimpleR2dbcRepositoryIntegrationTests extends R2dbcIntegrationTestSupport {
6264

@@ -465,6 +467,20 @@ void shouldDeleteAllUsingPublisher() {
465467
assertThat(count).isEqualTo(0);
466468
}
467469

470+
@Test // gh-498
471+
void shouldDeleteAllById() {
472+
473+
jdbc.execute("INSERT INTO legoset (name, manual) VALUES('SCHAUFELRADBAGGER', 12)");
474+
Integer id = jdbc.queryForObject("SELECT id FROM legoset", Integer.class);
475+
476+
repository.deleteAllById(asList(id)) //
477+
.as(StepVerifier::create) //
478+
.verifyComplete();
479+
480+
Integer count = jdbc.queryForObject("SELECT COUNT(*) FROM legoset", Integer.class);
481+
assertThat(count).isEqualTo(0);
482+
}
483+
468484
@Data
469485
@Table("legoset")
470486
@AllArgsConstructor

0 commit comments

Comments
 (0)