|
15 | 15 | */
|
16 | 16 | package org.springframework.data.keyvalue.core.mapping;
|
17 | 17 |
|
| 18 | +import org.springframework.data.expression.ValueExpression; |
| 19 | +import org.springframework.data.expression.ValueExpressionParser; |
18 | 20 | import org.springframework.data.mapping.model.BasicPersistentEntity;
|
19 | 21 | import org.springframework.data.util.TypeInformation;
|
20 | 22 | import org.springframework.expression.Expression;
|
21 |
| -import org.springframework.expression.ParserContext; |
22 | 23 | import org.springframework.expression.common.LiteralExpression;
|
23 | 24 | import org.springframework.expression.spel.standard.SpelExpressionParser;
|
24 | 25 | import org.springframework.lang.Nullable;
|
| 26 | +import org.springframework.util.ObjectUtils; |
25 | 27 | import org.springframework.util.StringUtils;
|
26 | 28 |
|
27 | 29 | /**
|
|
35 | 37 | public class BasicKeyValuePersistentEntity<T, P extends KeyValuePersistentProperty<P>>
|
36 | 38 | extends BasicPersistentEntity<T, P> implements KeyValuePersistentEntity<T, P> {
|
37 | 39 |
|
38 |
| - private static final SpelExpressionParser PARSER = new SpelExpressionParser(); |
| 40 | + private static final ValueExpressionParser PARSER = ValueExpressionParser.create(SpelExpressionParser::new); |
39 | 41 |
|
40 |
| - private final @Nullable Expression keyspaceExpression; |
| 42 | + private final @Nullable ValueExpression keyspaceExpression; |
41 | 43 | private final @Nullable String keyspace;
|
42 | 44 |
|
43 | 45 | /**
|
@@ -89,16 +91,16 @@ private BasicKeyValuePersistentEntity(TypeInformation<T> information, @Nullable
|
89 | 91 | * @return the parsed {@link Expression} or {@literal null}.
|
90 | 92 | */
|
91 | 93 | @Nullable
|
92 |
| - private static Expression detectExpression(String potentialExpression) { |
| 94 | + private static ValueExpression detectExpression(String potentialExpression) { |
93 | 95 |
|
94 |
| - Expression expression = PARSER.parseExpression(potentialExpression, ParserContext.TEMPLATE_EXPRESSION); |
95 |
| - return expression instanceof LiteralExpression ? null : expression; |
| 96 | + ValueExpression expression = PARSER.parse(potentialExpression); |
| 97 | + return expression.isLiteral() ? null : expression; |
96 | 98 | }
|
97 | 99 |
|
98 | 100 | @Override
|
99 | 101 | public String getKeySpace() {
|
100 | 102 | return keyspaceExpression == null //
|
101 | 103 | ? keyspace //
|
102 |
| - : keyspaceExpression.getValue(getEvaluationContext(null), String.class); |
| 104 | + : ObjectUtils.nullSafeToString(keyspaceExpression.evaluate(getValueEvaluationContext(null))); |
103 | 105 | }
|
104 | 106 | }
|
0 commit comments