From 71b92bc3f91b6ff0da2a612d376031326392a895 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Mon, 7 Dec 2020 11:26:58 +0100 Subject: [PATCH] =?UTF-8?q?DATACMNS-1838=20-=20Accept=20ExpressionDependen?= =?UTF-8?q?cies=20in=20BasicPersistentEntity.getEvaluationContext(?= =?UTF-8?q?=E2=80=A6).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow obtaining an EvaluationContext with a reduced set of extensions that are required for ExpressionDependencies instead of initializing all extensions. --- .../mapping/model/BasicPersistentEntity.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java b/src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java index 308d3d053..716e005ed 100644 --- a/src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java +++ b/src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java @@ -35,6 +35,7 @@ import org.springframework.data.annotation.TypeAlias; import org.springframework.data.domain.Persistable; import org.springframework.data.mapping.*; import org.springframework.data.spel.EvaluationContextProvider; +import org.springframework.data.spel.ExpressionDependencies; import org.springframework.data.support.IsNewStrategy; import org.springframework.data.support.PersistableIsNewStrategy; import org.springframework.data.util.Lazy; @@ -537,10 +538,29 @@ public class BasicPersistentEntity> implement }; } + /** + * Obtain a {@link EvaluationContext} for a {@code rootObject}. + * + * @param rootObject must not be {@literal null}. + * @return the evaluation context including all potential extensions. + * @since 2.1 + */ protected EvaluationContext getEvaluationContext(Object rootObject) { return evaluationContextProvider.getEvaluationContext(rootObject); } + /** + * Obtain a {@link EvaluationContext} for a {@code rootObject} given {@link ExpressionDependencies}. + * + * @param rootObject must not be {@literal null}. + * @param dependencies must not be {@literal null}. + * @return the evaluation context with extensions loaded that satisfy {@link ExpressionDependencies}. + * @since 2.5 + */ + protected EvaluationContext getEvaluationContext(Object rootObject, ExpressionDependencies dependencies) { + return evaluationContextProvider.getEvaluationContext(rootObject, dependencies); + } + /** * Returns the default {@link IsNewStrategy} to be used. Will be a {@link PersistentEntityIsNewStrategy} by default. * Note, that this strategy only gets used if the entity doesn't implement {@link Persistable} as this indicates the