2626import org .reactivestreams .Publisher ;
2727
2828import 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 ;
2933import org .springframework .data .expression .ValueExpression ;
34+ import org .springframework .data .expression .ValueExpressionParser ;
3035import org .springframework .data .mapping .model .EntityInstantiators ;
3136import org .springframework .data .mapping .model .SpELExpressionEvaluator ;
3237import org .springframework .data .mapping .model .ValueExpressionEvaluator ;
5055import org .springframework .data .mongodb .util .json .ParameterBindingContext ;
5156import org .springframework .data .mongodb .util .json .ParameterBindingDocumentCodec ;
5257import 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 ;
5460import org .springframework .data .repository .query .RepositoryQuery ;
5561import org .springframework .data .repository .query .ResultProcessor ;
56- import org .springframework .data .repository .query .ValueExpressionSupportHolder ;
62+ import org .springframework .data .repository .query .ValueExpressionDelegate ;
5763import org .springframework .data .spel .ExpressionDependencies ;
5864import org .springframework .data .util .TypeInformation ;
65+ import org .springframework .expression .ExpressionParser ;
5966import org .springframework .expression .spel .standard .SpelExpressionParser ;
6067import org .springframework .lang .Nullable ;
6168import org .springframework .util .Assert ;
@@ -80,36 +87,72 @@ public abstract class AbstractReactiveMongoQuery implements RepositoryQuery {
8087 private final EntityInstantiators instantiators ;
8188 private final FindWithProjection <?> findOperationWithProjection ;
8289 private final ReactiveUpdate <?> updateOps ;
83- private final ValueExpressionSupportHolder expressionSupportHolder ;
84- private final ReactiveQueryMethodValueEvaluationContextProvider evaluationContextProvider ;
90+ private final ValueExpressionDelegate valueExpressionDelegate ;
91+ private final ReactiveValueEvaluationContextProvider valueEvaluationContextProvider ;
8592
8693 /**
8794 * Creates a new {@link AbstractReactiveMongoQuery} from the given {@link MongoQueryMethod} and
8895 * {@link MongoOperations}.
8996 *
9097 * @param method must not be {@literal null}.
9198 * @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}
93102 */
103+ @ Deprecated (since = "4.4.0" )
94104 public AbstractReactiveMongoQuery (ReactiveMongoQueryMethod method , ReactiveMongoOperations operations ,
95- ValueExpressionSupportHolder expressionSupportHolder ) {
105+ ExpressionParser expressionParser , ReactiveQueryMethodEvaluationContextProvider evaluationContextProvider ) {
96106
97107 Assert .notNull (method , "MongoQueryMethod must not be null" );
98108 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" );
100111
101112 this .method = method ;
102113 this .operations = operations ;
103114 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 ));
107116
108117 MongoEntityMetadata <?> metadata = method .getEntityInformation ();
109118 Class <?> type = metadata .getCollectionEntity ().getType ();
110119
111120 this .findOperationWithProjection = operations .query (type );
112121 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 ;
113156 }
114157
115158 @ Override
@@ -390,7 +433,7 @@ private Mono<Tuple2<ValueExpressionEvaluator, ParameterBindingDocumentCodec>> ex
390433 MongoParameterAccessor accessor , ParameterBindingDocumentCodec codec ) {
391434
392435 ExpressionDependencies dependencies = codec .captureExpressionDependencies (source , accessor ::getBindableValue ,
393- expressionSupportHolder .getValueExpressionParser ());
436+ valueExpressionDelegate .getValueExpressionParser ());
394437 return getValueExpressionEvaluatorLater (dependencies , accessor ).zipWith (Mono .just (codec ));
395438 }
396439
@@ -426,8 +469,7 @@ protected Mono<ParameterBindingDocumentCodec> getParameterBindingCodec() {
426469 @ Deprecated (since = "4.3" )
427470 protected Mono <SpELExpressionEvaluator > getSpelEvaluatorFor (ExpressionDependencies dependencies ,
428471 MongoParameterAccessor accessor ) {
429-
430- return evaluationContextProvider .getEvaluationContextLater (accessor .getValues (), dependencies )
472+ return valueEvaluationContextProvider .getEvaluationContextLater (accessor .getValues (), dependencies )
431473 .map (evaluationContext -> (SpELExpressionEvaluator ) new DefaultSpELExpressionEvaluator (
432474 new SpelExpressionParser (), evaluationContext .getEvaluationContext ()))
433475 .defaultIfEmpty (DefaultSpELExpressionEvaluator .unsupported ());
@@ -445,10 +487,10 @@ ValueExpressionEvaluator getValueExpressionEvaluator(MongoParameterAccessor acce
445487
446488 @ Override
447489 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 );
452494 }
453495 };
454496 }
@@ -465,19 +507,19 @@ public <T> T evaluate(String expressionString) {
465507 protected Mono <ValueExpressionEvaluator > getValueExpressionEvaluatorLater (ExpressionDependencies dependencies ,
466508 MongoParameterAccessor accessor ) {
467509
468- return evaluationContextProvider .getEvaluationContextLater (accessor .getValues (), dependencies )
469- .map (evaluationContext -> {
510+ return valueEvaluationContextProvider .getEvaluationContextLater (accessor .getValues (), dependencies )
511+ .map (evaluationContext -> {
470512
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 ) {
474516
475- ValueExpression expression = expressionSupportHolder .parse (expressionString );
517+ ValueExpression expression = valueExpressionDelegate .parse (expressionString );
476518
477- return (T ) expression .evaluate (evaluationContext );
478- }
479- };
480- });
519+ return (T ) expression .evaluate (evaluationContext );
520+ }
521+ };
522+ });
481523 }
482524
483525 /**
0 commit comments