Skip to content

Commit 2d21b48

Browse files
committed
Add inherited labels as parameters to deleteAll.
Before this change, the query itself already assumed that there will be a parameter for the inherited labels. But this parameter was never bound to the query. Closes #3092 Signed-off-by: Gerrit Meier <meistermeier@gmail.com> (cherry picked from commit ffaff20)
1 parent ac25064 commit 2d21b48

5 files changed

Lines changed: 139 additions & 1 deletion

File tree

src/main/java/org/springframework/data/neo4j/core/Neo4jTemplate.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,9 @@ public void deleteAll(Class<?> domainType) {
809809
() -> String.format("Deleting all nodes with primary label %s", entityMetaData.getPrimaryLabel()));
810810

811811
Statement statement = this.cypherGenerator.prepareDeleteOf(entityMetaData);
812-
ResultSummary summary = this.neo4jClient.query(this.renderer.render(statement)).run();
812+
ResultSummary summary = this.neo4jClient.query(this.renderer.render(statement))
813+
.bindAll(statement.getCatalog().getParameters())
814+
.run();
813815

814816
log.debug(() -> String.format("Deleted %d nodes and %d relationships.", summary.counters().nodesDeleted(),
815817
summary.counters().relationshipsDeleted()));

src/test/java/org/springframework/data/neo4j/integration/issues/IssuesIT.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Map;
2626
import java.util.Optional;
2727
import java.util.Set;
28+
import java.util.UUID;
2829
import java.util.stream.Collectors;
2930
import java.util.stream.IntStream;
3031

@@ -201,6 +202,9 @@
201202
import org.springframework.data.neo4j.integration.issues.gh2973.RelationshipD;
202203
import org.springframework.data.neo4j.integration.issues.gh3036.Vehicle;
203204
import org.springframework.data.neo4j.integration.issues.gh3036.VehicleRepository;
205+
import org.springframework.data.neo4j.integration.issues.gh3092.DynamicLabelChild;
206+
import org.springframework.data.neo4j.integration.issues.gh3092.DynamicLabelChildRepository;
207+
import org.springframework.data.neo4j.integration.issues.gh3092.DynamicLabelRoot;
204208
import org.springframework.data.neo4j.integration.issues.qbe.A;
205209
import org.springframework.data.neo4j.integration.issues.qbe.ARepository;
206210
import org.springframework.data.neo4j.integration.issues.qbe.B;
@@ -1420,6 +1424,24 @@ void dynamicLabels(@Autowired FruitRepository repository) {
14201424
assertThat(fruits).allMatch(f -> f instanceof Apple || f instanceof Orange);
14211425
}
14221426

1427+
@Test
1428+
void dynamicLabelsDeleteAll(@Autowired DynamicLabelChildRepository repository, @Autowired Neo4jTemplate template) {
1429+
1430+
// some data for verification
1431+
var child = new DynamicLabelChild();
1432+
child.setUuid(UUID.randomUUID());
1433+
child.setLabels(Set.of("new", "labels"));
1434+
repository.save(child);
1435+
1436+
var root = new DynamicLabelRoot();
1437+
template.save(root);
1438+
1439+
repository.deleteAll();
1440+
1441+
assertThat(repository.findAll()).isEmpty();
1442+
assertThat(template.findAll(DynamicLabelRoot.class)).hasSize(1);
1443+
}
1444+
14231445
@Test
14241446
@Tag("GH-2905")
14251447
void storeFromRootAggregate(@Autowired ToRepositoryV1 toRepositoryV1, @Autowired Driver driver) {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2011-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.neo4j.integration.issues.gh3092;
17+
18+
import java.util.HashSet;
19+
import java.util.Set;
20+
21+
import org.springframework.data.neo4j.core.schema.DynamicLabels;
22+
import org.springframework.data.neo4j.core.schema.Node;
23+
24+
/**
25+
* @author Gerrit Meier
26+
*/
27+
@Node
28+
public class DynamicLabelChild extends DynamicLabelRoot {
29+
30+
// @Id
31+
// @GeneratedValue(GeneratedValue.UUIDGenerator.class)
32+
// private UUID uuid;
33+
34+
@DynamicLabels
35+
Set<String> labels = new HashSet<>();
36+
37+
public Set<String> getLabels() {
38+
return this.labels;
39+
}
40+
41+
public void setLabels(Set<String> labels) {
42+
this.labels = labels;
43+
}
44+
45+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2011-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.neo4j.integration.issues.gh3092;
17+
18+
import java.util.UUID;
19+
20+
import org.springframework.data.neo4j.repository.Neo4jRepository;
21+
22+
/**
23+
* @author Gerrit Meier
24+
*/
25+
public interface DynamicLabelChildRepository extends Neo4jRepository<DynamicLabelChild, UUID> {
26+
27+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2011-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.neo4j.integration.issues.gh3092;
17+
18+
import java.util.UUID;
19+
20+
import org.springframework.data.neo4j.core.schema.GeneratedValue;
21+
import org.springframework.data.neo4j.core.schema.Id;
22+
import org.springframework.data.neo4j.core.schema.Node;
23+
24+
/**
25+
* @author Gerrit Meier
26+
*/
27+
@Node
28+
public class DynamicLabelRoot {
29+
30+
@Id
31+
@GeneratedValue(GeneratedValue.UUIDGenerator.class)
32+
UUID uuid;
33+
34+
public UUID getUuid() {
35+
return this.uuid;
36+
}
37+
38+
public void setUuid(UUID uuid) {
39+
this.uuid = uuid;
40+
}
41+
42+
}

0 commit comments

Comments
 (0)