From 28ce97a647a19e83ac7d7f4bfa367ec3cb80ef2d Mon Sep 17 00:00:00 2001 From: Michael Simons Date: Wed, 21 Feb 2024 12:15:17 +0000 Subject: [PATCH] fix: Several issues wrt JavaDoc and the module-path. (#2865) The latest version of the Maven JavaDoc plugin and JavaDoc itself have been rightfully complaining that some pieces of SDN have been using internal API of the driver and Cypher-DSL which would not be available on the module-path. This has been fixed. The schema-name support from Cypher-DSL is now a direct dependency and not relying on the shaded version any long. Several issues in the `Neo4jSpelSupport` have been fixed along the way. --- pom.xml | 9 ++++++++ .../neo4j/core/mapping/CypherGenerator.java | 3 +-- .../mapping/DefaultNeo4jEntityConverter.java | 3 +-- .../neo4j/core/mapping/MapValueWrapper.java | 2 +- .../repository/query/Neo4jSpelSupport.java | 21 +++++++++---------- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/pom.xml b/pom.xml index c9f6246e4..3a9b1ad63 100644 --- a/pom.xml +++ b/pom.xml @@ -198,6 +198,11 @@ + + org.neo4j + neo4j-cypher-dsl-schema-name-support + ${cypher-dsl.version} + org.neo4j.driver neo4j-java-driver @@ -370,6 +375,10 @@ org.neo4j neo4j-cypher-dsl + + org.neo4j + neo4j-cypher-dsl-schema-name-support + org.neo4j.driver neo4j-java-driver 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 0768e85fe..81c0f98c5 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 @@ -60,7 +60,6 @@ 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; @@ -701,7 +700,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."); + Assert.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/main/java/org/springframework/data/neo4j/core/mapping/DefaultNeo4jEntityConverter.java b/src/main/java/org/springframework/data/neo4j/core/mapping/DefaultNeo4jEntityConverter.java index 4ca845a95..23b142ad0 100644 --- a/src/main/java/org/springframework/data/neo4j/core/mapping/DefaultNeo4jEntityConverter.java +++ b/src/main/java/org/springframework/data/neo4j/core/mapping/DefaultNeo4jEntityConverter.java @@ -38,7 +38,6 @@ import java.util.stream.StreamSupport; import org.neo4j.driver.Record; import org.neo4j.driver.Value; import org.neo4j.driver.Values; -import org.neo4j.driver.internal.value.NullValue; import org.neo4j.driver.types.MapAccessor; import org.neo4j.driver.types.Node; import org.neo4j.driver.types.Relationship; @@ -895,7 +894,7 @@ final class DefaultNeo4jEntityConverter implements Neo4jEntityConverter { } else if (propertyContainer.containsKey(Constants.NAME_OF_ALL_PROPERTIES)) { return propertyContainer.get(Constants.NAME_OF_ALL_PROPERTIES).get(graphPropertyName); } else { - return NullValue.NULL; + return Values.NULL; } } } diff --git a/src/main/java/org/springframework/data/neo4j/core/mapping/MapValueWrapper.java b/src/main/java/org/springframework/data/neo4j/core/mapping/MapValueWrapper.java index ec2cfd9f9..c35858c7b 100644 --- a/src/main/java/org/springframework/data/neo4j/core/mapping/MapValueWrapper.java +++ b/src/main/java/org/springframework/data/neo4j/core/mapping/MapValueWrapper.java @@ -19,7 +19,7 @@ import org.apiguardian.api.API; import org.neo4j.driver.Value; /** - * A wrapper or marker for a Neo4j {@link org.neo4j.driver.internal.value.MapValue} that needs to be unwrapped when used + * A wrapper or marker for a Neo4j {@code org.neo4j.driver.internal.value.MapValue} that needs to be unwrapped when used * for properties. * This class exists solely for projection / filtering purposes: It allows the {@link DefaultNeo4jEntityConverter} to keep * the composite properties together as long as possible (in the form of above's {@code MapValue}. Thus, the key in the diff --git a/src/main/java/org/springframework/data/neo4j/repository/query/Neo4jSpelSupport.java b/src/main/java/org/springframework/data/neo4j/repository/query/Neo4jSpelSupport.java index 2b67a31ce..837f6277e 100644 --- a/src/main/java/org/springframework/data/neo4j/repository/query/Neo4jSpelSupport.java +++ b/src/main/java/org/springframework/data/neo4j/repository/query/Neo4jSpelSupport.java @@ -15,6 +15,7 @@ */ package org.springframework.data.neo4j.repository.query; +import java.io.Serial; import java.util.Collection; import java.util.LinkedHashMap; import java.util.Locale; @@ -24,10 +25,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; -import org.apache.commons.logging.LogFactory; import org.apiguardian.api.API; -import org.neo4j.cypherdsl.core.internal.SchemaNames; -import org.springframework.core.log.LogAccessor; +import org.neo4j.cypherdsl.support.schema_name.SchemaNames; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.data.neo4j.core.mapping.CypherGenerator; @@ -57,8 +56,6 @@ public final class Neo4jSpelSupport { public static String FUNCTION_ALL_OF = "allOf"; public static String FUNCTION_ORDER_BY = "orderBy"; - private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(Neo4jSpelSupport.class)); - /** * Takes {@code arg} and tries to either extract a {@link Sort sort} from it or cast it to a sort. That sort is * than past to the {@link CypherGenerator} that renders a valid order by fragment which replaces the SpEL placeholder @@ -90,9 +87,8 @@ public final class Neo4jSpelSupport { */ public static LiteralReplacement literal(@Nullable Object arg) { - LiteralReplacement literalReplacement = StringBasedLiteralReplacement + return StringBasedLiteralReplacement .withTargetAndValue(LiteralReplacement.Target.UNSPECIFIED, arg == null ? "" : arg.toString()); - return literalReplacement; } public static LiteralReplacement anyOf(@Nullable Object arg) { @@ -113,7 +109,7 @@ public final class Neo4jSpelSupport { private static String joinStrings(Object arg, String joinOn) { if (arg instanceof Collection) { return ((Collection) arg).stream() - .map(o -> SchemaNames.sanitize(o.toString()).get()) + .map(o -> SchemaNames.sanitize(o.toString()).orElseThrow()) .collect(Collectors.joining(joinOn)); } @@ -130,7 +126,7 @@ public final class Neo4jSpelSupport { * comes in handy in places where non-parameterizable things should be created dynamic, for example matching on * set of dynamic labels, types order ordering in a dynamic way. */ - interface LiteralReplacement { + public interface LiteralReplacement { /** * The target of this replacement. While a replacement can be used theoretically everywhere in the query, the target @@ -155,7 +151,10 @@ public final class Neo4jSpelSupport { * the creation of too many small objects. */ private static final Map INSTANCES = - new LinkedHashMap(DEFAULT_CACHE_SIZE) { + new LinkedHashMap<>(DEFAULT_CACHE_SIZE) { + @Serial + private static final long serialVersionUID = 195460174410223375L; + @Override protected boolean removeEldestEntry(Map.Entry eldest) { return size() > DEFAULT_CACHE_SIZE; @@ -167,7 +166,7 @@ public final class Neo4jSpelSupport { static LiteralReplacement withTargetAndValue(LiteralReplacement.Target target, @Nullable String value) { String valueUsed = value == null ? "" : value; - String key = new StringBuilder(target.name()).append("_").append(valueUsed).toString(); + String key = target.name() + "_" + valueUsed; long stamp = LOCK.tryOptimisticRead(); if (LOCK.validate(stamp) && INSTANCES.containsKey(key)) {