Skip to content

Commit e533a75

Browse files
committed
DATAGRAPH-1428 - Implement deleteAllById(Iterable<ID> ids).
1 parent 02b2b65 commit e533a75

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-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
@@ -43,6 +43,7 @@
4343
* @author Gerrit Meier
4444
* @author Michael J. Simons
4545
* @author Ján Šúr
46+
* @author Jens Schauder
4647
* @since 6.0
4748
* @param <T> the type of the domain class managed by this repository
4849
* @param <ID> the type of the unique identifier of the domain class
@@ -168,4 +169,11 @@ public void deleteAll(Iterable<? extends T> entities) {
168169

169170
this.neo4jOperations.deleteAllById(ids, this.entityInformation.getJavaType());
170171
}
172+
173+
@Override
174+
@Transactional
175+
public void deleteAllById(Iterable<? extends ID> ids) {
176+
177+
this.neo4jOperations.deleteAllById(ids, this.entityInformation.getJavaType());
178+
}
171179
}

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
@@ -40,6 +40,7 @@
4040
*
4141
* @author Gerrit Meier
4242
* @author Michael J. Simons
43+
* @author Jens Schauder
4344
* @since 6.0
4445
* @param <T> the type of the domain class managed by this repository
4546
* @param <ID> the type of the unique identifier of the domain class
@@ -195,11 +196,20 @@ public Mono<Void> deleteAll() {
195196
public Mono<Void> deleteAll(Iterable<? extends T> entities) {
196197

197198
Assert.notNull(entities, "The given Iterable of entities must not be null!");
199+
198200
List<ID> ids = StreamSupport.stream(entities.spliterator(), false).map(this.entityInformation::getId)
199201
.collect(Collectors.toList());
200202
return this.neo4jOperations.deleteAllById(ids, this.entityInformation.getJavaType());
201203
}
202204

205+
@Override
206+
public Mono<Void> deleteAllById(Iterable<? extends ID> ids) {
207+
208+
Assert.notNull(ids, "The given Iterable of ids must not be null!");
209+
210+
return this.neo4jOperations.deleteAllById(ids, this.entityInformation.getJavaType());
211+
}
212+
203213
/*
204214
* (non-Javadoc)
205215
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#deleteAll(org.reactivestreams.Publisher)

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

Lines changed: 13 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;
@@ -1892,6 +1893,18 @@ void deleteAllEntities(@Autowired PersonRepository repository) {
18921893
assertThat(repository.existsById(id2)).isFalse();
18931894
}
18941895

1896+
@Test // DATAGRAPH-1428
1897+
void deleteAllById(@Autowired PersonRepository repository) {
1898+
1899+
PersonWithAllConstructor person3 = new PersonWithAllConstructor(id1, TEST_PERSON1_NAME, TEST_PERSON1_FIRST_NAME,
1900+
TEST_PERSON_SAMEVALUE, true, 1L, TEST_PERSON1_BORN_ON, "something", Arrays.asList("a", "b"), NEO4J_HQ,
1901+
Instant.now());
1902+
1903+
repository.deleteAllById(Arrays.asList(person1.getId(), person3.getId()));
1904+
1905+
assertThat(repository.findAll()).extracting(PersonWithAllConstructor::getId).containsExactly(id2);
1906+
}
1907+
18951908
@Test
18961909
void deleteAll(@Autowired PersonRepository repository) {
18971910

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
@@ -104,6 +104,7 @@
104104
* @author Gerrit Meier
105105
* @author Michael J. Simons
106106
* @author Philipp Tölle
107+
* @author Jens Schauder
107108
*/
108109
@ExtendWith(Neo4jExtension.class)
109110
@SpringJUnitConfig
@@ -1910,6 +1911,13 @@ void deleteAllEntitiesPublisher(@Autowired ReactivePersonRepository repository)
19101911
.concatWith(repository.existsById(id2)).as(StepVerifier::create).expectNext(false, false).verifyComplete();
19111912
}
19121913

1914+
@Test // DATAGRAPH-1428
1915+
void deleteAllById(@Autowired ReactivePersonRepository repository) {
1916+
1917+
repository.deleteAllById(Arrays.asList(person1.getId(), person2.getId())).then(repository.existsById(id1))
1918+
.concatWith(repository.existsById(id2)).as(StepVerifier::create).expectNext(false, false).verifyComplete();
1919+
}
1920+
19131921
@Test
19141922
void deleteSimpleRelationship(@Autowired ReactiveRelationshipRepository repository) {
19151923
try (Session session = createSession()) {

0 commit comments

Comments
 (0)