1818import java .lang .reflect .Method ;
1919import java .util .Collections ;
2020import java .util .Set ;
21+ import java .util .function .Function ;
2122import java .util .function .Predicate ;
2223import java .util .stream .Stream ;
2324
3839import org .springframework .data .util .ReactiveWrappers ;
3940import org .springframework .data .util .ReflectionUtils ;
4041import org .springframework .data .util .TypeInformation ;
42+ import org .springframework .lang .Nullable ;
4143import 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