From e86cc2f029047fd55eaea259213a94ae23059832 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Thu, 16 Feb 2023 08:46:29 +0100 Subject: [PATCH] GH-2671 - Migrate off deprecated Parameters API. Migrate to newly introduced constructors and methods to consider the relationship between the domain type and Class parameters to distinguish between projection parameters and bindable class parameters. Closes #2671 --- .../repository/query/Neo4jQueryMethod.java | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/springframework/data/neo4j/repository/query/Neo4jQueryMethod.java b/src/main/java/org/springframework/data/neo4j/repository/query/Neo4jQueryMethod.java index f7b756df1..6d01cd528 100644 --- a/src/main/java/org/springframework/data/neo4j/repository/query/Neo4jQueryMethod.java +++ b/src/main/java/org/springframework/data/neo4j/repository/query/Neo4jQueryMethod.java @@ -15,6 +15,10 @@ */ package org.springframework.data.neo4j.repository.query; +import java.lang.reflect.Method; +import java.util.List; +import java.util.Optional; + import org.springframework.core.MethodParameter; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.data.neo4j.repository.support.CypherdslStatementExecutor; @@ -23,13 +27,10 @@ import org.springframework.data.repository.core.RepositoryMetadata; import org.springframework.data.repository.query.Parameter; import org.springframework.data.repository.query.Parameters; import org.springframework.data.repository.query.QueryMethod; +import org.springframework.data.util.TypeInformation; import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; -import java.lang.reflect.Method; -import java.util.List; -import java.util.Optional; - /** * Neo4j specific implementation of {@link QueryMethod}. It contains a custom implementation of {@link Parameter} which * supports Neo4js specific placeholder as well as a convenient method to return either the parameters index or name @@ -72,7 +73,8 @@ class Neo4jQueryMethod extends QueryMethod { * @param factory must not be {@literal null}. * @param cypherBasedProjection True if this points to a Cypher-DSL based projection. */ - Neo4jQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory, boolean cypherBasedProjection) { + Neo4jQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory, + boolean cypherBasedProjection) { super(method, metadata, factory); Class declaringClass = method.getDeclaringClass(); @@ -108,25 +110,20 @@ class Neo4jQueryMethod extends QueryMethod { } @Override - protected Parameters createParameters(Method method) { - return new Neo4jParameters(method); + protected Parameters createParameters(Method method, TypeInformation domainType) { + return new Neo4jParameters(method, domainType); } static class Neo4jParameters extends Parameters { - Neo4jParameters(Method method) { - super(method); + Neo4jParameters(Method method, TypeInformation domainType) { + super(method, it -> new Neo4jParameter(it, domainType)); } private Neo4jParameters(List originals) { super(originals); } - @Override - protected Neo4jParameter createParameter(MethodParameter parameter) { - return new Neo4jParameter(parameter); - } - @Override protected Neo4jParameters createFrom(List parameters) { return new Neo4jParameters(parameters); @@ -139,12 +136,13 @@ class Neo4jQueryMethod extends QueryMethod { private static final String POSITION_PARAMETER_TEMPLATE = "$%d"; /** - * Creates a new {@link Parameter} for the given {@link MethodParameter}. + * Creates a new {@link Parameter} for the given {@link MethodParameter} and {@link TypeInformation}. * * @param parameter must not be {@literal null}. + * @param domainType must not be {@literal null}. */ - Neo4jParameter(MethodParameter parameter) { - super(parameter); + Neo4jParameter(MethodParameter parameter, TypeInformation domainType) { + super(parameter, domainType); } public String getPlaceholder() {