Skip to content

Commit 5fe7f47

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>
1 parent 30de08b commit 5fe7f47

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
@@ -751,7 +751,9 @@ public void deleteAll(Class<?> domainType) {
751751
log.debug(() -> String.format("Deleting all nodes with primary label %s", entityMetaData.getPrimaryLabel()));
752752

753753
Statement statement = cypherGenerator.prepareDeleteOf(entityMetaData);
754-
ResultSummary summary = this.neo4jClient.query(renderer.render(statement)).run();
754+
ResultSummary summary = this.neo4jClient.query(renderer.render(statement))
755+
.bindAll(statement.getCatalog().getParameters())
756+
.run();
755757

756758
log.debug(() -> String.format("Deleted %d nodes and %d relationships.", summary.counters().nodesDeleted(),
757759
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
@@ -31,6 +31,7 @@
3131
import java.util.Map;
3232
import java.util.Optional;
3333
import java.util.Set;
34+
import java.util.UUID;
3435
import java.util.stream.Collectors;
3536
import java.util.stream.IntStream;
3637

@@ -198,6 +199,9 @@
198199
import org.springframework.data.neo4j.integration.issues.gh2973.RelationshipD;
199200
import org.springframework.data.neo4j.integration.issues.gh3036.Vehicle;
200201
import org.springframework.data.neo4j.integration.issues.gh3036.VehicleRepository;
202+
import org.springframework.data.neo4j.integration.issues.gh3092.DynamicLabelChild;
203+
import org.springframework.data.neo4j.integration.issues.gh3092.DynamicLabelChildRepository;
204+
import org.springframework.data.neo4j.integration.issues.gh3092.DynamicLabelRoot;
201205
import org.springframework.data.neo4j.integration.issues.qbe.A;
202206
import org.springframework.data.neo4j.integration.issues.qbe.ARepository;
203207
import org.springframework.data.neo4j.integration.issues.qbe.B;
@@ -1292,6 +1296,24 @@ void dynamicLabels(@Autowired FruitRepository repository) {
12921296
assertThat(fruits).allMatch(f -> f instanceof Apple || f instanceof Orange);
12931297
}
12941298

1299+
@Test
1300+
void dynamicLabelsDeleteAll(@Autowired DynamicLabelChildRepository repository, @Autowired Neo4jTemplate template) {
1301+
1302+
// some data for verification
1303+
var child = new DynamicLabelChild();
1304+
child.setUuid(UUID.randomUUID());
1305+
child.setLabels(Set.of("new", "labels"));
1306+
repository.save(child);
1307+
1308+
var root = new DynamicLabelRoot();
1309+
template.save(root);
1310+
1311+
repository.deleteAll();
1312+
1313+
assertThat(repository.findAll()).isEmpty();
1314+
assertThat(template.findAll(DynamicLabelRoot.class)).hasSize(1);
1315+
}
1316+
12951317
@Test
12961318
@Tag("GH-2905")
12971319
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)