DATACMNS-825 - Polishing.

Tweaked annotation cache usage in BasicPersistentEntity.findAnnotation(…).

Original pull request: #156.
This commit is contained in:
Oliver Gierke
2016-03-08 13:20:08 +01:00
parent a40e247c25
commit f0f9d5bc20
2 changed files with 5 additions and 8 deletions

View File

@@ -359,15 +359,14 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
* @see org.springframework.data.mapping.PersistentEntity#findAnnotation(java.lang.Class)
*/
@Override
@SuppressWarnings("unchecked")
public <A extends Annotation> A findAnnotation(Class<A> annotationType) {
A annotation = annotationType.getAnnotation(annotationType);
if (annotation != null) {
return annotation;
if (annotationCache.containsKey(annotationType)) {
return (A) annotationCache.get(annotationType);
}
annotation = AnnotatedElementUtils.findMergedAnnotation(getType(), annotationType);
A annotation = AnnotatedElementUtils.findMergedAnnotation(getType(), annotationType);
annotationCache.put(annotationType, annotation);
return annotation;