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
This commit is contained in:
Mark Paluch
2023-02-16 08:46:29 +01:00
parent 4a2282c584
commit e86cc2f029

View File

@@ -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<Neo4jParameters, Neo4jParameter> createParameters(Method method) {
return new Neo4jParameters(method);
protected Parameters<Neo4jParameters, Neo4jParameter> createParameters(Method method, TypeInformation<?> domainType) {
return new Neo4jParameters(method, domainType);
}
static class Neo4jParameters extends Parameters<Neo4jParameters, Neo4jParameter> {
Neo4jParameters(Method method) {
super(method);
Neo4jParameters(Method method, TypeInformation<?> domainType) {
super(method, it -> new Neo4jParameter(it, domainType));
}
private Neo4jParameters(List<Neo4jParameter> originals) {
super(originals);
}
@Override
protected Neo4jParameter createParameter(MethodParameter parameter) {
return new Neo4jParameter(parameter);
}
@Override
protected Neo4jParameters createFrom(List<Neo4jParameter> 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() {