Adopt RelationalParameters and RelationalParameter to reflect the actual parameter type when using generics.

Closes #1691
This commit is contained in:
Mark Paluch
2023-12-08 11:58:59 +01:00
parent eb6303605c
commit cc43be8d02
3 changed files with 17 additions and 21 deletions

View File

@@ -32,6 +32,8 @@ import org.springframework.data.relational.repository.query.RelationalParameters
import org.springframework.data.relational.repository.query.SimpleRelationalEntityMetadata;
import org.springframework.data.repository.core.NamedQueries;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.query.Parameters;
import org.springframework.data.repository.query.ParametersSource;
import org.springframework.data.repository.query.QueryMethod;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.jdbc.core.RowMapper;
@@ -71,8 +73,8 @@ public class JdbcQueryMethod extends QueryMethod {
}
@Override
protected RelationalParameters createParameters(Method method) {
return new RelationalParameters(method);
protected Parameters<?, ?> createParameters(ParametersSource parametersSource) {
return new RelationalParameters(parametersSource);
}
@Override
@@ -246,7 +248,7 @@ public class JdbcQueryMethod extends QueryMethod {
/**
* Looks up the {@link Lock} annotation from the query method.
*
*
* @return the {@link Optional} wrapped {@link Lock} annotation.
*/
Optional<Lock> lookupLockAnnotation() {

View File

@@ -38,10 +38,11 @@ import org.springframework.data.relational.repository.query.RelationalParameters
import org.springframework.data.relational.repository.query.SimpleRelationalEntityMetadata;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.query.Parameter;
import org.springframework.data.repository.query.ParametersSource;
import org.springframework.data.repository.query.QueryMethod;
import org.springframework.data.repository.util.ReactiveWrapperConverters;
import org.springframework.data.util.ReactiveWrappers;
import org.springframework.data.util.Lazy;
import org.springframework.data.util.ReactiveWrappers;
import org.springframework.data.util.ReflectionUtils;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;
@@ -122,12 +123,9 @@ public class R2dbcQueryMethod extends QueryMethod {
this.lock = Optional.ofNullable(AnnotatedElementUtils.findMergedAnnotation(method, Lock.class));
}
/* (non-Javadoc)
* @see org.springframework.data.repository.query.QueryMethod#createParameters(java.lang.reflect.Method)
*/
@Override
protected RelationalParameters createParameters(Method method) {
return new RelationalParameters(method);
protected RelationalParameters createParameters(ParametersSource parametersSource) {
return new RelationalParameters(parametersSource);
}
/* (non-Javadoc)

View File

@@ -15,7 +15,6 @@
*/
package org.springframework.data.relational.repository.query;
import java.lang.reflect.Method;
import java.util.List;
import org.springframework.core.MethodParameter;
@@ -23,6 +22,7 @@ import org.springframework.core.ResolvableType;
import org.springframework.data.relational.repository.query.RelationalParameters.RelationalParameter;
import org.springframework.data.repository.query.Parameter;
import org.springframework.data.repository.query.Parameters;
import org.springframework.data.repository.query.ParametersSource;
import org.springframework.data.util.TypeInformation;
/**
@@ -33,23 +33,19 @@ import org.springframework.data.util.TypeInformation;
public class RelationalParameters extends Parameters<RelationalParameters, RelationalParameter> {
/**
* Creates a new {@link RelationalParameters} instance from the given {@link Method}.
* Creates a new {@link RelationalParameters} instance from the given {@link ParametersSource}.
*
* @param method must not be {@literal null}.
* @param parametersSource must not be {@literal null}.
*/
public RelationalParameters(Method method) {
super(method);
public RelationalParameters(ParametersSource parametersSource) {
super(parametersSource,
methodParameter -> new RelationalParameter(methodParameter, parametersSource.getDomainTypeInformation()));
}
private RelationalParameters(List<RelationalParameter> parameters) {
super(parameters);
}
@Override
protected RelationalParameter createParameter(MethodParameter parameter) {
return new RelationalParameter(parameter);
}
@Override
protected RelationalParameters createFrom(List<RelationalParameter> parameters) {
return new RelationalParameters(parameters);
@@ -70,8 +66,8 @@ public class RelationalParameters extends Parameters<RelationalParameters, Relat
*
* @param parameter must not be {@literal null}.
*/
RelationalParameter(MethodParameter parameter) {
super(parameter);
RelationalParameter(MethodParameter parameter, TypeInformation<?> domainType) {
super(parameter, domainType);
this.parameter = parameter;
}