diff --git a/pom.xml b/pom.xml
index 21c9e3f3..7d75b50e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
org.springframework.data
spring-data-keyvalue
- 1.1.0.BUILD-SNAPSHOT
+ 1.1.0.DATAKV-129-SNAPSHOT
Spring Data KeyValue
diff --git a/src/main/java/org/springframework/data/keyvalue/core/mapping/AnnotationBasedKeySpaceResolver.java b/src/main/java/org/springframework/data/keyvalue/core/mapping/AnnotationBasedKeySpaceResolver.java
index 5103a276..1c444478 100644
--- a/src/main/java/org/springframework/data/keyvalue/core/mapping/AnnotationBasedKeySpaceResolver.java
+++ b/src/main/java/org/springframework/data/keyvalue/core/mapping/AnnotationBasedKeySpaceResolver.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 the original author or authors.
+ * Copyright 2015-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -59,7 +59,7 @@ public String resolveKeySpace(Class> type) {
private static Object getKeySpace(Class> type) {
- KeySpace keyspace = AnnotationUtils.findAnnotation(type, KeySpace.class);
+ KeySpace keyspace = AnnotatedElementUtils.findMergedAnnotation(type, KeySpace.class);
if (keyspace != null) {
return AnnotationUtils.getValue(keyspace);
diff --git a/src/test/java/org/springframework/data/keyvalue/CustomKeySpaceAnnotationWithAliasFor.java b/src/test/java/org/springframework/data/keyvalue/CustomKeySpaceAnnotationWithAliasFor.java
new file mode 100644
index 00000000..95f4b219
--- /dev/null
+++ b/src/test/java/org/springframework/data/keyvalue/CustomKeySpaceAnnotationWithAliasFor.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2016 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.data.keyvalue;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.springframework.core.annotation.AliasFor;
+import org.springframework.data.annotation.Persistent;
+import org.springframework.data.keyvalue.annotation.KeySpace;
+
+/**
+ * Custom composed {@link Persistent} annotation using {@link AliasFor} on name attribute.
+ *
+ * @author Christoph Strobl
+ */
+@Persistent
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ ElementType.TYPE })
+@KeySpace
+public @interface CustomKeySpaceAnnotationWithAliasFor {
+
+ @AliasFor(annotation = KeySpace.class, attribute = "value")
+ String name() default "";
+}
diff --git a/src/test/java/org/springframework/data/keyvalue/TypeWithCustomComposedKeySpaceAnnotationUsingAliasFor.java b/src/test/java/org/springframework/data/keyvalue/TypeWithCustomComposedKeySpaceAnnotationUsingAliasFor.java
new file mode 100644
index 00000000..33ad6d6b
--- /dev/null
+++ b/src/test/java/org/springframework/data/keyvalue/TypeWithCustomComposedKeySpaceAnnotationUsingAliasFor.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2016 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.data.keyvalue;
+
+import org.springframework.data.annotation.Id;
+import org.springframework.data.annotation.Persistent;
+import org.springframework.util.ObjectUtils;
+
+/**
+ * A {@link Persistent} type with {@link CustomKeySpaceAnnotationWithAliasFor}.
+ *
+ * @author Christoph Strobl
+ */
+@CustomKeySpaceAnnotationWithAliasFor(name = "aliased")
+public class TypeWithCustomComposedKeySpaceAnnotationUsingAliasFor {
+
+ @Id String id;
+ String name;
+
+ public TypeWithCustomComposedKeySpaceAnnotationUsingAliasFor(String name) {
+ this.name = name;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ObjectUtils.nullSafeHashCode(this.id);
+ result = prime * result + ObjectUtils.nullSafeHashCode(this.name);
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (!(obj instanceof TypeWithCustomComposedKeySpaceAnnotationUsingAliasFor)) {
+ return false;
+ }
+ TypeWithCustomComposedKeySpaceAnnotationUsingAliasFor other = (TypeWithCustomComposedKeySpaceAnnotationUsingAliasFor) obj;
+ if (!ObjectUtils.nullSafeEquals(this.id, other.id)) {
+ return false;
+ }
+ if (!ObjectUtils.nullSafeEquals(this.name, other.name)) {
+ return false;
+ }
+ return true;
+ }
+
+}
diff --git a/src/test/java/org/springframework/data/keyvalue/core/KeyValueTemplateUnitTests.java b/src/test/java/org/springframework/data/keyvalue/core/KeyValueTemplateUnitTests.java
index 59ee40b7..ec872d0a 100644
--- a/src/test/java/org/springframework/data/keyvalue/core/KeyValueTemplateUnitTests.java
+++ b/src/test/java/org/springframework/data/keyvalue/core/KeyValueTemplateUnitTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,6 +42,7 @@
import org.springframework.data.annotation.Id;
import org.springframework.data.keyvalue.SubclassOfTypeWithCustomComposedKeySpaceAnnotation;
import org.springframework.data.keyvalue.TypeWithCustomComposedKeySpaceAnnotation;
+import org.springframework.data.keyvalue.TypeWithCustomComposedKeySpaceAnnotationUsingAliasFor;
import org.springframework.data.keyvalue.core.event.KeyValueEvent;
import org.springframework.data.keyvalue.core.event.KeyValueEvent.AfterDeleteEvent;
import org.springframework.data.keyvalue.core.event.KeyValueEvent.AfterDropKeySpaceEvent;
@@ -69,6 +70,8 @@ public class KeyValueTemplateUnitTests {
private static final Foo FOO_TWO = new Foo("two");
private static final TypeWithCustomComposedKeySpaceAnnotation ALIASED = new TypeWithCustomComposedKeySpaceAnnotation(
"super");
+ private static final TypeWithCustomComposedKeySpaceAnnotationUsingAliasFor ALIASED_USING_ALIAS_FOR = new TypeWithCustomComposedKeySpaceAnnotationUsingAliasFor(
+ "super");
private static final SubclassOfTypeWithCustomComposedKeySpaceAnnotation SUBCLASS_OF_ALIASED = new SubclassOfTypeWithCustomComposedKeySpaceAnnotation(
"sub");
private static final KeyValueQuery STRING_QUERY = new KeyValueQuery("foo == 'two'");
@@ -697,6 +700,17 @@ public void shouldPublishDropKeyspaceEventCorrectly() {
assertThat(captor.getValue().getKeyspace(), is(Foo.class.getName()));
}
+ /**
+ * @see DATAKV-129
+ */
+ @Test
+ public void insertShouldRespectTypeAliasUsingAliasFor() {
+
+ template.insert("1", ALIASED_USING_ALIAS_FOR);
+
+ verify(adapterMock, times(1)).put("1", ALIASED_USING_ALIAS_FOR, "aliased");
+ }
+
@SuppressWarnings("rawtypes")
private void setEventsToPublish(Class extends KeyValueEvent>... events) {
template.setEventTypesToPublish(new HashSet>(Arrays.asList(events)));
diff --git a/src/test/java/org/springframework/data/keyvalue/core/mapping/AnnotationBasedKeySpaceResolverUnitTests.java b/src/test/java/org/springframework/data/keyvalue/core/mapping/AnnotationBasedKeySpaceResolverUnitTests.java
index 2d4dd418..f0c79ec2 100644
--- a/src/test/java/org/springframework/data/keyvalue/core/mapping/AnnotationBasedKeySpaceResolverUnitTests.java
+++ b/src/test/java/org/springframework/data/keyvalue/core/mapping/AnnotationBasedKeySpaceResolverUnitTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@
import org.junit.Before;
import org.junit.Test;
+import org.springframework.core.annotation.AliasFor;
import org.springframework.data.annotation.Persistent;
import org.springframework.data.keyvalue.TypeWithDirectKeySpaceAnnotation;
import org.springframework.data.keyvalue.TypeWithInhteritedPersistentAnnotationNotHavingKeySpace;
@@ -102,6 +103,22 @@ public void shouldResolveDirectKeySpaceAnnotationCorrectly() {
assertThat(resolver.resolveKeySpace(TypeWithDirectKeySpaceAnnotation.class), is("rhaegar"));
}
+ /**
+ * @see DATAKV-129
+ */
+ @Test
+ public void shouldResolveKeySpaceUsingAliasForCorrectly() {
+ assertThat(resolver.resolveKeySpace(EntityWithSetKeySpaceUsingAliasFor.class), is("viserys"));
+ }
+
+ /**
+ * @see DATAKV-129
+ */
+ @Test
+ public void shouldResolveKeySpaceUsingAliasForCorrectlyOnSubClass() {
+ assertThat(resolver.resolveKeySpace(EntityWithInheritedKeySpaceUsingAliasFor.class), is("viserys"));
+ }
+
@PersistentAnnotationWithExplicitKeySpace
static class EntityWithDefaultKeySpace {
@@ -116,6 +133,15 @@ static class EntityWithInheritedKeySpace extends EntityWithSetKeySpace {
}
+ @PersistentAnnotationWithExplicitKeySpace(firstname = "viserys")
+ static class EntityWithSetKeySpaceUsingAliasFor {
+
+ }
+
+ static class EntityWithInheritedKeySpaceUsingAliasFor extends EntityWithSetKeySpaceUsingAliasFor {
+
+ }
+
@Persistent
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
@@ -127,6 +153,19 @@ static class EntityWithInheritedKeySpace extends EntityWithSetKeySpace {
String lastnamne() default "targaryen";
}
+ @Persistent
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ ElementType.TYPE })
+ @KeySpace
+ static @interface PersistentAnnotationWithExplicitKeySpaceUsingAliasFor {
+
+ @AliasFor(annotation = KeySpace.class, attribute = "value")
+ String firstname() default "daenerys";
+
+ String lastnamne() default "targaryen";
+
+ }
+
static class TypeWithoutKeySpace {
String foo;