@@ -72,6 +72,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
72
72
73
73
private final Map <String , P > propertyCache ;
74
74
private final Map <Class <? extends Annotation >, Optional <Annotation >> annotationCache ;
75
+ private final Map <Class <? extends Annotation >, Optional <P >> propertyAnnotationCache ;
75
76
76
77
private P idProperty ;
77
78
private P versionProperty ;
@@ -109,6 +110,7 @@ public BasicPersistentEntity(TypeInformation<T> information, Comparator<P> compa
109
110
110
111
this .propertyCache = new HashMap <>();
111
112
this .annotationCache = new HashMap <>();
113
+ this .propertyAnnotationCache = new HashMap <>();
112
114
this .propertyAccessorFactory = BeanWrapperPropertyAccessorFactory .INSTANCE ;
113
115
this .typeAlias = Lazy .of (() -> getAliasFromAnnotation (getType ()));
114
116
}
@@ -265,14 +267,7 @@ public void addAssociation(Association<P> association) {
265
267
* @see org.springframework.data.mapping.PersistentEntity#getPersistentProperty(java.lang.String)
266
268
*/
267
269
public P getPersistentProperty (String name ) {
268
-
269
- P property = propertyCache .get (name );
270
-
271
- if (property != null ) {
272
- return property ;
273
- }
274
-
275
- return null ;
270
+ return propertyCache .get (name );
276
271
}
277
272
278
273
/*
@@ -284,12 +279,23 @@ public P getPersistentProperty(Class<? extends Annotation> annotationType) {
284
279
285
280
Assert .notNull (annotationType , "Annotation type must not be null!" );
286
281
287
- Optional <P > property = properties .stream ()//
288
- .filter (it -> it .isAnnotationPresent (annotationType ))//
282
+ return propertyAnnotationCache .computeIfAbsent (annotationType , this ::doFindPersistentProperty ).orElse (null );
283
+ }
284
+
285
+ private Optional <P > doFindPersistentProperty (Class <? extends Annotation > annotationType ) {
286
+
287
+ Optional <P > property = properties .stream () //
288
+ .filter (it -> it .isAnnotationPresent (annotationType )) //
289
289
.findAny ();
290
290
291
- return property .orElseGet (() -> associations .stream ().map (Association ::getInverse )//
292
- .filter (it -> it .isAnnotationPresent (annotationType )).findAny ().orElse (null ));
291
+ if (property .isPresent ()) {
292
+
293
+ return property ;
294
+ }
295
+
296
+ return associations .stream () //
297
+ .map (Association ::getInverse ) //
298
+ .filter (it -> it .isAnnotationPresent (annotationType )).findAny ();
293
299
}
294
300
295
301
/*
0 commit comments