Skip to content

Commit de1d6a1

Browse files
committed
Adopt to deprecated QueryMethod constructor.
Closes #3833
1 parent 4f99584 commit de1d6a1

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryMethod.java

+21-10
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.List;
2626
import java.util.Optional;
2727
import java.util.Set;
28+
import java.util.function.Function;
2829

2930
import org.springframework.core.annotation.AnnotatedElementUtils;
3031
import org.springframework.core.annotation.AnnotationUtils;
@@ -91,15 +92,30 @@ public class JpaQueryMethod extends QueryMethod {
9192
/**
9293
* Creates a {@link JpaQueryMethod}.
9394
*
94-
* @param method must not be {@literal null}
95-
* @param metadata must not be {@literal null}
96-
* @param factory must not be {@literal null}
97-
* @param extractor must not be {@literal null}
95+
* @param method must not be {@literal null}.
96+
* @param metadata must not be {@literal null}.
97+
* @param factory must not be {@literal null}.
98+
* @param extractor must not be {@literal null}.
9899
*/
99100
public JpaQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory,
100101
QueryExtractor extractor) {
102+
this(method, metadata, factory, extractor, JpaParameters::new);
103+
}
104+
105+
/**
106+
* Creates a {@link JpaQueryMethod}.
107+
*
108+
* @param method must not be {@literal null}.
109+
* @param metadata must not be {@literal null}.
110+
* @param factory must not be {@literal null}.
111+
* @param extractor must not be {@literal null}.
112+
* @param parametersFunction function to obtain {@link JpaParameters}, must not be {@literal null}.
113+
* @since 3.5
114+
*/
115+
public JpaQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory,
116+
QueryExtractor extractor, Function<ParametersSource, JpaParameters> parametersFunction) {
101117

102-
super(method, metadata, factory);
118+
super(method, metadata, factory, parametersFunction);
103119

104120
Assert.notNull(method, "Method must not be null");
105121
Assert.notNull(extractor, "Query extractor must not be null");
@@ -413,11 +429,6 @@ private <T> T getMergedOrDefaultAnnotationValue(String attribute, Class annotati
413429
return targetType.cast(AnnotationUtils.getValue(annotation, attribute));
414430
}
415431

416-
@Override
417-
protected Parameters<?, ?> createParameters(ParametersSource parametersSource) {
418-
return new JpaParameters(parametersSource);
419-
}
420-
421432
@Override
422433
public JpaParameters getParameters() {
423434
return (JpaParameters) super.getParameters();

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/CustomNonBindableJpaParametersIntegrationTests.java

+1-14
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,6 @@ private static class NonBindableAwareJpaParameters extends JpaParameters {
9292

9393
}
9494

95-
private static class NonBindableAwareJpaQueryMethod extends JpaQueryMethod {
96-
97-
NonBindableAwareJpaQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory,
98-
QueryExtractor extractor) {
99-
super(method, metadata, factory, extractor);
100-
}
101-
102-
@Override
103-
protected JpaParameters createParameters(ParametersSource source) {
104-
return new NonBindableAwareJpaParameters(source);
105-
}
106-
}
107-
10895
private static class NonBindableAwareJpaQueryMethodFactory implements JpaQueryMethodFactory {
10996

11097
private final QueryExtractor extractor;
@@ -115,7 +102,7 @@ private NonBindableAwareJpaQueryMethodFactory(QueryExtractor extractor) {
115102

116103
@Override
117104
public JpaQueryMethod build(Method method, RepositoryMetadata metadata, ProjectionFactory factory) {
118-
return new NonBindableAwareJpaQueryMethod(method, metadata, factory, extractor);
105+
return new JpaQueryMethod(method, metadata, factory, extractor, NonBindableAwareJpaParameters::new);
119106
}
120107
}
121108

0 commit comments

Comments
 (0)