Skip to content

DATACASS-825 - Implements deleteAllById(Iterable<ID> ids). #181

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra-parent</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.0-DATACASS-825-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data for Apache Cassandra</name>
Expand Down Expand Up @@ -98,7 +98,7 @@
<hppc.version>0.5.4</hppc.version>
<multithreadedtc.version>1.01</multithreadedtc.version>
<project.type>multi</project.type>
<springdata.commons>2.5.0-SNAPSHOT</springdata.commons>
<springdata.commons>2.4.0-DATACMNS-800-SNAPSHOT</springdata.commons>
</properties>

<repositories>
Expand Down
2 changes: 1 addition & 1 deletion spring-data-cassandra-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra-parent</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.0-DATACASS-825-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-cassandra/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra-parent</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.0-DATACASS-825-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
* @author Matthew T. Adams
* @author Mark Paluch
* @author John Blum
* @author Jens Schauder
* @see org.springframework.data.cassandra.repository.CassandraRepository
*/
public class SimpleCassandraRepository<T, ID> implements CassandraRepository<T, ID> {
Expand Down Expand Up @@ -247,6 +248,14 @@ public void deleteAll(Iterable<? extends T> entities) {
entities.forEach(this.operations::delete);
}

@Override
public void deleteAllById(Iterable<? extends ID> ids) {

Assert.notNull(ids, "The given Iterable of ids must not be null");

ids.forEach(id -> operations.deleteById(id, entityInformation.getJavaType()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use the same semantics as with findAllById(…) regarding the query mechanism to avoid individual database queries for each ID.

}

/* (non-Javadoc)
* @see org.springframework.data.repository.CrudRepository#deleteAll()
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
*
* @author Mark Paluch
* @author Christoph Strobl
* @author Jens Schauder
* @since 2.0
*/
public class SimpleReactiveCassandraRepository<T, ID> implements ReactiveCassandraRepository<T, ID> {
Expand Down Expand Up @@ -304,6 +305,14 @@ public Mono<Void> deleteAll(Iterable<? extends T> entities) {
return Flux.fromIterable(entities).flatMap(this.operations::delete).then();
}

@Override
public Mono<Void> deleteAllById(Iterable<? extends ID> ids) {

Assert.notNull(ids, "The given Iterable of entities must not be null");

return Flux.fromIterable(ids).flatMap(this::deleteById).then();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use the same semantics as with findAllById(…) regarding the query mechanism to avoid individual database queries for each ID.

}

/* (non-Javadoc)
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#deleteAll(org.reactivestreams.Publisher)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.springframework.data.cassandra.repository.support;

import static java.util.Arrays.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;

Expand Down Expand Up @@ -62,6 +63,7 @@
* Integration tests for {@link SimpleCassandraRepository}.
*
* @author Mark Paluch
* @author Jens Schauder
*/
@SpringJUnitConfig
public class SimpleCassandraRepositoryIntegrationTests extends IntegrationTestsSupport
Expand Down Expand Up @@ -125,7 +127,7 @@ void setUp() {
carter = new User("49", "Carter", "Beauford");
boyd = new User("45", "Boyd", "Tinsley");

repository.saveAll(Arrays.asList(oliver, dave, carter, boyd));
repository.saveAll(asList(oliver, dave, carter, boyd));

eventListener.clear();
}
Expand Down Expand Up @@ -181,7 +183,7 @@ void findAllShouldReturnAllResults() {
@Test // DATACASS-396, DATACASS-416
void findAllByIterableOfIdShouldReturnResults() {

List<User> Users = repository.findAllById(Arrays.asList(dave.getId(), boyd.getId()));
List<User> Users = repository.findAllById(asList(dave.getId(), boyd.getId()));

assertThat(Users).hasSize(2);
}
Expand Down Expand Up @@ -253,7 +255,7 @@ void insertIterableOfEntitiesShouldInsertEntity() {

repository.deleteAll();

repository.insert(Arrays.asList(dave, oliver, boyd));
repository.insert(asList(dave, oliver, boyd));

assertThat(repository.count()).isEqualTo(3);
}
Expand Down Expand Up @@ -309,7 +311,7 @@ void saveIterableOfNewEntitiesShouldInsertEntity() {

repository.deleteAll();

List<User> saved = repository.saveAll(Arrays.asList(dave, oliver, boyd));
List<User> saved = repository.saveAll(asList(dave, oliver, boyd));

assertThat(saved).hasSize(3).contains(dave, oliver, boyd);

Expand All @@ -324,7 +326,7 @@ void saveIterableOfMixedEntitiesShouldInsertEntity() {
dave.setFirstname("Hello, Dave");
dave.setLastname("Bowman");

List<User> saved = repository.saveAll(Arrays.asList(User, dave));
List<User> saved = repository.saveAll(asList(User, dave));

assertThat(saved).hasSize(2);

Expand Down Expand Up @@ -355,6 +357,16 @@ void deleteByIdShouldRemoveEntity() {
assertThat(loaded).isEmpty();
}

@Test // DATACASS-825
void deleteAllByIdShouldRemoveEntity() {

repository.deleteAllById(asList(dave.getId()));

Optional<User> loaded = repository.findById(dave.getId());

assertThat(loaded).isEmpty();
}

@Test // DATACASS-396
void deleteShouldRemoveEntity() {

Expand All @@ -368,7 +380,7 @@ void deleteShouldRemoveEntity() {
@Test // DATACASS-396
void deleteIterableOfEntitiesShouldRemoveEntities() {

repository.deleteAll(Arrays.asList(dave, boyd));
repository.deleteAll(asList(dave, boyd));

Optional<User> loaded = repository.findById(boyd.getId());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.springframework.data.cassandra.repository.support;

import static org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;

Expand Down Expand Up @@ -59,6 +60,7 @@
*
* @author Mark Paluch
* @author Christoph Strobl
* @author Jens Schauder
*/
@SpringJUnitConfig
public class SimpleReactiveCassandraRepositoryIntegrationTests extends IntegrationTestsSupport
Expand Down Expand Up @@ -391,6 +393,17 @@ void deleteByIdUsingMonoShouldRemoveEntity() {
repository.existsById(dave.getId()).as(StepVerifier::create).expectNext(false).verifyComplete();
}

@Test // DATACASS-825
void deleteAllByIdRemovesEntities() {

insertTestData();

repository.deleteAllById(Arrays.asList(dave.getId(), carter.getId())).as(StepVerifier::create).verifyComplete();

repository.existsById(dave.getId()).as(StepVerifier::create).expectNext(false).verifyComplete();
repository.existsById(carter.getId()).as(StepVerifier::create).expectNext(false).verifyComplete();
}

@Test // DATACASS-462
void deleteByIdUsingFluxShouldRemoveFirstEntity() {

Expand Down