Skip to content

Commit 1c45fcf

Browse files
committed
DATACMNS-867 - Lazify lookups in AbstractPersistentProperty.
1 parent 417e728 commit 1c45fcf

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
5050
CAUSE_FIELD = ReflectionUtils.findField(Throwable.class, "cause");
5151
}
5252

53-
protected final String name;
54-
protected final TypeInformation<?> information;
55-
protected final Class<?> rawType;
56-
protected final Optional<Association<P>> association;
53+
private final String name;
54+
private final TypeInformation<?> information;
55+
private final Class<?> rawType;
56+
private final Lazy<Optional<Association<P>>> association;
5757
private final @Getter PersistentEntity<?, P> owner;
5858
private final @Getter(AccessLevel.PROTECTED) Property property;
5959
private final Lazy<Integer> hashCode;
@@ -71,7 +71,7 @@ public AbstractPersistentProperty(Property property, PersistentEntity<?, P> owne
7171
this.information = PropertyPath.from(Pattern.quote(property.getName()), owner.getTypeInformation())
7272
.getTypeInformation();
7373
this.property = property;
74-
this.association = isAssociation() ? Optional.of(createAssociation()) : Optional.empty();
74+
this.association = Lazy.of(() -> isAssociation() ? Optional.of(createAssociation()) : Optional.empty());
7575
this.owner = owner;
7676

7777
this.hashCode = Lazy.of(property::hashCode);
@@ -206,7 +206,7 @@ public boolean isAssociation() {
206206
*/
207207
@Override
208208
public Optional<Association<P>> getAssociation() {
209-
return association;
209+
return association.get();
210210
}
211211

212212
/*

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,11 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
5656
private final Optional<Value> value;
5757
private final Map<Class<? extends Annotation>, Optional<? extends Annotation>> annotationCache = new HashMap<>();
5858

59-
private Lazy<Boolean> isTransient;
60-
private Lazy<Boolean> usePropertyAccess;
59+
private final Lazy<Boolean> usePropertyAccess = Lazy.of(() -> findPropertyOrOwnerAnnotation(AccessType.class)//
60+
.map(it -> Type.PROPERTY.equals(it.value()))//
61+
.orElse(super.usePropertyAccess()));
62+
private final Lazy<Boolean> isTransient = Lazy.of(() -> super.isTransient() || isAnnotationPresent(Transient.class)
63+
|| isAnnotationPresent(Value.class) || isAnnotationPresent(Autowired.class));
6164

6265
/**
6366
* Creates a new {@link AnnotationBasedPersistentProperty}.
@@ -73,11 +76,6 @@ public AnnotationBasedPersistentProperty(Property property, PersistentEntity<?,
7376
populateAnnotationCache(property);
7477

7578
this.value = findAnnotation(Value.class);
76-
this.usePropertyAccess = Lazy.of(() -> findPropertyOrOwnerAnnotation(AccessType.class)//
77-
.map(it -> Type.PROPERTY.equals(it.value()))//
78-
.orElse(super.usePropertyAccess()));
79-
this.isTransient = Lazy.of(() -> super.isTransient() || isAnnotationPresent(Transient.class)
80-
|| isAnnotationPresent(Value.class) || isAnnotationPresent(Autowired.class));
8179
}
8280

8381
/**

0 commit comments

Comments
 (0)