2121
2222import org .apache .commons .logging .Log ;
2323import org .apache .commons .logging .LogFactory ;
24+
25+ import org .springframework .core .env .StandardEnvironment ;
2426import org .springframework .data .jpa .repository .Query ;
2527import org .springframework .data .jpa .repository .QueryRewriter ;
2628import org .springframework .data .projection .ProjectionFactory ;
3032import org .springframework .data .repository .query .QueryLookupStrategy .Key ;
3133import org .springframework .data .repository .query .QueryMethod ;
3234import org .springframework .data .repository .query .QueryMethodEvaluationContextProvider ;
35+ import org .springframework .data .repository .query .QueryMethodValueEvaluationContextAccessor ;
3336import org .springframework .data .repository .query .RepositoryQuery ;
37+ import org .springframework .data .repository .query .ValueExpressionDelegate ;
3438import org .springframework .lang .Nullable ;
3539import org .springframework .util .Assert ;
3640import org .springframework .util .StringUtils ;
@@ -135,7 +139,7 @@ protected RepositoryQuery resolveQuery(JpaQueryMethod method, QueryRewriter quer
135139 */
136140 private static class DeclaredQueryLookupStrategy extends AbstractQueryLookupStrategy {
137141
138- private final QueryMethodEvaluationContextProvider evaluationContextProvider ;
142+ private final ValueExpressionDelegate valueExpressionDelegate ;
139143
140144 /**
141145 * Creates a new {@link DeclaredQueryLookupStrategy}.
@@ -145,11 +149,11 @@ private static class DeclaredQueryLookupStrategy extends AbstractQueryLookupStra
145149 * @param evaluationContextProvider must not be {@literal null}.
146150 */
147151 public DeclaredQueryLookupStrategy (EntityManager em , JpaQueryMethodFactory queryMethodFactory ,
148- QueryMethodEvaluationContextProvider evaluationContextProvider , QueryRewriterProvider queryRewriterProvider ) {
152+ ValueExpressionDelegate delegate , QueryRewriterProvider queryRewriterProvider ) {
149153
150154 super (em , queryMethodFactory , queryRewriterProvider );
151155
152- this .evaluationContextProvider = evaluationContextProvider ;
156+ this .valueExpressionDelegate = delegate ;
153157 }
154158
155159 @ Override
@@ -168,13 +172,13 @@ protected RepositoryQuery resolveQuery(JpaQueryMethod method, QueryRewriter quer
168172 }
169173
170174 return JpaQueryFactory .INSTANCE .fromMethodWithQueryString (method , em , method .getRequiredAnnotatedQuery (),
171- getCountQuery (method , namedQueries , em ), queryRewriter , evaluationContextProvider );
175+ getCountQuery (method , namedQueries , em ), queryRewriter , valueExpressionDelegate );
172176 }
173177
174178 String name = method .getNamedQueryName ();
175179 if (namedQueries .hasQuery (name )) {
176180 return JpaQueryFactory .INSTANCE .fromMethodWithQueryString (method , em , namedQueries .getQuery (name ),
177- getCountQuery (method , namedQueries , em ), queryRewriter , evaluationContextProvider );
181+ getCountQuery (method , namedQueries , em ), queryRewriter , valueExpressionDelegate );
178182 }
179183
180184 RepositoryQuery query = NamedQuery .lookupFrom (method , em );
@@ -267,28 +271,47 @@ protected RepositoryQuery resolveQuery(JpaQueryMethod method, QueryRewriter quer
267271 * @param key may be {@literal null}.
268272 * @param evaluationContextProvider must not be {@literal null}.
269273 * @param escape must not be {@literal null}.
274+ * @deprecated since 3.4, use
275+ * {@link #create(EntityManager, JpaQueryMethodFactory, Key, ValueExpressionDelegate, QueryRewriterProvider, EscapeCharacter)}
276+ * instead.
270277 */
278+ @ Deprecated (since = "3.4" )
271279 public static QueryLookupStrategy create (EntityManager em , JpaQueryMethodFactory queryMethodFactory ,
272280 @ Nullable Key key , QueryMethodEvaluationContextProvider evaluationContextProvider ,
273281 QueryRewriterProvider queryRewriterProvider , EscapeCharacter escape ) {
282+ return create (em , queryMethodFactory , key ,
283+ new ValueExpressionDelegate (new QueryMethodValueEvaluationContextAccessor (new StandardEnvironment (),
284+ evaluationContextProvider .getEvaluationContextProvider ()), ValueExpressionDelegate .create ()),
285+ queryRewriterProvider , escape );
286+ }
287+
288+ /**
289+ * Creates a {@link QueryLookupStrategy} for the given {@link EntityManager} and {@link Key}.
290+ *
291+ * @param em must not be {@literal null}.
292+ * @param queryMethodFactory must not be {@literal null}.
293+ * @param key may be {@literal null}.
294+ * @param delegate must not be {@literal null}.
295+ * @param queryRewriterProvider must not be {@literal null}.
296+ * @param escape must not be {@literal null}.
297+ */
298+ public static QueryLookupStrategy create (EntityManager em , JpaQueryMethodFactory queryMethodFactory ,
299+ @ Nullable Key key , ValueExpressionDelegate delegate , QueryRewriterProvider queryRewriterProvider ,
300+ EscapeCharacter escape ) {
274301
275302 Assert .notNull (em , "EntityManager must not be null" );
276- Assert .notNull (evaluationContextProvider , "EvaluationContextProvider must not be null" );
277-
278- switch (key != null ? key : Key .CREATE_IF_NOT_FOUND ) {
279- case CREATE :
280- return new CreateQueryLookupStrategy (em , queryMethodFactory , queryRewriterProvider , escape );
281- case USE_DECLARED_QUERY :
282- return new DeclaredQueryLookupStrategy (em , queryMethodFactory , evaluationContextProvider ,
283- queryRewriterProvider );
284- case CREATE_IF_NOT_FOUND :
285- return new CreateIfNotFoundQueryLookupStrategy (em , queryMethodFactory ,
286- new CreateQueryLookupStrategy (em , queryMethodFactory , queryRewriterProvider , escape ),
287- new DeclaredQueryLookupStrategy (em , queryMethodFactory , evaluationContextProvider , queryRewriterProvider ),
288- queryRewriterProvider );
289- default :
290- throw new IllegalArgumentException (String .format ("Unsupported query lookup strategy %s" , key ));
291- }
303+ Assert .notNull (delegate , "ValueExpressionDelegate must not be null" );
304+
305+ return switch (key != null ? key : Key .CREATE_IF_NOT_FOUND ) {
306+ case CREATE -> new CreateQueryLookupStrategy (em , queryMethodFactory , queryRewriterProvider , escape );
307+ case USE_DECLARED_QUERY ->
308+ new DeclaredQueryLookupStrategy (em , queryMethodFactory , delegate , queryRewriterProvider );
309+ case CREATE_IF_NOT_FOUND -> new CreateIfNotFoundQueryLookupStrategy (em , queryMethodFactory ,
310+ new CreateQueryLookupStrategy (em , queryMethodFactory , queryRewriterProvider , escape ),
311+ new DeclaredQueryLookupStrategy (em , queryMethodFactory , delegate , queryRewriterProvider ),
312+ queryRewriterProvider );
313+ default -> throw new IllegalArgumentException (String .format ("Unsupported query lookup strategy %s" , key ));
314+ };
292315 }
293316
294317 /**
0 commit comments