From de1d6a1c72fc12e1fdbc60bee19acc7b167d4415 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Wed, 9 Apr 2025 12:04:23 +0200 Subject: [PATCH] Adopt to deprecated `QueryMethod` constructor. Closes #3833 --- .../jpa/repository/query/JpaQueryMethod.java | 31 +++++++++++++------ ...BindableJpaParametersIntegrationTests.java | 15 +-------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryMethod.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryMethod.java index 97b6390d2..39202fcb7 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryMethod.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryMethod.java @@ -25,6 +25,7 @@ import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.Set; +import java.util.function.Function; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.AnnotationUtils; @@ -91,15 +92,30 @@ public class JpaQueryMethod extends QueryMethod { /** * Creates a {@link JpaQueryMethod}. * - * @param method must not be {@literal null} - * @param metadata must not be {@literal null} - * @param factory must not be {@literal null} - * @param extractor must not be {@literal null} + * @param method must not be {@literal null}. + * @param metadata must not be {@literal null}. + * @param factory must not be {@literal null}. + * @param extractor must not be {@literal null}. */ public JpaQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory, QueryExtractor extractor) { + this(method, metadata, factory, extractor, JpaParameters::new); + } - super(method, metadata, factory); + /** + * Creates a {@link JpaQueryMethod}. + * + * @param method must not be {@literal null}. + * @param metadata must not be {@literal null}. + * @param factory must not be {@literal null}. + * @param extractor must not be {@literal null}. + * @param parametersFunction function to obtain {@link JpaParameters}, must not be {@literal null}. + * @since 3.5 + */ + public JpaQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory, + QueryExtractor extractor, Function parametersFunction) { + + super(method, metadata, factory, parametersFunction); Assert.notNull(method, "Method must not be null"); Assert.notNull(extractor, "Query extractor must not be null"); @@ -413,11 +429,6 @@ public class JpaQueryMethod extends QueryMethod { return targetType.cast(AnnotationUtils.getValue(annotation, attribute)); } - @Override - protected Parameters createParameters(ParametersSource parametersSource) { - return new JpaParameters(parametersSource); - } - @Override public JpaParameters getParameters() { return (JpaParameters) super.getParameters(); diff --git a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/CustomNonBindableJpaParametersIntegrationTests.java b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/CustomNonBindableJpaParametersIntegrationTests.java index 50ca107e9..bc850052d 100644 --- a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/CustomNonBindableJpaParametersIntegrationTests.java +++ b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/CustomNonBindableJpaParametersIntegrationTests.java @@ -92,19 +92,6 @@ class CustomNonBindableJpaParametersIntegrationTests { } - private static class NonBindableAwareJpaQueryMethod extends JpaQueryMethod { - - NonBindableAwareJpaQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory, - QueryExtractor extractor) { - super(method, metadata, factory, extractor); - } - - @Override - protected JpaParameters createParameters(ParametersSource source) { - return new NonBindableAwareJpaParameters(source); - } - } - private static class NonBindableAwareJpaQueryMethodFactory implements JpaQueryMethodFactory { private final QueryExtractor extractor; @@ -115,7 +102,7 @@ class CustomNonBindableJpaParametersIntegrationTests { @Override public JpaQueryMethod build(Method method, RepositoryMetadata metadata, ProjectionFactory factory) { - return new NonBindableAwareJpaQueryMethod(method, metadata, factory, extractor); + return new JpaQueryMethod(method, metadata, factory, extractor, NonBindableAwareJpaParameters::new); } }