Browse Source

#498 - Implements ReactiveCrudRepository.deleteAllById.

See also: DATACMNS-800.
Original pull request: #501.
pull/1188/head
Jens Schauder 5 years ago committed by Mark Paluch
parent
commit
843c402e00
No known key found for this signature in database
GPG Key ID: 4406B84C1661DCD1
  1. 15
      src/main/java/org/springframework/data/r2dbc/repository/support/SimpleR2dbcRepository.java
  2. 16
      src/test/java/org/springframework/data/r2dbc/repository/support/AbstractSimpleR2dbcRepositoryIntegrationTests.java

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

@ -15,6 +15,9 @@ @@ -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; @@ -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 @@ -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)
*/

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

@ -16,6 +16,7 @@ @@ -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; @@ -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 @@ -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

Loading…
Cancel
Save