Skip to content

Commit f0f9d5b

Browse files
committed
DATACMNS-825 - Polishing.
Tweaked annotation cache usage in BasicPersistentEntity.findAnnotation(…). Original pull request: #156.
1 parent a40e247 commit f0f9d5b

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,15 +359,14 @@ public void doWithAssociations(SimpleAssociationHandler handler) {
359359
* @see org.springframework.data.mapping.PersistentEntity#findAnnotation(java.lang.Class)
360360
*/
361361
@Override
362+
@SuppressWarnings("unchecked")
362363
public <A extends Annotation> A findAnnotation(Class<A> annotationType) {
363364

364-
A annotation = annotationType.getAnnotation(annotationType);
365-
366-
if (annotation != null) {
367-
return annotation;
365+
if (annotationCache.containsKey(annotationType)) {
366+
return (A) annotationCache.get(annotationType);
368367
}
369368

370-
annotation = AnnotatedElementUtils.findMergedAnnotation(getType(), annotationType);
369+
A annotation = AnnotatedElementUtils.findMergedAnnotation(getType(), annotationType);
371370
annotationCache.put(annotationType, annotation);
372371

373372
return annotation;

src/test/java/org/springframework/data/mapping/model/BasicPersistentEntityUnitTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,7 @@ public String getProperty() {
274274
}
275275

276276
@ComposedTypeAlias
277-
static class AliasEntityUsingComposedAnnotation {
278-
279-
}
277+
static class AliasEntityUsingComposedAnnotation {}
280278

281279
static class Subtype extends Entity {}
282280
}

0 commit comments

Comments
 (0)