diff --git a/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java b/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java index 6f1a991d2..c260ac250 100644 --- a/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java +++ b/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java @@ -15,11 +15,15 @@ */ package org.springframework.data.mapping.model; +import static org.springframework.core.annotation.AnnotationUtils.*; + import java.beans.PropertyDescriptor; import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -42,6 +46,7 @@ public abstract class AnnotationBasedPersistentProperty
{
private final Value value;
+ private final Map A findAnnotation(Class extends A> annotationType) {
+ @SuppressWarnings("unchecked")
+ public A findAnnotation(Class extends A> annotationType) {
Assert.notNull(annotationType, "Annotation type must not be null!");
+ if (annotationCache != null && annotationCache.containsKey(annotationType)) {
+ return (A) annotationCache.get(annotationType);
+ }
+
for (Method method : Arrays.asList(getGetter(), getSetter())) {
if (method == null) {
@@ -125,11 +135,26 @@ public abstract class AnnotationBasedPersistentProperty A cacheAndReturn(Class extends A> type, A annotation) {
+
+ if (annotationCache != null) {
+ annotationCache.put(type, annotation);
+ }
+
+ return annotation;
}
/**