-
Notifications
You must be signed in to change notification settings - Fork 1.1k
DATAMONGO-2652 - Implements deleteAllById. #892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
70a2370
90884e3
57e0d0f
8d5ea38
9dab7e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ | |
* @author Oliver Gierke | ||
* @author Christoph Strobl | ||
* @author Ruben J Garcia | ||
* @author Jens Schauder | ||
* @since 2.0 | ||
*/ | ||
public class SimpleReactiveMongoRepository<T, ID extends Serializable> implements ReactiveMongoRepository<T, ID> { | ||
|
@@ -404,6 +405,14 @@ public Mono<Void> deleteAll(Iterable<? extends T> entities) { | |
return Flux.fromIterable(entities).flatMap(this::delete).then(); | ||
} | ||
|
||
@Override | ||
public Mono<Void> deleteAllById(Iterable<? extends ID> ids) { | ||
|
||
Assert.notNull(ids, "The given Iterable of ids must not be null!"); | ||
|
||
return Flux.fromIterable(ids).flatMap(this::deleteById).then(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should collect all ID's into a query to run a single delete query and to avoid issuing a query per given Id. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we do the same for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made the same change for Pick and choose. |
||
} | ||
|
||
/* | ||
* (non-Javadoc) | ||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#deleteAll(org.reactivestreams.Publisher) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
*/ | ||
package org.springframework.data.mongodb.repository; | ||
|
||
import static java.util.Arrays.*; | ||
import static org.assertj.core.api.Assertions.*; | ||
import static org.springframework.data.domain.Sort.Direction.*; | ||
import static org.springframework.data.mongodb.core.query.Criteria.*; | ||
|
@@ -66,7 +67,6 @@ | |
import org.springframework.data.mongodb.test.util.MongoTestUtils; | ||
import org.springframework.data.querydsl.ReactiveQuerydslPredicateExecutor; | ||
import org.springframework.data.repository.Repository; | ||
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider; | ||
import org.springframework.data.repository.query.ReactiveQueryMethodEvaluationContextProvider; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
|
||
|
@@ -77,10 +77,12 @@ | |
* | ||
* @author Mark Paluch | ||
* @author Christoph Strobl | ||
* @author Jens Schauder | ||
*/ | ||
@ExtendWith({ MongoClientExtension.class, SpringExtension.class }) | ||
public class ReactiveMongoRepositoryTests { | ||
|
||
public static final int PERSON_COUNT = 7; | ||
static @Client MongoClient mongoClient; | ||
|
||
@Autowired ReactiveMongoTemplate template; | ||
|
@@ -154,17 +156,17 @@ public void setUp() throws Exception { | |
dave = new Person("Dave", "Matthews", 42); | ||
oliver = new Person("Oliver August", "Matthews", 4); | ||
carter = new Person("Carter", "Beauford", 49); | ||
carter.setSkills(Arrays.asList("Drums", "percussion", "vocals")); | ||
carter.setSkills(asList("Drums", "percussion", "vocals")); | ||
Thread.sleep(10); | ||
boyd = new Person("Boyd", "Tinsley", 45); | ||
boyd.setSkills(Arrays.asList("Violin", "Electric Violin", "Viola", "Mandolin", "Vocals", "Guitar")); | ||
boyd.setSkills(asList("Violin", "Electric Violin", "Viola", "Mandolin", "Vocals", "Guitar")); | ||
stefan = new Person("Stefan", "Lessard", 34); | ||
leroi = new Person("Leroi", "Moore", 41); | ||
|
||
alicia = new Person("Alicia", "Keys", 30, Sex.FEMALE); | ||
|
||
repository.saveAll(Arrays.asList(oliver, carter, boyd, stefan, leroi, alicia, dave)).as(StepVerifier::create) // | ||
.expectNextCount(7) // | ||
repository.saveAll(asList(oliver, carter, boyd, stefan, leroi, alicia, dave)).as(StepVerifier::create) // | ||
.expectNextCount(PERSON_COUNT) // | ||
.verifyComplete(); | ||
} | ||
|
||
|
@@ -411,7 +413,7 @@ public void considersRepositoryCollectionName() { | |
|
||
leroi.id = null; | ||
boyd.id = null; | ||
contactRepository.saveAll(Arrays.asList(leroi, boyd)) // | ||
contactRepository.saveAll(asList(leroi, boyd)) // | ||
.as(StepVerifier::create) // | ||
.expectNextCount(2) // | ||
.verifyComplete(); | ||
|
@@ -430,7 +432,7 @@ public void considersRepositoryCollectionName() { | |
@Test // DATAMONGO-2182 | ||
public void shouldFindPersonsWhenUsingQueryDslPerdicatedOnIdProperty() { | ||
|
||
repository.findAll(person.id.in(Arrays.asList(dave.id, carter.id))) // | ||
repository.findAll(person.id.in(asList(dave.id, carter.id))) // | ||
.collectList() // | ||
.as(StepVerifier::create) // | ||
.assertNext(actual -> { | ||
|
@@ -468,7 +470,7 @@ public void annotatedAggregationWithPlaceholderValue() { | |
.contains(new PersonAggregate("Tinsley", "Boyd")) // | ||
.contains(new PersonAggregate("Beauford", "Carter")) // | ||
.contains(new PersonAggregate("Moore", "Leroi")) // | ||
.contains(new PersonAggregate("Matthews", Arrays.asList("Dave", "Oliver August"))); | ||
.contains(new PersonAggregate("Matthews", asList("Dave", "Oliver August"))); | ||
}).verifyComplete(); | ||
} | ||
|
||
|
@@ -484,7 +486,7 @@ public void annotatedAggregationWithSort() { | |
new PersonAggregate("Beauford", "Carter"), // | ||
new PersonAggregate("Keys", "Alicia"), // | ||
new PersonAggregate("Lessard", "Stefan"), // | ||
new PersonAggregate("Matthews", Arrays.asList("Dave", "Oliver August")), // | ||
new PersonAggregate("Matthews", asList("Dave", "Oliver August")), // | ||
new PersonAggregate("Moore", "Leroi"), // | ||
new PersonAggregate("Tinsley", "Boyd")); | ||
}) // | ||
|
@@ -501,7 +503,7 @@ public void annotatedAggregationWithPageable() { | |
assertThat(actual) // | ||
.containsExactly( // | ||
new PersonAggregate("Lessard", "Stefan"), // | ||
new PersonAggregate("Matthews", Arrays.asList("Dave", "Oliver August"))); | ||
new PersonAggregate("Matthews", asList("Dave", "Oliver August"))); | ||
}) // | ||
.verifyComplete(); | ||
} | ||
|
@@ -576,7 +578,7 @@ public void annotatedAggregationSkipsEmptyDocumentsWhenExtractingSimpleValue() { | |
Person p3 = new Person(firstname, null); | ||
p3.setEmail("[email protected]"); | ||
|
||
repository.saveAll(Arrays.asList(p1, p2, p3)).then().as(StepVerifier::create).verifyComplete(); | ||
repository.saveAll(asList(p1, p2, p3)).then().as(StepVerifier::create).verifyComplete(); | ||
|
||
repository.projectToLastnameAndRemoveId(firstname) // | ||
.as(StepVerifier::create) // | ||
|
@@ -617,6 +619,18 @@ public void deleteByShouldAllowSingleDocumentRemovalCorrectly() { | |
.verifyComplete(); | ||
} | ||
|
||
@Test // DATAMONGO-2652 | ||
public void deleteAllById() { | ||
|
||
repository.deleteAllById(asList(carter.id, dave.id)) // | ||
.as(StepVerifier::create) // | ||
.verifyComplete(); | ||
|
||
repository.count().as(StepVerifier::create) // | ||
.expectNext(PERSON_COUNT - 2L) // | ||
.verifyComplete(); | ||
} | ||
|
||
interface ReactivePersonRepository | ||
extends ReactiveMongoRepository<Person, String>, ReactiveQuerydslPredicateExecutor<Person> { | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use a single query here. Going to apply that change during the merge.