Skip to content

Commit a59f183

Browse files
mp911deodrotbohm
authored andcommitted
DATACMNS-1364 - Polishing.
Use weak references in annotation and property annotation cache to retain references until the last GC root is cleared. Remove trailing whitespaces. Reformat. Original pull request: #304.
1 parent 9edf2e5 commit a59f183

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

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

+9-7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.springframework.util.Assert;
3939
import org.springframework.util.CollectionUtils;
4040
import org.springframework.util.ConcurrentReferenceHashMap;
41+
import org.springframework.util.ConcurrentReferenceHashMap.ReferenceType;
4142
import org.springframework.util.MultiValueMap;
4243
import org.springframework.util.StringUtils;
4344

@@ -105,8 +106,9 @@ public BasicPersistentEntity(TypeInformation<T> information, @Nullable Comparato
105106
this.associations = comparator == null ? new HashSet<>() : new TreeSet<>(new AssociationComparator<>(comparator));
106107

107108
this.propertyCache = new ConcurrentHashMap<>();
108-
this.annotationCache = new ConcurrentReferenceHashMap<>();
109-
this.propertyAnnotationCache = CollectionUtils.toMultiValueMap(new ConcurrentReferenceHashMap<>());
109+
this.annotationCache = new ConcurrentReferenceHashMap<>(16, ReferenceType.WEAK);
110+
this.propertyAnnotationCache = CollectionUtils
111+
.toMultiValueMap(new ConcurrentReferenceHashMap<>(16, ReferenceType.WEAK));
110112
this.propertyAccessorFactory = BeanWrapperPropertyAccessorFactory.INSTANCE;
111113
this.typeAlias = Lazy.of(() -> getAliasFromAnnotation(getType()));
112114
this.isNewStrategy = Lazy.of(() -> Persistable.class.isAssignableFrom(information.getType()) //
@@ -236,7 +238,7 @@ public void addPersistentProperty(P property) {
236238
}
237239
}
238240

239-
/*
241+
/*
240242
* (non-Javadoc)
241243
* @see org.springframework.data.mapping.model.MutablePersistentEntity#setEvaluationContextProvider(org.springframework.data.spel.EvaluationContextProvider)
242244
*/
@@ -469,7 +471,7 @@ public IdentifierAccessor getIdentifierAccessor(Object bean) {
469471
return hasIdProperty() ? new IdPropertyIdentifierAccessor(this, bean) : new AbsentIdentifierAccessor(bean);
470472
}
471473

472-
/*
474+
/*
473475
* (non-Javadoc)
474476
* @see org.springframework.data.mapping.PersistentEntity#isNew(java.lang.Object)
475477
*/
@@ -481,7 +483,7 @@ public boolean isNew(Object bean) {
481483
return isNewStrategy.get().isNew(bean);
482484
}
483485

484-
/*
486+
/*
485487
* (non-Javadoc)
486488
* @see org.springframework.data.mapping.PersistentEntity#isImmutable()
487489
*/
@@ -516,7 +518,7 @@ protected EvaluationContext getEvaluationContext(Object rootObject) {
516518
* Returns the default {@link IsNewStrategy} to be used. Will be a {@link PersistentEntityIsNewStrategy} by default.
517519
* Note, that this strategy only gets used if the entity doesn't implement {@link Persistable} as this indicates the
518520
* user wants to be in control over whether an entity is new or not.
519-
*
521+
*
520522
* @return
521523
* @since 2.1
522524
*/
@@ -526,7 +528,7 @@ protected IsNewStrategy getFallbackIsNewStrategy() {
526528

527529
/**
528530
* Verifies the given bean type to no be {@literal null} and of the type of the current {@link PersistentEntity}.
529-
*
531+
*
530532
* @param bean must not be {@literal null}.
531533
*/
532534
private final void verifyBeanType(Object bean) {

0 commit comments

Comments
 (0)