Skip to content

Commit 344d6c4

Browse files
Aligning internal caches with core framework patterns.
1 parent 7023ed3 commit 344d6c4

24 files changed

+45
-51
lines changed

src/main/java/org/springframework/data/auditing/MappingAuditableBeanWrapperFactory.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.time.temporal.TemporalAccessor;
2020
import java.util.Map;
2121
import java.util.Optional;
22+
import java.util.concurrent.ConcurrentHashMap;
2223
import java.util.function.Predicate;
2324
import java.util.stream.Stream;
2425

@@ -40,7 +41,6 @@
4041
import org.springframework.data.mapping.context.PersistentEntities;
4142
import org.springframework.data.util.Lazy;
4243
import org.springframework.util.Assert;
43-
import org.springframework.util.ConcurrentReferenceHashMap;
4444

4545
/**
4646
* {@link AuditableBeanWrapperFactory} that will create am {@link AuditableBeanWrapper} using mapping information
@@ -67,7 +67,7 @@ public MappingAuditableBeanWrapperFactory(PersistentEntities entities) {
6767
Assert.notNull(entities, "PersistentEntities must not be null");
6868

6969
this.entities = entities;
70-
this.metadataCache = new ConcurrentReferenceHashMap<>();
70+
this.metadataCache = new ConcurrentHashMap<>();
7171
}
7272

7373
@Override

src/main/java/org/springframework/data/mapping/PropertyPath.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
import java.util.Map;
2424
import java.util.Objects;
2525
import java.util.Stack;
26+
import java.util.concurrent.ConcurrentHashMap;
2627
import java.util.regex.Matcher;
2728
import java.util.regex.Pattern;
2829

2930
import org.springframework.data.util.Streamable;
3031
import org.springframework.data.util.TypeInformation;
3132
import org.springframework.lang.Nullable;
3233
import org.springframework.util.Assert;
33-
import org.springframework.util.ConcurrentReferenceHashMap;
3434
import org.springframework.util.StringUtils;
3535

3636
/**
@@ -50,7 +50,7 @@ public class PropertyPath implements Streamable<PropertyPath> {
5050
private static final Pattern SPLITTER = Pattern.compile("(?:[%s]?([%s]*?[^%s]+))".replaceAll("%s", DELIMITERS));
5151
private static final Pattern SPLITTER_FOR_QUOTED = Pattern.compile("(?:[%s]?([%s]*?[^%s]+))".replaceAll("%s", "\\."));
5252
private static final Pattern NESTED_PROPERTY_PATTERN = Pattern.compile("\\p{Lu}[\\p{Ll}\\p{Nd}]*$");
53-
private static final Map<Property, PropertyPath> cache = new ConcurrentReferenceHashMap<>();
53+
private static final Map<Property, PropertyPath> cache = new ConcurrentHashMap<>();
5454

5555
private final TypeInformation<?> owningType;
5656
private final String name;

src/main/java/org/springframework/data/mapping/callback/DefaultEntityCallbacks.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.lang.reflect.Method;
1919
import java.util.Map;
20+
import java.util.concurrent.ConcurrentHashMap;
2021
import java.util.function.BiFunction;
2122

2223
import org.apache.commons.logging.Log;
@@ -26,7 +27,6 @@
2627
import org.springframework.core.ResolvableType;
2728
import org.springframework.util.Assert;
2829
import org.springframework.util.ClassUtils;
29-
import org.springframework.util.ConcurrentReferenceHashMap;
3030
import org.springframework.util.ReflectionUtils;
3131

3232
/**
@@ -40,7 +40,7 @@
4040
*/
4141
class DefaultEntityCallbacks implements EntityCallbacks {
4242

43-
private final Map<Class<?>, Method> callbackMethodCache = new ConcurrentReferenceHashMap<>(64);
43+
private final Map<Class<?>, Method> callbackMethodCache = new ConcurrentHashMap<>(64);
4444
private final SimpleEntityCallbackInvoker callbackInvoker = new SimpleEntityCallbackInvoker();
4545
private final EntityCallbackDiscoverer callbackDiscoverer;
4646

src/main/java/org/springframework/data/mapping/callback/DefaultReactiveEntityCallbacks.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.lang.reflect.Method;
2121
import java.util.Map;
22+
import java.util.concurrent.ConcurrentHashMap;
2223
import java.util.function.BiFunction;
2324

2425
import org.apache.commons.logging.Log;
@@ -28,7 +29,6 @@
2829
import org.springframework.core.ResolvableType;
2930
import org.springframework.util.Assert;
3031
import org.springframework.util.ClassUtils;
31-
import org.springframework.util.ConcurrentReferenceHashMap;
3232
import org.springframework.util.ReflectionUtils;
3333

3434
/**
@@ -41,7 +41,7 @@
4141
*/
4242
class DefaultReactiveEntityCallbacks implements ReactiveEntityCallbacks {
4343

44-
private final Map<Class<?>, Method> callbackMethodCache = new ConcurrentReferenceHashMap<>(64);
44+
private final Map<Class<?>, Method> callbackMethodCache = new ConcurrentHashMap<>(64);
4545
private final ReactiveEntityCallbackInvoker callbackInvoker = new DefaultReactiveEntityCallbackInvoker();
4646
private final EntityCallbackDiscoverer callbackDiscoverer;
4747

src/main/java/org/springframework/data/mapping/callback/EntityCallbackDiscoverer.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.springframework.lang.Nullable;
3939
import org.springframework.util.Assert;
4040
import org.springframework.util.ClassUtils;
41-
import org.springframework.util.ConcurrentReferenceHashMap;
4241
import org.springframework.util.ReflectionUtils;
4342
import org.springframework.util.comparator.Comparators;
4443

@@ -54,7 +53,7 @@ class EntityCallbackDiscoverer {
5453

5554
private final CallbackRetriever defaultRetriever = new CallbackRetriever();
5655
private final Map<CallbackCacheKey, CallbackRetriever> retrieverCache = new ConcurrentHashMap<>(64);
57-
private final Map<Class<?>, ResolvableType> entityTypeCache = new ConcurrentReferenceHashMap<>(64);
56+
private final Map<Class<?>, ResolvableType> entityTypeCache = new ConcurrentHashMap<>(64);
5857

5958
@Nullable private ClassLoader beanClassLoader;
6059

src/main/java/org/springframework/data/mapping/context/PersistentPropertyPathFactory.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.springframework.data.mapping.context;
1717

1818
import java.util.*;
19+
import java.util.concurrent.ConcurrentHashMap;
1920
import java.util.function.Function;
2021
import java.util.function.Predicate;
2122
import java.util.stream.Collectors;
@@ -33,7 +34,6 @@
3334
import org.springframework.data.util.TypeInformation;
3435
import org.springframework.lang.Nullable;
3536
import org.springframework.util.Assert;
36-
import org.springframework.util.ConcurrentReferenceHashMap;
3737
import org.springframework.util.StringUtils;
3838

3939
/**
@@ -49,7 +49,7 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
4949

5050
private static final Predicate<PersistentProperty<? extends PersistentProperty<?>>> IS_ENTITY = PersistentProperty::isEntity;
5151

52-
private final Map<TypeAndPath, PathResolution> propertyPaths = new ConcurrentReferenceHashMap<>();
52+
private final Map<TypeAndPath, PathResolution> propertyPaths = new ConcurrentHashMap<>();
5353
private final MappingContext<E, P> context;
5454

5555
public PersistentPropertyPathFactory(MappingContext<E, P> context) {

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.Optional;
2828
import java.util.Set;
2929
import java.util.TreeSet;
30+
import java.util.concurrent.ConcurrentHashMap;
3031
import java.util.stream.Collectors;
3132

3233
import org.springframework.core.annotation.AnnotatedElementUtils;
@@ -46,8 +47,6 @@
4647
import org.springframework.lang.Nullable;
4748
import org.springframework.util.Assert;
4849
import org.springframework.util.CollectionUtils;
49-
import org.springframework.util.ConcurrentReferenceHashMap;
50-
import org.springframework.util.ConcurrentReferenceHashMap.ReferenceType;
5150
import org.springframework.util.MultiValueMap;
5251
import org.springframework.util.StringUtils;
5352

@@ -117,9 +116,9 @@ public BasicPersistentEntity(TypeInformation<T> information, @Nullable Comparato
117116
this.associations = comparator == null ? new HashSet<>() : new TreeSet<>(new AssociationComparator<>(comparator));
118117

119118
this.propertyCache = new HashMap<>(16, 1f);
120-
this.annotationCache = new ConcurrentReferenceHashMap<>(16, ReferenceType.WEAK);
119+
this.annotationCache = new ConcurrentHashMap<>(16);
121120
this.propertyAnnotationCache = CollectionUtils
122-
.toMultiValueMap(new ConcurrentReferenceHashMap<>(16, ReferenceType.WEAK));
121+
.toMultiValueMap(new ConcurrentHashMap<>(16));
123122
this.propertyAccessorFactory = BeanWrapperPropertyAccessorFactory.INSTANCE;
124123
this.typeAlias = Lazy.of(() -> getAliasFromAnnotation(getType()));
125124
this.isNewStrategy = Lazy.of(() -> Persistable.class.isAssignableFrom(information.getType()) //

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

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.springframework.data.util.KotlinReflectionUtils;
3333
import org.springframework.lang.Nullable;
3434
import org.springframework.util.Assert;
35-
import org.springframework.util.ConcurrentReferenceHashMap;
3635
import org.springframework.util.ReflectionUtils;
3736

3837
/**

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.List;
3333
import java.util.Map;
3434
import java.util.Optional;
35+
import java.util.concurrent.ConcurrentHashMap;
3536
import java.util.function.Predicate;
3637
import java.util.stream.Collectors;
3738

@@ -41,7 +42,6 @@
4142
import org.springframework.data.mapping.SimplePropertyHandler;
4243
import org.springframework.data.util.KotlinReflectionUtils;
4344
import org.springframework.util.Assert;
44-
import org.springframework.util.ConcurrentReferenceHashMap;
4545

4646
/**
4747
* Value object to represent a Kotlin {@code copy} method. The lookup requires a {@code copy} method that matches the
@@ -53,7 +53,7 @@
5353
*/
5454
class KotlinCopyMethod {
5555

56-
private static final Map<Class<?>, Optional<KotlinCopyMethod>> COPY_METHOD_CACHE = new ConcurrentReferenceHashMap<>();
56+
private static final Map<Class<?>, Optional<KotlinCopyMethod>> COPY_METHOD_CACHE = new ConcurrentHashMap<>();
5757

5858
private final Method publicCopyMethod;
5959
private final Method syntheticCopyMethod;

src/main/java/org/springframework/data/projection/DefaultMethodInvokingMethodInterceptor.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@
2222
import java.lang.reflect.Method;
2323
import java.lang.reflect.Modifier;
2424
import java.util.Map;
25+
import java.util.concurrent.ConcurrentHashMap;
2526
import java.util.concurrent.atomic.AtomicBoolean;
2627

2728
import org.aopalliance.intercept.MethodInterceptor;
2829
import org.aopalliance.intercept.MethodInvocation;
2930
import org.springframework.aop.ProxyMethodInvocation;
3031
import org.springframework.lang.Nullable;
31-
import org.springframework.util.ConcurrentReferenceHashMap;
32-
import org.springframework.util.ConcurrentReferenceHashMap.ReferenceType;
3332
import org.springframework.util.ReflectionUtils;
3433

3534
/**
@@ -43,7 +42,7 @@
4342
public class DefaultMethodInvokingMethodInterceptor implements MethodInterceptor {
4443

4544
private static final Lookup LOOKUP = MethodHandles.lookup();
46-
private final Map<Method, MethodHandle> methodHandleCache = new ConcurrentReferenceHashMap<>(10, ReferenceType.WEAK);
45+
private final Map<Method, MethodHandle> methodHandleCache = new ConcurrentHashMap<>();
4746

4847
/**
4948
* Returns whether the {@code interfaceClass} declares {@link Method#isDefault() default methods}.

src/main/java/org/springframework/data/projection/ProxyProjectionFactory.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.HashMap;
2121
import java.util.List;
2222
import java.util.Map;
23+
import java.util.concurrent.ConcurrentHashMap;
2324

2425
import org.aopalliance.intercept.MethodInterceptor;
2526
import org.aopalliance.intercept.MethodInvocation;
@@ -34,7 +35,6 @@
3435
import org.springframework.lang.Nullable;
3536
import org.springframework.util.Assert;
3637
import org.springframework.util.ClassUtils;
37-
import org.springframework.util.ConcurrentReferenceHashMap;
3838

3939
/**
4040
* A {@link ProjectionFactory} to create JDK proxies to back interfaces and handle method invocations on them. By
@@ -60,7 +60,7 @@ class ProxyProjectionFactory implements ProjectionFactory, BeanClassLoaderAware
6060
}
6161

6262
private final List<MethodInterceptorFactory> factories;
63-
private final Map<Class<?>, ProjectionMetadata> projectionInformationCache = new ConcurrentReferenceHashMap<>();
63+
private final Map<Class<?>, ProjectionMetadata> projectionInformationCache = new ConcurrentHashMap<>();
6464
private @Nullable ClassLoader classLoader;
6565

6666
private final Lazy<DefaultMethodInvokingMethodInterceptor> defaultMethodInvokingMethodInterceptor = Lazy

src/main/java/org/springframework/data/querydsl/binding/QuerydslBindingsFactory.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.List;
1919
import java.util.Map;
2020
import java.util.Optional;
21+
import java.util.concurrent.ConcurrentHashMap;
2122
import java.util.stream.Collectors;
2223

2324
import org.springframework.beans.BeanUtils;
@@ -30,7 +31,6 @@
3031
import org.springframework.data.repository.support.Repositories;
3132
import org.springframework.data.util.TypeInformation;
3233
import org.springframework.util.Assert;
33-
import org.springframework.util.ConcurrentReferenceHashMap;
3434

3535
import com.querydsl.core.types.EntityPath;
3636

@@ -63,7 +63,7 @@ public QuerydslBindingsFactory(EntityPathResolver entityPathResolver) {
6363
Assert.notNull(entityPathResolver, "EntityPathResolver must not be null");
6464

6565
this.entityPathResolver = entityPathResolver;
66-
this.entityPaths = new ConcurrentReferenceHashMap<>();
66+
this.entityPaths = new ConcurrentHashMap<>();
6767
this.beanFactory = Optional.empty();
6868
this.repositories = Optional.empty();
6969
this.defaultCustomizer = NoOpCustomizer.INSTANCE;

src/main/java/org/springframework/data/repository/core/support/EventPublishingRepositoryProxyPostProcessor.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Collection;
2121
import java.util.Collections;
2222
import java.util.Map;
23+
import java.util.concurrent.ConcurrentHashMap;
2324
import java.util.function.Supplier;
2425

2526
import org.aopalliance.intercept.MethodInterceptor;
@@ -33,7 +34,6 @@
3334
import org.springframework.data.util.AnnotationDetectionMethodCallback;
3435
import org.springframework.lang.Nullable;
3536
import org.springframework.util.Assert;
36-
import org.springframework.util.ConcurrentReferenceHashMap;
3737
import org.springframework.util.ReflectionUtils;
3838

3939
/**
@@ -141,7 +141,7 @@ private static boolean isDeleteMethod(String methodName) {
141141
*/
142142
static class EventPublishingMethod {
143143

144-
private static Map<Class<?>, EventPublishingMethod> cache = new ConcurrentReferenceHashMap<>();
144+
private static Map<Class<?>, EventPublishingMethod> cache = new ConcurrentHashMap<>();
145145
private static @SuppressWarnings("null") EventPublishingMethod NONE = new EventPublishingMethod(Object.class, null,
146146
null);
147147

src/main/java/org/springframework/data/repository/core/support/MethodInvocationValidator.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.lang.annotation.ElementType;
1919
import java.lang.reflect.Method;
2020
import java.util.Map;
21+
import java.util.concurrent.ConcurrentHashMap;
2122

2223
import org.aopalliance.intercept.MethodInterceptor;
2324
import org.aopalliance.intercept.MethodInvocation;
@@ -49,7 +50,7 @@
4950
public class MethodInvocationValidator implements MethodInterceptor {
5051

5152
private final ParameterNameDiscoverer discoverer = new DefaultParameterNameDiscoverer();
52-
private final Map<Method, Nullability> nullabilityCache = new ConcurrentReferenceHashMap<>(16, ReferenceType.WEAK);
53+
private final Map<Method, Nullability> nullabilityCache = new ConcurrentHashMap<>(16);
5354

5455
/**
5556
* Returns {@literal true} if the {@code repositoryInterface} is supported by this interceptor.

src/main/java/org/springframework/data/repository/core/support/RepositoryComposition.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.springframework.lang.Nullable;
3939
import org.springframework.util.Assert;
4040
import org.springframework.util.ClassUtils;
41-
import org.springframework.util.ConcurrentReferenceHashMap;
4241
import org.springframework.util.ObjectUtils;
4342
import org.springframework.util.ReflectionUtils;
4443

@@ -101,7 +100,7 @@ public class RepositoryComposition {
101100
private static final RepositoryComposition EMPTY = new RepositoryComposition(null, RepositoryFragments.empty(),
102101
MethodLookups.direct(), PASSTHRU_ARG_CONVERTER);
103102

104-
private final Map<Method, Method> methodCache = new ConcurrentReferenceHashMap<>();
103+
private final Map<Method, Method> methodCache = new ConcurrentHashMap<>();
105104
private final RepositoryFragments fragments;
106105
private final MethodLookup methodLookup;
107106
private final BiFunction<Method, Object[], Object[]> argumentConverter;
@@ -365,7 +364,7 @@ public static class RepositoryFragments implements Streamable<RepositoryFragment
365364

366365
static final RepositoryFragments EMPTY = new RepositoryFragments(Collections.emptyList());
367366

368-
private final Map<Method, RepositoryFragment<?>> fragmentCache = new ConcurrentReferenceHashMap<>();
367+
private final Map<Method, RepositoryFragment<?>> fragmentCache = new ConcurrentHashMap<>();
369368
private final Map<Method, RepositoryMethodInvoker> invocationMetadataCache = new ConcurrentHashMap<>();
370369
private final List<RepositoryFragment<?>> fragments;
371370

src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
import java.util.List;
2424
import java.util.Map;
2525
import java.util.Optional;
26+
import java.util.concurrent.ConcurrentHashMap;
2627
import java.util.stream.Collectors;
2728

2829
import org.aopalliance.intercept.MethodInterceptor;
2930
import org.aopalliance.intercept.MethodInvocation;
3031
import org.apache.commons.logging.Log;
3132
import org.apache.commons.logging.LogFactory;
32-
3333
import org.springframework.aop.framework.ProxyFactory;
3434
import org.springframework.aop.interceptor.ExposeInvocationInterceptor;
3535
import org.springframework.beans.BeanUtils;
@@ -66,8 +66,6 @@
6666
import org.springframework.transaction.interceptor.TransactionalProxy;
6767
import org.springframework.util.Assert;
6868
import org.springframework.util.ClassUtils;
69-
import org.springframework.util.ConcurrentReferenceHashMap;
70-
import org.springframework.util.ConcurrentReferenceHashMap.ReferenceType;
7169
import org.springframework.util.ObjectUtils;
7270

7371
/**
@@ -110,7 +108,7 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware,
110108
@SuppressWarnings("null")
111109
public RepositoryFactorySupport() {
112110

113-
this.repositoryInformationCache = new ConcurrentReferenceHashMap<>(16, ReferenceType.WEAK);
111+
this.repositoryInformationCache = new ConcurrentHashMap<>(16);
114112
this.postProcessors = new ArrayList<>();
115113

116114
this.repositoryBaseClass = Optional.empty();

src/main/java/org/springframework/data/repository/query/ReturnedType.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.List;
2424
import java.util.Map;
2525
import java.util.Set;
26+
import java.util.concurrent.ConcurrentHashMap;
2627

2728
import org.springframework.data.mapping.Parameter;
2829
import org.springframework.data.mapping.PreferredConstructor;
@@ -46,7 +47,7 @@
4647
*/
4748
public abstract class ReturnedType {
4849

49-
private static final Map<CacheKey, ReturnedType> cache = new ConcurrentReferenceHashMap<>(32);
50+
private static final Map<CacheKey, ReturnedType> cache = new ConcurrentHashMap<>(32);
5051

5152
private final Class<?> domainType;
5253

0 commit comments

Comments
 (0)