From ac3896338ccdba91edaa8a9e349816094a66e8b6 Mon Sep 17 00:00:00 2001 From: Michael Simons Date: Tue, 10 Jan 2023 12:21:22 +0100 Subject: [PATCH] GH-2649 - Upgrade Cypher-DSL to 2023.0.0. Closes #2649. --- pom.xml | 2 +- .../data/neo4j/core/TemplateSupport.java | 6 +++--- .../neo4j/core/mapping/CypherGenerator.java | 17 +++++++++++------ .../custom_queries/MovieRepository.java | 14 +++++--------- .../reactive/ReactiveNeo4jClientIT.java | 8 ++++---- 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/pom.xml b/pom.xml index 452ecee3d..3bbf78059 100644 --- a/pom.xml +++ b/pom.xml @@ -77,7 +77,7 @@ ${skipTests} 8.40 4.8.149 - 2022.6.0 + 2023.0.0 spring-data-neo4j SDNEO4J 1.2.5 diff --git a/src/main/java/org/springframework/data/neo4j/core/TemplateSupport.java b/src/main/java/org/springframework/data/neo4j/core/TemplateSupport.java index b11137e75..bceab0821 100644 --- a/src/main/java/org/springframework/data/neo4j/core/TemplateSupport.java +++ b/src/main/java/org/springframework/data/neo4j/core/TemplateSupport.java @@ -211,17 +211,17 @@ public final class TemplateSupport { .with(Functions.collect(rootNodes).as(Constants.NAME_OF_ROOT_NODE)) .optionalMatch(relationships) .where(Functions.id(relationships).in(Cypher.parameter(relationshipIds))) - .with(Constants.NAME_OF_ROOT_NODE, Functions.collectDistinct(relationships).as(Constants.NAME_OF_SYNTHESIZED_RELATIONS).asExpression()) + .with(Constants.NAME_OF_ROOT_NODE, Functions.collectDistinct(relationships).as(Constants.NAME_OF_SYNTHESIZED_RELATIONS)) .optionalMatch(relatedNodes) .where(Functions.id(relatedNodes).in(Cypher.parameter(relatedNodeIds))) .with( Constants.NAME_OF_ROOT_NODE, Cypher.name(Constants.NAME_OF_SYNTHESIZED_RELATIONS).as(Constants.NAME_OF_SYNTHESIZED_RELATIONS), - Functions.collectDistinct(relatedNodes).as(Constants.NAME_OF_SYNTHESIZED_RELATED_NODES).asExpression() + Functions.collectDistinct(relatedNodes).as(Constants.NAME_OF_SYNTHESIZED_RELATED_NODES) ) .unwind(Constants.NAME_OF_ROOT_NODE).as(rootNodeIds) .with( - Cypher.name(rootNodeIds).as(Constants.NAME_OF_TYPED_ROOT_NODE.apply(nodeDescription).getValue()).asExpression(), + Cypher.name(rootNodeIds).as(Constants.NAME_OF_TYPED_ROOT_NODE.apply(nodeDescription).getValue()), Cypher.name(Constants.NAME_OF_SYNTHESIZED_RELATIONS), Cypher.name(Constants.NAME_OF_SYNTHESIZED_RELATED_NODES)) .orderBy(queryFragments.getOrderBy()) diff --git a/src/main/java/org/springframework/data/neo4j/core/mapping/CypherGenerator.java b/src/main/java/org/springframework/data/neo4j/core/mapping/CypherGenerator.java index f176d68f4..1975bd976 100644 --- a/src/main/java/org/springframework/data/neo4j/core/mapping/CypherGenerator.java +++ b/src/main/java/org/springframework/data/neo4j/core/mapping/CypherGenerator.java @@ -34,6 +34,8 @@ import java.util.function.Predicate; import java.util.function.UnaryOperator; import java.util.regex.Pattern; +import javax.lang.model.SourceVersion; + import org.apiguardian.api.API; import org.neo4j.cypherdsl.core.Condition; import org.neo4j.cypherdsl.core.Conditions; @@ -41,6 +43,7 @@ import org.neo4j.cypherdsl.core.Cypher; import org.neo4j.cypherdsl.core.Expression; import org.neo4j.cypherdsl.core.FunctionInvocation; import org.neo4j.cypherdsl.core.Functions; +import org.neo4j.cypherdsl.core.IdentifiableElement; import org.neo4j.cypherdsl.core.MapProjection; import org.neo4j.cypherdsl.core.Node; import org.neo4j.cypherdsl.core.Parameter; @@ -55,6 +58,7 @@ import org.neo4j.cypherdsl.core.StatementBuilder.OngoingUpdate; import org.neo4j.cypherdsl.core.SymbolicName; import org.neo4j.cypherdsl.core.renderer.Configuration; import org.neo4j.cypherdsl.core.renderer.Renderer; +import org.neo4j.cypherdsl.core.utils.Assertions; import org.springframework.data.domain.Sort; import org.springframework.data.mapping.MappingException; import org.springframework.data.mapping.PersistentProperty; @@ -111,12 +115,12 @@ public enum CypherGenerator { Node rootNode = createRootNode(nodeDescription); - List expressions = new ArrayList<>(); + List expressions = new ArrayList<>(); expressions.add(rootNode.getRequiredSymbolicName()); expressions.add(Functions.id(rootNode).as(Constants.NAME_OF_INTERNAL_ID)); expressions.add(Functions.elementId(rootNode).as(Constants.NAME_OF_ELEMENT_ID)); - return match(rootNode).where(conditionOrNoCondition(condition)).with(expressions.toArray(new Expression[] {})); + return match(rootNode).where(conditionOrNoCondition(condition)).with(expressions.toArray(IdentifiableElement[]::new)); } public StatementBuilder.OngoingReading prepareMatchOf(NodeDescription nodeDescription, @@ -126,12 +130,12 @@ public enum CypherGenerator { StatementBuilder.OngoingReadingWithoutWhere match = prepareMatchOfRootNode(rootNode, initialMatchOn); - List expressions = new ArrayList<>(); + List expressions = new ArrayList<>(); expressions.add(Functions.collect(Functions.id(rootNode)).as(Constants.NAME_OF_SYNTHESIZED_ROOT_NODE)); return match .where(conditionOrNoCondition(condition)) - .with(expressions.toArray(new Expression[]{})); + .with(expressions.toArray(IdentifiableElement[]::new)); } public StatementBuilder.OngoingReading prepareMatchOf(NodeDescription nodeDescription, @@ -163,7 +167,7 @@ public enum CypherGenerator { }; relationship = relationship.named(Constants.NAME_OF_SYNTHESIZED_RELATIONS); - List expressions = new ArrayList<>(); + List expressions = new ArrayList<>(); expressions.add(Functions.collect(Functions.id(rootNode)).as(Constants.NAME_OF_SYNTHESIZED_ROOT_NODE)); expressions.add(Functions.collect(Functions.id(targetNode)).as(Constants.NAME_OF_SYNTHESIZED_RELATED_NODES)); expressions.add(Functions.collect(Functions.id(relationship)).as(Constants.NAME_OF_SYNTHESIZED_RELATIONS)); @@ -171,7 +175,7 @@ public enum CypherGenerator { return match .where(conditionOrNoCondition(condition)) .optionalMatch(relationship) - .with(expressions.toArray(new Expression[]{})); + .with(expressions.toArray(IdentifiableElement[]::new)); } @NonNull @@ -619,6 +623,7 @@ public enum CypherGenerator { expression = Cypher.property(property.substring(0, firstDot), tail); } else { try { + Assertions.isTrue(SourceVersion.isIdentifier(property), "Name must be a valid identifier."); expression = Cypher.name(property); } catch (IllegalArgumentException e) { if (e.getMessage().endsWith(".")) { diff --git a/src/test/java/org/springframework/data/neo4j/documentation/repositories/custom_queries/MovieRepository.java b/src/test/java/org/springframework/data/neo4j/documentation/repositories/custom_queries/MovieRepository.java index 647fae7db..960fc93a1 100644 --- a/src/test/java/org/springframework/data/neo4j/documentation/repositories/custom_queries/MovieRepository.java +++ b/src/test/java/org/springframework/data/neo4j/documentation/repositories/custom_queries/MovieRepository.java @@ -31,11 +31,7 @@ import java.util.Map; // tag::domain-results-impl[] import org.neo4j.cypherdsl.core.Cypher; -import org.neo4j.cypherdsl.core.Expression; import org.neo4j.cypherdsl.core.Functions; -import org.neo4j.cypherdsl.core.NamedPath; -import org.neo4j.cypherdsl.core.Node; -import org.neo4j.cypherdsl.core.Statement; // end::domain-results-impl[] @@ -85,13 +81,13 @@ class DomainResultsImpl implements DomainResults { @Override public List findMoviesAlongShortestPath(PersonEntity from, PersonEntity to) { - Node p1 = node("Person").withProperties("name", parameter("person1")); - Node p2 = node("Person").withProperties("name", parameter("person2")); - NamedPath shortestPath = shortestPath("p").definedBy( + var p1 = node("Person").withProperties("name", parameter("person1")); + var p2 = node("Person").withProperties("name", parameter("person2")); + var shortestPath = shortestPath("p").definedBy( p1.relationshipBetween(p2).unbounded() ); - Expression p = shortestPath.getRequiredSymbolicName(); - Statement statement = Cypher.match(shortestPath) + var p = shortestPath.getRequiredSymbolicName(); + var statement = Cypher.match(shortestPath) .with(p, listWith(name("n")) .in(Functions.nodes(shortestPath)) .where(anyNode().named("n").hasLabels("Movie")).returning().as("mn") diff --git a/src/test/java/org/springframework/data/neo4j/integration/reactive/ReactiveNeo4jClientIT.java b/src/test/java/org/springframework/data/neo4j/integration/reactive/ReactiveNeo4jClientIT.java index c419fcc63..6ec6b59c3 100644 --- a/src/test/java/org/springframework/data/neo4j/integration/reactive/ReactiveNeo4jClientIT.java +++ b/src/test/java/org/springframework/data/neo4j/integration/reactive/ReactiveNeo4jClientIT.java @@ -20,8 +20,8 @@ import static org.assertj.core.api.Assertions.assertThat; import org.neo4j.cypherdsl.core.Statement; import org.neo4j.cypherdsl.core.executables.ExecutableResultStatement; import org.neo4j.driver.Query; -import org.neo4j.driver.QueryRunner; import org.neo4j.driver.Record; +import org.neo4j.driver.SimpleQueryRunner; import org.neo4j.driver.async.AsyncQueryRunner; import org.neo4j.driver.reactivestreams.ReactiveQueryRunner; import org.neo4j.driver.reactivestreams.ReactiveResult; @@ -176,7 +176,7 @@ class ReactiveNeo4jClientIT { } @Override - public List fetchWith(QueryRunner queryRunner, Function function) { + public List fetchWith(SimpleQueryRunner queryRunner, Function function) { throw new UnsupportedOperationException(); } @@ -186,12 +186,12 @@ class ReactiveNeo4jClientIT { } @Override - public ResultSummary streamWith(QueryRunner queryRunner, Consumer> consumer) { + public ResultSummary streamWith(SimpleQueryRunner queryRunner, Consumer> consumer) { throw new UnsupportedOperationException(); } @Override - public ResultSummary executeWith(QueryRunner queryRunner) { + public ResultSummary executeWith(SimpleQueryRunner queryRunner) { throw new UnsupportedOperationException(); }