21
21
import org .springframework .data .domain .PageImpl ;
22
22
import org .springframework .data .domain .Pageable ;
23
23
import org .springframework .data .domain .Sort ;
24
+ import org .springframework .data .expression .ValueEvaluationContext ;
25
+ import org .springframework .data .expression .ValueEvaluationContextProvider ;
24
26
import org .springframework .data .keyvalue .core .IterableConverter ;
25
27
import org .springframework .data .keyvalue .core .KeyValueOperations ;
26
28
import org .springframework .data .keyvalue .core .SpelCriteria ;
27
29
import org .springframework .data .keyvalue .core .query .KeyValueQuery ;
28
30
import org .springframework .data .repository .query .ParameterAccessor ;
29
31
import org .springframework .data .repository .query .ParametersParameterAccessor ;
30
32
import org .springframework .data .repository .query .QueryMethod ;
31
- import org .springframework .data .repository .query .QueryMethodEvaluationContextProvider ;
32
33
import org .springframework .data .repository .query .RepositoryQuery ;
33
34
import org .springframework .data .repository .query .ResultProcessor ;
35
+ import org .springframework .data .repository .query .ValueExpressionDelegate ;
34
36
import org .springframework .data .repository .query .parser .AbstractQueryCreator ;
35
37
import org .springframework .data .repository .query .parser .PartTree ;
36
38
import org .springframework .data .spel .EvaluationContextProvider ;
37
39
import org .springframework .data .util .Lazy ;
38
- import org .springframework .expression .EvaluationContext ;
39
40
import org .springframework .expression .spel .standard .SpelExpression ;
40
41
import org .springframework .lang .Nullable ;
41
42
import org .springframework .util .Assert ;
@@ -54,22 +55,23 @@ public class KeyValuePartTreeQuery implements RepositoryQuery {
54
55
private final Lazy <PartTree > partTree ;
55
56
private final QueryMethod queryMethod ;
56
57
private final KeyValueOperations keyValueOperations ;
57
- private final QueryMethodEvaluationContextProvider evaluationContextProvider ;
58
+ private final ValueExpressionDelegate valueExpressionDelegate ;
58
59
private final QueryCreatorFactory <AbstractQueryCreator <KeyValueQuery <?>, ?>> queryCreatorFactory ;
60
+ private final ValueEvaluationContextProvider evaluationContextProvider ;
59
61
60
62
/**
61
63
* Creates a new {@link KeyValuePartTreeQuery} for the given {@link QueryMethod}, {@link EvaluationContextProvider},
62
64
* {@link KeyValueOperations} and query creator type.
63
65
*
64
66
* @param queryMethod must not be {@literal null}.
65
- * @param evaluationContextProvider must not be {@literal null}.
67
+ * @param valueExpressionDelegate must not be {@literal null}.
66
68
* @param keyValueOperations must not be {@literal null}.
67
69
* @param queryCreator must not be {@literal null}.
68
70
*/
69
- public KeyValuePartTreeQuery (QueryMethod queryMethod , QueryMethodEvaluationContextProvider evaluationContextProvider ,
71
+ public KeyValuePartTreeQuery (QueryMethod queryMethod , ValueExpressionDelegate valueExpressionDelegate ,
70
72
KeyValueOperations keyValueOperations , Class <? extends AbstractQueryCreator <?, ?>> queryCreator ) {
71
73
72
- this (queryMethod , evaluationContextProvider , keyValueOperations ,
74
+ this (queryMethod , valueExpressionDelegate , keyValueOperations ,
73
75
new ConstructorCachingQueryCreatorFactory (queryCreator ));
74
76
}
75
77
@@ -79,26 +81,27 @@ public KeyValuePartTreeQuery(QueryMethod queryMethod, QueryMethodEvaluationConte
79
81
* in charge of altering the query.
80
82
*
81
83
* @param queryMethod must not be {@literal null}.
82
- * @param evaluationContextProvider must not be {@literal null}.
84
+ * @param valueExpressionDelegate must not be {@literal null}.
83
85
* @param keyValueOperations must not be {@literal null}.
84
86
* @param queryCreatorFactory must not be {@literal null}.
85
87
* @since 2.0
86
88
*/
87
- public KeyValuePartTreeQuery (QueryMethod queryMethod , QueryMethodEvaluationContextProvider evaluationContextProvider ,
89
+ public KeyValuePartTreeQuery (QueryMethod queryMethod , ValueExpressionDelegate valueExpressionDelegate ,
88
90
KeyValueOperations keyValueOperations ,
89
91
QueryCreatorFactory <AbstractQueryCreator <KeyValueQuery <?>, ?>> queryCreatorFactory ) {
90
92
91
93
Assert .notNull (queryMethod , "Query method must not be null" );
92
- Assert .notNull (evaluationContextProvider , "EvaluationContextProvider must not be null" );
94
+ Assert .notNull (valueExpressionDelegate , "ValueExpressionDelegate must not be null" );
93
95
Assert .notNull (keyValueOperations , "KeyValueOperations must not be null" );
94
96
Assert .notNull (queryCreatorFactory , "QueryCreatorFactory type must not be null" );
95
97
96
98
this .partTree = Lazy
97
99
.of (() -> new PartTree (queryMethod .getName (), queryMethod .getEntityInformation ().getJavaType ()));
98
100
this .queryMethod = queryMethod ;
99
101
this .keyValueOperations = keyValueOperations ;
100
- this .evaluationContextProvider = evaluationContextProvider ;
102
+ this .valueExpressionDelegate = valueExpressionDelegate ;
101
103
this .queryCreatorFactory = queryCreatorFactory ;
104
+ this .evaluationContextProvider = valueExpressionDelegate .createValueContextProvider (queryMethod .getParameters ());
102
105
}
103
106
104
107
@ Override
@@ -160,9 +163,8 @@ protected KeyValueQuery<?> prepareQuery(KeyValueQuery<?> instance, Object[] para
160
163
if (criteria instanceof SpelCriteria || criteria instanceof SpelExpression ) {
161
164
162
165
SpelExpression spelExpression = getSpelExpression (criteria );
163
- EvaluationContext context = this .evaluationContextProvider .getEvaluationContext (getQueryMethod ().getParameters (),
164
- parameters );
165
- criteria = new SpelCriteria (spelExpression , context );
166
+ ValueEvaluationContext context = this .evaluationContextProvider .getEvaluationContext (parameters );
167
+ criteria = new SpelCriteria (spelExpression , context .getRequiredEvaluationContext ());
166
168
}
167
169
168
170
KeyValueQuery <?> query = new KeyValueQuery (criteria );
0 commit comments