Skip to content

Commit bcddf8e

Browse files
schaudermp911de
authored andcommitted
DATAGRAPH-1428 - Implement CrudRepository and ReactiveCrudRepository.deleteAllById(Iterable<ID> ids).
Original pull request: #554.
1 parent a469683 commit bcddf8e

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

src/main/java/org/springframework/data/neo4j/repository/support/SimpleNeo4jRepository.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
* @author Gerrit Meier
4545
* @author Michael J. Simons
4646
* @author Ján Šúr
47+
* @author Jens Schauder
4748
* @since 6.0
4849
* @param <T> the type of the domain class managed by this repository
4950
* @param <ID> the type of the unique identifier of the domain class
@@ -175,4 +176,11 @@ public void deleteAll(Iterable<? extends T> entities) {
175176

176177
this.neo4jOperations.deleteAllById(ids, this.entityInformation.getJavaType());
177178
}
179+
180+
@Override
181+
@Transactional
182+
public void deleteAllById(Iterable<? extends ID> ids) {
183+
184+
this.neo4jOperations.deleteAllById(ids, this.entityInformation.getJavaType());
185+
}
178186
}

src/main/java/org/springframework/data/neo4j/repository/support/SimpleReactiveNeo4jRepository.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
*
4242
* @author Gerrit Meier
4343
* @author Michael J. Simons
44+
* @author Jens Schauder
4445
* @since 6.0
4546
* @param <T> the type of the domain class managed by this repository
4647
* @param <ID> the type of the unique identifier of the domain class
@@ -204,11 +205,20 @@ public Mono<Void> deleteAll() {
204205
public Mono<Void> deleteAll(Iterable<? extends T> entities) {
205206

206207
Assert.notNull(entities, "The given Iterable of entities must not be null!");
208+
207209
List<ID> ids = StreamSupport.stream(entities.spliterator(), false).map(this.entityInformation::getId)
208210
.collect(Collectors.toList());
209211
return this.neo4jOperations.deleteAllById(ids, this.entityInformation.getJavaType());
210212
}
211213

214+
@Override
215+
public Mono<Void> deleteAllById(Iterable<? extends ID> ids) {
216+
217+
Assert.notNull(ids, "The given Iterable of ids must not be null!");
218+
219+
return this.neo4jOperations.deleteAllById(ids, this.entityInformation.getJavaType());
220+
}
221+
212222
/*
213223
* (non-Javadoc)
214224
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#deleteAll(org.reactivestreams.Publisher)

src/test/java/org/springframework/data/neo4j/integration/imperative/RepositoryIT.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
2121
import static org.assertj.core.api.Assertions.tuple;
2222

23+
import java.time.Instant;
2324
import java.time.LocalDate;
2425
import java.time.LocalDateTime;
2526
import java.time.ZoneOffset;
@@ -2105,6 +2106,20 @@ void deleteAllEntities(@Autowired PersonRepository repository) {
21052106
assertThat(repository.existsById(id2)).isFalse();
21062107
}
21072108

2109+
@Test // DATAGRAPH-1428
2110+
void deleteAllById(@Autowired PersonRepository repository) {
2111+
2112+
PersonWithAllConstructor person3 = new PersonWithAllConstructor(id1, TEST_PERSON1_NAME, TEST_PERSON1_FIRST_NAME,
2113+
TEST_PERSON_SAMEVALUE, true, 1L, TEST_PERSON1_BORN_ON, "something", Arrays.asList("a", "b"), NEO4J_HQ,
2114+
Instant.now());
2115+
2116+
repository.save(person3);
2117+
2118+
repository.deleteAllById(Arrays.asList(person1.getId(), person3.getId()));
2119+
2120+
assertThat(repository.findAll()).extracting(PersonWithAllConstructor::getId).containsExactly(id2);
2121+
}
2122+
21082123
@Test
21092124
void deleteAll(@Autowired PersonRepository repository) {
21102125

src/test/java/org/springframework/data/neo4j/integration/reactive/ReactiveRepositoryIT.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
* @author Gerrit Meier
110110
* @author Michael J. Simons
111111
* @author Philipp Tölle
112+
* @author Jens Schauder
112113
*/
113114
@ExtendWith(Neo4jExtension.class)
114115
@SpringJUnitConfig
@@ -2033,6 +2034,13 @@ void deleteAllEntitiesPublisher(@Autowired ReactivePersonRepository repository)
20332034
.concatWith(repository.existsById(id2)).as(StepVerifier::create).expectNext(false, false).verifyComplete();
20342035
}
20352036

2037+
@Test // DATAGRAPH-1428
2038+
void deleteAllById(@Autowired ReactivePersonRepository repository) {
2039+
2040+
repository.deleteAllById(Arrays.asList(person1.getId(), person2.getId())).then(repository.existsById(id1))
2041+
.concatWith(repository.existsById(id2)).as(StepVerifier::create).expectNext(false, false).verifyComplete();
2042+
}
2043+
20362044
@Test
20372045
void deleteSimpleRelationship(@Autowired ReactiveRelationshipRepository repository) {
20382046
try (Session session = createSession()) {

0 commit comments

Comments
 (0)