26
26
import org .reactivestreams .Publisher ;
27
27
28
28
import org .springframework .core .convert .converter .Converter ;
29
+ import org .springframework .core .env .StandardEnvironment ;
30
+ import org .springframework .data .expression .ReactiveValueEvaluationContextProvider ;
31
+ import org .springframework .data .expression .ValueEvaluationContext ;
32
+ import org .springframework .data .expression .ValueEvaluationContextProvider ;
29
33
import org .springframework .data .expression .ValueExpression ;
34
+ import org .springframework .data .expression .ValueExpressionParser ;
30
35
import org .springframework .data .mapping .model .EntityInstantiators ;
31
36
import org .springframework .data .mapping .model .SpELExpressionEvaluator ;
32
37
import org .springframework .data .mapping .model .ValueExpressionEvaluator ;
50
55
import org .springframework .data .mongodb .util .json .ParameterBindingContext ;
51
56
import org .springframework .data .mongodb .util .json .ParameterBindingDocumentCodec ;
52
57
import org .springframework .data .repository .query .ParameterAccessor ;
53
- import org .springframework .data .repository .query .ReactiveQueryMethodValueEvaluationContextProvider ;
58
+ import org .springframework .data .repository .query .QueryMethodValueEvaluationContextAccessor ;
59
+ import org .springframework .data .repository .query .ReactiveQueryMethodEvaluationContextProvider ;
54
60
import org .springframework .data .repository .query .RepositoryQuery ;
55
61
import org .springframework .data .repository .query .ResultProcessor ;
56
- import org .springframework .data .repository .query .ValueExpressionSupportHolder ;
62
+ import org .springframework .data .repository .query .ValueExpressionDelegate ;
57
63
import org .springframework .data .spel .ExpressionDependencies ;
58
64
import org .springframework .data .util .TypeInformation ;
65
+ import org .springframework .expression .ExpressionParser ;
59
66
import org .springframework .expression .spel .standard .SpelExpressionParser ;
60
67
import org .springframework .lang .Nullable ;
61
68
import org .springframework .util .Assert ;
@@ -80,36 +87,72 @@ public abstract class AbstractReactiveMongoQuery implements RepositoryQuery {
80
87
private final EntityInstantiators instantiators ;
81
88
private final FindWithProjection <?> findOperationWithProjection ;
82
89
private final ReactiveUpdate <?> updateOps ;
83
- private final ValueExpressionSupportHolder expressionSupportHolder ;
84
- private final ReactiveQueryMethodValueEvaluationContextProvider evaluationContextProvider ;
90
+ private final ValueExpressionDelegate valueExpressionDelegate ;
91
+ private final ReactiveValueEvaluationContextProvider valueEvaluationContextProvider ;
85
92
86
93
/**
87
94
* Creates a new {@link AbstractReactiveMongoQuery} from the given {@link MongoQueryMethod} and
88
95
* {@link MongoOperations}.
89
96
*
90
97
* @param method must not be {@literal null}.
91
98
* @param operations must not be {@literal null}.
92
- * @param expressionSupportHolder must not be {@literal null}.
99
+ * @param expressionParser must not be {@literal null}.
100
+ * @param evaluationContextProvider must not be {@literal null}.
101
+ * @deprecated use the constructor version with {@link ValueExpressionDelegate}
93
102
*/
103
+ @ Deprecated (since = "4.4.0" )
94
104
public AbstractReactiveMongoQuery (ReactiveMongoQueryMethod method , ReactiveMongoOperations operations ,
95
- ValueExpressionSupportHolder expressionSupportHolder ) {
105
+ ExpressionParser expressionParser , ReactiveQueryMethodEvaluationContextProvider evaluationContextProvider ) {
96
106
97
107
Assert .notNull (method , "MongoQueryMethod must not be null" );
98
108
Assert .notNull (operations , "ReactiveMongoOperations must not be null" );
99
- Assert .notNull (expressionSupportHolder , "ValueExpressionSupportHolder must not be null" );
109
+ Assert .notNull (expressionParser , "SpelExpressionParser must not be null" );
110
+ Assert .notNull (evaluationContextProvider , "ReactiveEvaluationContextExtension must not be null" );
100
111
101
112
this .method = method ;
102
113
this .operations = operations ;
103
114
this .instantiators = new EntityInstantiators ();
104
- this .expressionSupportHolder = expressionSupportHolder ;
105
- this .evaluationContextProvider = (ReactiveQueryMethodValueEvaluationContextProvider ) expressionSupportHolder
106
- .createValueContextProvider (method .getParameters ());
115
+ this .valueExpressionDelegate = new ValueExpressionDelegate (new QueryMethodValueEvaluationContextAccessor (new StandardEnvironment (), evaluationContextProvider .getEvaluationContextProvider ()), ValueExpressionParser .create (() -> expressionParser ));
107
116
108
117
MongoEntityMetadata <?> metadata = method .getEntityInformation ();
109
118
Class <?> type = metadata .getCollectionEntity ().getType ();
110
119
111
120
this .findOperationWithProjection = operations .query (type );
112
121
this .updateOps = operations .update (type );
122
+ ValueEvaluationContextProvider valueContextProvider = valueExpressionDelegate .createValueContextProvider (
123
+ method .getParameters ());
124
+ Assert .isInstanceOf (ReactiveValueEvaluationContextProvider .class , valueContextProvider , "ValueEvaluationContextProvider must be reactive" );
125
+ this .valueEvaluationContextProvider = (ReactiveValueEvaluationContextProvider ) valueContextProvider ;
126
+ }
127
+ /**
128
+ * Creates a new {@link AbstractReactiveMongoQuery} from the given {@link MongoQueryMethod} and
129
+ * {@link MongoOperations}.
130
+ *
131
+ * @param method must not be {@literal null}.
132
+ * @param operations must not be {@literal null}.
133
+ * @param delegate must not be {@literal null}.
134
+ */
135
+ public AbstractReactiveMongoQuery (ReactiveMongoQueryMethod method , ReactiveMongoOperations operations ,
136
+ ValueExpressionDelegate delegate ) {
137
+
138
+ Assert .notNull (method , "MongoQueryMethod must not be null" );
139
+ Assert .notNull (operations , "ReactiveMongoOperations must not be null" );
140
+ Assert .notNull (delegate , "ValueExpressionDelegate must not be null" );
141
+
142
+ this .method = method ;
143
+ this .operations = operations ;
144
+ this .instantiators = new EntityInstantiators ();
145
+ this .valueExpressionDelegate = delegate ;
146
+
147
+ MongoEntityMetadata <?> metadata = method .getEntityInformation ();
148
+ Class <?> type = metadata .getCollectionEntity ().getType ();
149
+
150
+ this .findOperationWithProjection = operations .query (type );
151
+ this .updateOps = operations .update (type );
152
+ ValueEvaluationContextProvider valueContextProvider = valueExpressionDelegate .createValueContextProvider (
153
+ method .getParameters ());
154
+ Assert .isInstanceOf (ReactiveValueEvaluationContextProvider .class , valueContextProvider , "ValueEvaluationContextProvider must be reactive" );
155
+ this .valueEvaluationContextProvider = (ReactiveValueEvaluationContextProvider ) valueContextProvider ;
113
156
}
114
157
115
158
@ Override
@@ -390,7 +433,7 @@ private Mono<Tuple2<ValueExpressionEvaluator, ParameterBindingDocumentCodec>> ex
390
433
MongoParameterAccessor accessor , ParameterBindingDocumentCodec codec ) {
391
434
392
435
ExpressionDependencies dependencies = codec .captureExpressionDependencies (source , accessor ::getBindableValue ,
393
- expressionSupportHolder .getValueExpressionParser ());
436
+ valueExpressionDelegate .getValueExpressionParser ());
394
437
return getValueExpressionEvaluatorLater (dependencies , accessor ).zipWith (Mono .just (codec ));
395
438
}
396
439
@@ -426,8 +469,7 @@ protected Mono<ParameterBindingDocumentCodec> getParameterBindingCodec() {
426
469
@ Deprecated (since = "4.3" )
427
470
protected Mono <SpELExpressionEvaluator > getSpelEvaluatorFor (ExpressionDependencies dependencies ,
428
471
MongoParameterAccessor accessor ) {
429
-
430
- return evaluationContextProvider .getEvaluationContextLater (accessor .getValues (), dependencies )
472
+ return valueEvaluationContextProvider .getEvaluationContextLater (accessor .getValues (), dependencies )
431
473
.map (evaluationContext -> (SpELExpressionEvaluator ) new DefaultSpELExpressionEvaluator (
432
474
new SpelExpressionParser (), evaluationContext .getEvaluationContext ()))
433
475
.defaultIfEmpty (DefaultSpELExpressionEvaluator .unsupported ());
@@ -445,10 +487,10 @@ ValueExpressionEvaluator getValueExpressionEvaluator(MongoParameterAccessor acce
445
487
446
488
@ Override
447
489
public <T > T evaluate (String expressionString ) {
448
-
449
- ValueExpression expression = expressionSupportHolder . parse ( expressionString );
450
- return ( T ) expression .evaluate ( evaluationContextProvider . getEvaluationContext ( accessor . getValues (),
451
- expression .getExpressionDependencies ()) );
490
+ ValueExpression expression = valueExpressionDelegate . parse ( expressionString );
491
+ ValueEvaluationContext evaluationContext = valueEvaluationContextProvider . getEvaluationContext ( accessor . getValues (),
492
+ expression .getExpressionDependencies ());
493
+ return ( T ) expression .evaluate ( evaluationContext );
452
494
}
453
495
};
454
496
}
@@ -465,19 +507,19 @@ public <T> T evaluate(String expressionString) {
465
507
protected Mono <ValueExpressionEvaluator > getValueExpressionEvaluatorLater (ExpressionDependencies dependencies ,
466
508
MongoParameterAccessor accessor ) {
467
509
468
- return evaluationContextProvider .getEvaluationContextLater (accessor .getValues (), dependencies )
469
- .map (evaluationContext -> {
510
+ return valueEvaluationContextProvider .getEvaluationContextLater (accessor .getValues (), dependencies )
511
+ .map (evaluationContext -> {
470
512
471
- return new ValueExpressionEvaluator () {
472
- @ Override
473
- public <T > T evaluate (String expressionString ) {
513
+ return new ValueExpressionEvaluator () {
514
+ @ Override
515
+ public <T > T evaluate (String expressionString ) {
474
516
475
- ValueExpression expression = expressionSupportHolder .parse (expressionString );
517
+ ValueExpression expression = valueExpressionDelegate .parse (expressionString );
476
518
477
- return (T ) expression .evaluate (evaluationContext );
478
- }
479
- };
480
- });
519
+ return (T ) expression .evaluate (evaluationContext );
520
+ }
521
+ };
522
+ });
481
523
}
482
524
483
525
/**
0 commit comments