Skip to content

Commit

Permalink
DATACMNS-1364 - Polishing.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mp911de authored and odrotbohm committed Aug 14, 2018
1 parent 9edf2e5 commit 6b0e774
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import org.springframework.core.annotation.AnnotatedElementUtils;
Expand All @@ -38,6 +39,7 @@
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ConcurrentReferenceHashMap;
import org.springframework.util.ConcurrentReferenceHashMap.ReferenceType;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;

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

this.propertyCache = new ConcurrentHashMap<>();
this.annotationCache = new ConcurrentReferenceHashMap<>();
this.propertyAnnotationCache = CollectionUtils.toMultiValueMap(new ConcurrentReferenceHashMap<>());
this.annotationCache = new ConcurrentReferenceHashMap<>(16, ReferenceType.WEAK);
this.propertyAnnotationCache = CollectionUtils
.toMultiValueMap(new ConcurrentReferenceHashMap<>(16, ReferenceType.WEAK));
this.propertyAccessorFactory = BeanWrapperPropertyAccessorFactory.INSTANCE;
this.typeAlias = Lazy.of(() -> getAliasFromAnnotation(getType()));
this.isNewStrategy = Lazy.of(() -> Persistable.class.isAssignableFrom(information.getType()) //
Expand Down Expand Up @@ -236,7 +239,7 @@ public void addPersistentProperty(P property) {
}
}

/*
/*
* (non-Javadoc)
* @see org.springframework.data.mapping.model.MutablePersistentEntity#setEvaluationContextProvider(org.springframework.data.spel.EvaluationContextProvider)
*/
Expand Down Expand Up @@ -469,7 +472,7 @@ public IdentifierAccessor getIdentifierAccessor(Object bean) {
return hasIdProperty() ? new IdPropertyIdentifierAccessor(this, bean) : new AbsentIdentifierAccessor(bean);
}

/*
/*
* (non-Javadoc)
* @see org.springframework.data.mapping.PersistentEntity#isNew(java.lang.Object)
*/
Expand All @@ -481,7 +484,7 @@ public boolean isNew(Object bean) {
return isNewStrategy.get().isNew(bean);
}

/*
/*
* (non-Javadoc)
* @see org.springframework.data.mapping.PersistentEntity#isImmutable()
*/
Expand Down Expand Up @@ -516,7 +519,7 @@ protected EvaluationContext getEvaluationContext(Object rootObject) {
* Returns the default {@link IsNewStrategy} to be used. Will be a {@link PersistentEntityIsNewStrategy} by default.
* Note, that this strategy only gets used if the entity doesn't implement {@link Persistable} as this indicates the
* user wants to be in control over whether an entity is new or not.
*
*
* @return
* @since 2.1
*/
Expand All @@ -526,7 +529,7 @@ protected IsNewStrategy getFallbackIsNewStrategy() {

/**
* Verifies the given bean type to no be {@literal null} and of the type of the current {@link PersistentEntity}.
*
*
* @param bean must not be {@literal null}.
*/
private final void verifyBeanType(Object bean) {
Expand Down

0 comments on commit 6b0e774

Please sign in to comment.