Skip to content

Commit 1b9e36c

Browse files
committed
Accept Function to create Parameters in QueryMethod.
We now no longer rely on overriding a method in the QueryMethod constructor but accept a Function to create Parameters. Closes spring-projects#3263
1 parent f4e9581 commit 1b9e36c

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

Diff for: src/main/java/org/springframework/data/repository/query/QueryMethod.java

+25-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.lang.reflect.Method;
1919
import java.util.Collections;
2020
import java.util.Set;
21+
import java.util.function.Function;
2122
import java.util.function.Predicate;
2223
import java.util.stream.Stream;
2324

@@ -38,6 +39,7 @@
3839
import org.springframework.data.util.ReactiveWrappers;
3940
import org.springframework.data.util.ReflectionUtils;
4041
import org.springframework.data.util.TypeInformation;
42+
import org.springframework.lang.Nullable;
4143
import org.springframework.util.Assert;
4244

4345
/**
@@ -68,8 +70,26 @@ public class QueryMethod {
6870
* @param method must not be {@literal null}.
6971
* @param metadata must not be {@literal null}.
7072
* @param factory must not be {@literal null}.
73+
* @deprecated since 3.5, use {@link QueryMethod#QueryMethod(Method, RepositoryMetadata, ProjectionFactory, Function)}
74+
* instead.
7175
*/
76+
@Deprecated(since = "3.5")
7277
public QueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory) {
78+
this(method, metadata, factory, null);
79+
}
80+
81+
/**
82+
* Creates a new {@link QueryMethod} from the given parameters. Looks up the correct query to use for following
83+
* invocations of the method given.
84+
*
85+
* @param method must not be {@literal null}.
86+
* @param metadata must not be {@literal null}.
87+
* @param factory must not be {@literal null}.
88+
* @param parametersFunction must not be {@literal null}.
89+
* @since 3.5
90+
*/
91+
public QueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory,
92+
@Nullable Function<ParametersSource, ? extends Parameters<?, ?>> parametersFunction) {
7393

7494
Assert.notNull(method, "Method must not be null");
7595
Assert.notNull(metadata, "Repository metadata must not be null");
@@ -86,7 +106,8 @@ public QueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory
86106
this.method = method;
87107
this.unwrappedReturnType = potentiallyUnwrapReturnTypeFor(metadata, method);
88108
this.metadata = metadata;
89-
this.parameters = createParameters(method, metadata.getDomainTypeInformation());
109+
this.parameters = parametersFunction == null ? createParameters(method, metadata.getDomainTypeInformation())
110+
: parametersFunction.apply(ParametersSource.of(metadata, method));
90111

91112
this.domainClass = Lazy.of(() -> {
92113

@@ -186,7 +207,10 @@ private boolean calculateIsCollectionQuery() {
186207
* @param parametersSource must not be {@literal null}.
187208
* @return must not return {@literal null}.
188209
* @since 3.2.1
210+
* @deprecated since 3.5, use {@link QueryMethod#QueryMethod(Method, RepositoryMetadata, ProjectionFactory, Function)}
211+
* instead.
189212
*/
213+
@Deprecated(since = "3.5")
190214
protected Parameters<?, ?> createParameters(ParametersSource parametersSource) {
191215
return new DefaultParameters(parametersSource);
192216
}

0 commit comments

Comments
 (0)