Remove deprecated methods.

See #2996
Closes #2995
This commit is contained in:
Mark Paluch
2023-12-08 11:03:47 +01:00
parent bd05ed1dda
commit d7732182ee
6 changed files with 17 additions and 67 deletions

View File

@@ -15,27 +15,16 @@
*/
package org.springframework.data.repository.query;
import java.lang.reflect.Method;
import java.util.List;
/**
* Default implementation of {@link Parameters}.
*
* @author Oliver Gierke
* @author Mark Paluch
*/
public final class DefaultParameters extends Parameters<DefaultParameters, Parameter> {
/**
* Creates a new {@link DefaultParameters} instance from the given {@link Method}.
*
* @param method must not be {@literal null}.
* @deprecated since 3.1, use {@link #DefaultParameters(ParametersSource)} instead.
*/
@Deprecated(since = "3.1", forRemoval = true)
public DefaultParameters(Method method) {
super(method);
}
/**
* Creates a new {@link DefaultParameters} instance from the given {@link ParametersSource}.
*

View File

@@ -64,18 +64,6 @@ public abstract class Parameters<S extends Parameters<S, T>, T extends Parameter
private int dynamicProjectionIndex;
/**
* Creates a new instance of {@link Parameters}.
*
* @param method must not be {@literal null}.
* @deprecated since 3.1, use {@link #Parameters(Method, Function)} instead.
*/
@SuppressWarnings("null")
@Deprecated(since = "3.1", forRemoval = true)
public Parameters(Method method) {
this(method, null);
}
/**
* Creates a new {@link Parameters} instance for the given {@link Method} and {@link Function} to create a
* {@link Parameter} instance from a {@link MethodParameter}.
@@ -102,9 +90,9 @@ public abstract class Parameters<S extends Parameters<S, T>, T extends Parameter
Function<MethodParameter, T> parameterFactory) {
Assert.notNull(parametersSource, "ParametersSource must not be null");
Assert.notNull(parameterFactory, "Parameter factory must not be null");
// Factory nullability not enforced yet to support falling back to the deprecated
// createParameter(MethodParameter). Add assertion when the deprecation is removed.
Method method = parametersSource.getMethod();
int parameterCount = method.getParameterCount();
@@ -124,9 +112,7 @@ public abstract class Parameters<S extends Parameters<S, T>, T extends Parameter
methodParameter.initParameterNameDiscovery(PARAMETER_NAME_DISCOVERER);
T parameter = parameterFactory == null //
? createParameter(methodParameter) //
: parameterFactory.apply(methodParameter);
T parameter = parameterFactory.apply(methodParameter);
if (parameter.isSpecialParameter() && parameter.isNamedParameter()) {
throw new IllegalArgumentException(PARAM_ON_SPECIAL);
@@ -213,19 +199,6 @@ public abstract class Parameters<S extends Parameters<S, T>, T extends Parameter
return createFrom(bindables);
}
/**
* Creates a {@link Parameter} instance for the given {@link MethodParameter}.
*
* @param parameter will never be {@literal null}.
* @return
* @deprecated since 3.1, in your extension, call {@link #Parameters(Method, Function)} instead.
*/
@SuppressWarnings("unchecked")
@Deprecated(since = "3.1", forRemoval = true)
protected T createParameter(MethodParameter parameter) {
return (T) new Parameter(parameter);
}
/**
* Returns whether the method the {@link Parameters} was created for contains a {@link ScrollPosition} argument.
*

View File

@@ -85,7 +85,7 @@ public class QueryMethod {
this.method = method;
this.unwrappedReturnType = potentiallyUnwrapReturnTypeFor(metadata, method);
this.metadata = metadata;
this.parameters = createParameters(method);
this.parameters = createParameters(method, metadata.getDomainTypeInformation());
this.domainClass = Lazy.of(() -> {
@@ -165,18 +165,6 @@ public class QueryMethod {
return TypeInformation.of(unwrappedReturnType).isCollectionLike();
}
/**
* Creates a {@link Parameters} instance.
*
* @param method must not be {@literal null}.
* @return must not return {@literal null}.
* @deprecated since 3.1, call or override {@link #createParameters(Method, TypeInformation)} instead.
*/
@Deprecated(since = "3.1", forRemoval = true)
protected Parameters<?, ?> createParameters(Method method) {
return createParameters(method, metadata.getDomainTypeInformation());
}
/**
* Creates a {@link Parameters} instance.
*

View File

@@ -386,7 +386,7 @@ class ExtensionAwareEvaluationContextProviderUnitTests {
private Object evaluateExpression(String expression, Object[] args) {
var parameters = new DefaultParameters(method);
var parameters = new DefaultParameters(ParametersSource.of(method));
var evaluationContext = provider.getEvaluationContext(parameters, args);
return new SpelExpressionParser().parseExpression(expression).getValue(evaluationContext);
}

View File

@@ -37,10 +37,13 @@ class SimpleParameterAccessorUnitTests {
@BeforeEach
void setUp() throws SecurityException, NoSuchMethodException {
parameters = new DefaultParameters(Sample.class.getMethod("sample", String.class));
cursorRequestParameters = new DefaultParameters(Sample.class.getMethod("sample", ScrollPosition.class));
sortParameters = new DefaultParameters(Sample.class.getMethod("sample1", String.class, Sort.class));
pageableParameters = new DefaultParameters(Sample.class.getMethod("sample2", String.class, Pageable.class));
parameters = new DefaultParameters(ParametersSource.of(Sample.class.getMethod("sample", String.class)));
cursorRequestParameters = new DefaultParameters(
ParametersSource.of(Sample.class.getMethod("sample", ScrollPosition.class)));
sortParameters = new DefaultParameters(
ParametersSource.of(Sample.class.getMethod("sample1", String.class, Sort.class)));
pageableParameters = new DefaultParameters(
ParametersSource.of(Sample.class.getMethod("sample2", String.class, Pageable.class)));
}
@Test
@@ -60,8 +63,7 @@ class SimpleParameterAccessorUnitTests {
@Test
void rejectsTooLittleNumberOfArguments() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new ParametersParameterAccessor(parameters, new Object[0]));
assertThatIllegalArgumentException().isThrownBy(() -> new ParametersParameterAccessor(parameters, new Object[0]));
}
@Test
@@ -103,8 +105,7 @@ class SimpleParameterAccessorUnitTests {
void returnsPageableIfAvailable() {
Pageable pageable = PageRequest.of(0, 10);
ParameterAccessor accessor = new ParametersParameterAccessor(pageableParameters,
new Object[] { "test", pageable });
ParameterAccessor accessor = new ParametersParameterAccessor(pageableParameters, new Object[] { "test", pageable });
assertThat(accessor.getPageable()).isEqualTo(pageable);
assertThat(accessor.getSort().isSorted()).isFalse();
@@ -115,8 +116,7 @@ class SimpleParameterAccessorUnitTests {
var sort = Sort.by("foo");
Pageable pageable = PageRequest.of(0, 10, sort);
ParameterAccessor accessor = new ParametersParameterAccessor(pageableParameters,
new Object[] { "test", pageable });
ParameterAccessor accessor = new ParametersParameterAccessor(pageableParameters, new Object[] { "test", pageable });
assertThat(accessor.getPageable()).isEqualTo(pageable);
assertThat(accessor.getSort()).isEqualTo(sort);

View File

@@ -38,7 +38,7 @@ class SpelEvaluatorUnitTests {
SpelExtractor extractor = context.parse("SELECT :#{#value}");
Method method = MyRepository.class.getDeclaredMethod("simpleExpression", String.class);
SpelEvaluator evaluator = new SpelEvaluator(QueryMethodEvaluationContextProvider.DEFAULT,
new DefaultParameters(method), extractor);
new DefaultParameters(ParametersSource.of(method)), extractor);
assertThat(evaluator.getQueryString()).isEqualTo("SELECT :__$synthetic$__1");
assertThat(evaluator.evaluate(new Object[] { "hello" })).containsEntry("__$synthetic$__1", "hello");
@@ -50,7 +50,7 @@ class SpelEvaluatorUnitTests {
SpelExtractor extractor = context.parse("SELECT :#{#value}");
Method method = MyRepository.class.getDeclaredMethod("simpleExpression", String.class);
SpelEvaluator evaluator = new SpelEvaluator(QueryMethodEvaluationContextProvider.DEFAULT,
new DefaultParameters(method), extractor);
new DefaultParameters(ParametersSource.of(method)), extractor);
assertThat(evaluator.getQueryString()).isEqualTo("SELECT :__$synthetic$__1");
assertThat(evaluator.evaluate(new Object[] { null })).containsEntry("__$synthetic$__1", null);