diff --git a/src/main/antora/modules/ROOT/nav.adoc b/src/main/antora/modules/ROOT/nav.adoc index 0f5bc8c..0c9ad24 100644 --- a/src/main/antora/modules/ROOT/nav.adoc +++ b/src/main/antora/modules/ROOT/nav.adoc @@ -7,6 +7,7 @@ ** xref:repositories/definition.adoc[] ** xref:repositories/create-instances.adoc[] ** xref:keyvalue/repository/map-repositories.adoc[] +** xref:keyvalue/value-expressions.adoc[] ** xref:repositories/query-keywords-reference.adoc[] ** xref:repositories/query-return-types-reference.adoc[] diff --git a/src/main/antora/modules/ROOT/pages/keyvalue/template.adoc b/src/main/antora/modules/ROOT/pages/keyvalue/template.adoc index 5e945c3..05306f9 100644 --- a/src/main/antora/modules/ROOT/pages/keyvalue/template.adoc +++ b/src/main/antora/modules/ROOT/pages/keyvalue/template.adoc @@ -56,7 +56,7 @@ template.findAllOf(User.class); <2> <2> Returns only elements of type `User` stored in `persons` keyspace. ==== -TIP: `@KeySpace` supports https://docs.spring.io/spring/docs/{springVersion}/spring-framework-reference/core.html#expressions[SpEL] expressions allowing dynamic keyspace configuration. +TIP: `@KeySpace` supports xref:keyvalue/value-expressions.adoc[Value Expressions] allowing dynamic keyspace configuration. [[key-value.keyspaces-custom]] === Custom KeySpace Annotation diff --git a/src/main/antora/modules/ROOT/pages/keyvalue/value-expressions.adoc b/src/main/antora/modules/ROOT/pages/keyvalue/value-expressions.adoc new file mode 100644 index 0000000..6356a46 --- /dev/null +++ b/src/main/antora/modules/ROOT/pages/keyvalue/value-expressions.adoc @@ -0,0 +1 @@ +include::{commons}@data-commons::page$value-expressions.adoc[] diff --git a/src/main/java/org/springframework/data/keyvalue/annotation/KeySpace.java b/src/main/java/org/springframework/data/keyvalue/annotation/KeySpace.java index 89f200a..043d9ae 100644 --- a/src/main/java/org/springframework/data/keyvalue/annotation/KeySpace.java +++ b/src/main/java/org/springframework/data/keyvalue/annotation/KeySpace.java @@ -27,7 +27,7 @@ import org.springframework.data.annotation.Persistent; /** * Marker interface for methods with {@link Persistent} annotations indicating the presence of a dedicated keyspace the * entity should reside in. If present the value will be picked up for resolving the keyspace. The {@link #value()} - * attribute supports SpEL expressions to dynamically resolve the keyspace based on a per-operation basis. + * attribute supports Value Expressions to dynamically resolve the keyspace based on a per-operation basis. * *
  * @Persistent
diff --git a/src/main/java/org/springframework/data/keyvalue/core/mapping/BasicKeyValuePersistentEntity.java b/src/main/java/org/springframework/data/keyvalue/core/mapping/BasicKeyValuePersistentEntity.java
index d4045fb..93e9fac 100644
--- a/src/main/java/org/springframework/data/keyvalue/core/mapping/BasicKeyValuePersistentEntity.java
+++ b/src/main/java/org/springframework/data/keyvalue/core/mapping/BasicKeyValuePersistentEntity.java
@@ -15,13 +15,15 @@
  */
 package org.springframework.data.keyvalue.core.mapping;
 
+import org.springframework.data.expression.ValueExpression;
+import org.springframework.data.expression.ValueExpressionParser;
 import org.springframework.data.mapping.model.BasicPersistentEntity;
 import org.springframework.data.util.TypeInformation;
 import org.springframework.expression.Expression;
-import org.springframework.expression.ParserContext;
 import org.springframework.expression.common.LiteralExpression;
 import org.springframework.expression.spel.standard.SpelExpressionParser;
 import org.springframework.lang.Nullable;
+import org.springframework.util.ObjectUtils;
 import org.springframework.util.StringUtils;
 
 /**
@@ -35,9 +37,9 @@ import org.springframework.util.StringUtils;
 public class BasicKeyValuePersistentEntity>
 		extends BasicPersistentEntity implements KeyValuePersistentEntity {
 
-	private static final SpelExpressionParser PARSER = new SpelExpressionParser();
+	private static final ValueExpressionParser PARSER = ValueExpressionParser.create(SpelExpressionParser::new);
 
-	private final @Nullable Expression keyspaceExpression;
+	private final @Nullable ValueExpression keyspaceExpression;
 	private final @Nullable String keyspace;
 
 	/**
@@ -89,16 +91,16 @@ public class BasicKeyValuePersistentEntity persistentEntity = mappingContext.getPersistentEntity(ExpressionEntity.class);
 		persistentEntity.setEvaluationContextProvider(
 				new ExtensionAwareEvaluationContextProvider(Collections.singletonList(new SampleExtension())));
 
-		assertThat(persistentEntity.getKeySpace()).isEqualTo("some");
+		assertThat(persistentEntity.getKeySpace()).isEqualTo("some_foo");
 	}
 
 	@Test // DATAKV-268
@@ -81,7 +85,7 @@ class BasicKeyValuePersistentEntityUnitTests {
 		assertThat(persistentEntity.getKeySpace()).isEqualTo(NoKeyspaceEntity.class.getName());
 	}
 
-	@KeySpace("#{myProperty}")
+	@KeySpace("#{myProperty}_${my.property}")
 	private static class ExpressionEntity {}
 
 	@KeySpace