#498 - Implements ReactiveCrudRepository.deleteAllById.

See also: DATACMNS-800.
Original pull request: #501.
This commit is contained in:
Jens Schauder
2020-11-13 15:50:26 +01:00
committed by Mark Paluch
parent 1d5e5cc6c3
commit 843c402e00
2 changed files with 31 additions and 0 deletions

View File

@@ -15,6 +15,9 @@
*/
package org.springframework.data.r2dbc.repository.support;
import org.springframework.data.util.StreamUtils;
import org.springframework.data.util.Streamable;
import org.springframework.util.CollectionUtils;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -35,6 +38,8 @@ import org.springframework.r2dbc.core.DatabaseClient;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import java.util.List;
/**
* Simple {@link ReactiveSortingRepository} implementation using R2DBC through {@link DatabaseClient}.
*
@@ -304,6 +309,16 @@ public class SimpleR2dbcRepository<T, ID> implements ReactiveSortingRepository<T
return deleteAll(Flux.fromIterable(iterable));
}
@Override
public Mono<Void> deleteAllById(Iterable<? extends ID> ids) {
Assert.notNull(ids, "The iterable of Id's must not be null!");
List<? extends ID> idsList = Streamable.of(ids).toList();
String idProperty = getIdProperty().getName();
return this.entityOperations.delete(Query.query(Criteria.where(idProperty).in(idsList)), this.entity.getJavaType()).then();
}
/* (non-Javadoc)
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#deleteAll(org.reactivestreams.Publisher)
*/

View File

@@ -16,6 +16,7 @@
package org.springframework.data.r2dbc.repository.support;
import static org.assertj.core.api.Assertions.*;
import static org.testcontainers.shaded.com.google.common.primitives.Ints.*;
import lombok.AllArgsConstructor;
import lombok.Data;
@@ -57,6 +58,7 @@ import org.springframework.r2dbc.core.DatabaseClient;
* @author Mark Paluch
* @author Bogdan Ilchyshyn
* @author Stephen Cohen
* @author Jens Schauder
*/
public abstract class AbstractSimpleR2dbcRepositoryIntegrationTests extends R2dbcIntegrationTestSupport {
@@ -465,6 +467,20 @@ public abstract class AbstractSimpleR2dbcRepositoryIntegrationTests extends R2db
assertThat(count).isEqualTo(0);
}
@Test // gh-498
void shouldDeleteAllById() {
jdbc.execute("INSERT INTO legoset (name, manual) VALUES('SCHAUFELRADBAGGER', 12)");
Integer id = jdbc.queryForObject("SELECT id FROM legoset", Integer.class);
repository.deleteAllById(asList(id)) //
.as(StepVerifier::create) //
.verifyComplete();
Integer count = jdbc.queryForObject("SELECT COUNT(*) FROM legoset", Integer.class);
assertThat(count).isEqualTo(0);
}
@Data
@Table("legoset")
@AllArgsConstructor