Skip to content

Aligning internal caches with core framework patterns. #3073

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.x-3067-SNAPSHOT</version>

<name>Spring Data Core</name>
<description>Core Spring concepts underpinning every Spring Data module.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.time.temporal.TemporalAccessor;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Predicate;
import java.util.stream.Stream;

Expand All @@ -40,7 +41,6 @@
import org.springframework.data.mapping.context.PersistentEntities;
import org.springframework.data.util.Lazy;
import org.springframework.util.Assert;
import org.springframework.util.ConcurrentReferenceHashMap;

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

this.entities = entities;
this.metadataCache = new ConcurrentReferenceHashMap<>();
this.metadataCache = new ConcurrentHashMap<>();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@
public class SimplePropertyValueConverterRegistry<P extends PersistentProperty<P>>
implements ValueConverterRegistry<P> {

private final Map<Key, PropertyValueConverter<?, ?, ? extends ValueConversionContext<P>>> converterRegistrationMap = new LinkedHashMap<>();
private final Map<Key, PropertyValueConverter<?, ?, ? extends ValueConversionContext<P>>> converterRegistrationMap;

public SimplePropertyValueConverterRegistry() {}
public SimplePropertyValueConverterRegistry() {
this.converterRegistrationMap = new LinkedHashMap<>();
}

SimplePropertyValueConverterRegistry(SimplePropertyValueConverterRegistry<P> source) {
this.converterRegistrationMap.putAll(source.converterRegistrationMap);
this.converterRegistrationMap = new LinkedHashMap<>(source.converterRegistrationMap);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,12 +775,14 @@ protected boolean canEqual(final Object other) {
*/
class PropertySpecifiers {

private final Map<String, PropertySpecifier> propertySpecifiers = new LinkedHashMap<>();
private final Map<String, PropertySpecifier> propertySpecifiers;

PropertySpecifiers() {}
PropertySpecifiers() {
this. propertySpecifiers = new LinkedHashMap<>();
}

PropertySpecifiers(PropertySpecifiers propertySpecifiers) {
this.propertySpecifiers.putAll(propertySpecifiers.propertySpecifiers);
this.propertySpecifiers = new LinkedHashMap<>(propertySpecifiers.propertySpecifiers);
}

public void add(PropertySpecifier specifier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public enum DistanceFormatter implements Converter<String, Distance>, Formatter<

static {

Map<String, Metric> metrics = new LinkedHashMap<>();
Map<String, Metric> metrics = new LinkedHashMap<>(Metrics.values().length);

for (Metric metric : Metrics.values()) {
metrics.put(metric.getAbbreviation(), metric);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.lang.reflect.Method;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BiFunction;

import org.apache.commons.logging.Log;
Expand All @@ -26,7 +27,6 @@
import org.springframework.core.ResolvableType;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ConcurrentReferenceHashMap;
import org.springframework.util.ReflectionUtils;

/**
Expand All @@ -40,7 +40,7 @@
*/
class DefaultEntityCallbacks implements EntityCallbacks {

private final Map<Class<?>, Method> callbackMethodCache = new ConcurrentReferenceHashMap<>(64);
private final Map<Class<?>, Method> callbackMethodCache = new ConcurrentHashMap<>(64);
private final SimpleEntityCallbackInvoker callbackInvoker = new SimpleEntityCallbackInvoker();
private final EntityCallbackDiscoverer callbackDiscoverer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.lang.reflect.Method;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BiFunction;

import org.apache.commons.logging.Log;
Expand All @@ -28,7 +29,6 @@
import org.springframework.core.ResolvableType;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ConcurrentReferenceHashMap;
import org.springframework.util.ReflectionUtils;

/**
Expand All @@ -41,7 +41,7 @@
*/
class DefaultReactiveEntityCallbacks implements ReactiveEntityCallbacks {

private final Map<Class<?>, Method> callbackMethodCache = new ConcurrentReferenceHashMap<>(64);
private final Map<Class<?>, Method> callbackMethodCache = new ConcurrentHashMap<>(64);
private final ReactiveEntityCallbackInvoker callbackInvoker = new DefaultReactiveEntityCallbackInvoker();
private final EntityCallbackDiscoverer callbackDiscoverer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ConcurrentReferenceHashMap;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.comparator.Comparators;

Expand All @@ -54,7 +53,7 @@ class EntityCallbackDiscoverer {

private final CallbackRetriever defaultRetriever = new CallbackRetriever();
private final Map<CallbackCacheKey, CallbackRetriever> retrieverCache = new ConcurrentHashMap<>(64);
private final Map<Class<?>, ResolvableType> entityTypeCache = new ConcurrentReferenceHashMap<>(64);
private final Map<Class<?>, ResolvableType> entityTypeCache = new ConcurrentHashMap<>(64);

@Nullable private ClassLoader beanClassLoader;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ private E doAddPersistentEntity(TypeInformation<?> typeInformation) {

if (shouldCreateProperties(userTypeInformation)) {
PropertyDescriptor[] pds = BeanUtils.getPropertyDescriptors(type);
Map<String, PropertyDescriptor> descriptors = new HashMap<>();
Map<String, PropertyDescriptor> descriptors = new HashMap<>(pds.length);

for (PropertyDescriptor descriptor : pds) {
descriptors.put(descriptor.getName(), descriptor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.springframework.data.mapping.context;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
Expand All @@ -33,7 +34,6 @@
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ConcurrentReferenceHashMap;
import org.springframework.util.StringUtils;

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

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

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

public PersistentPropertyPathFactory(MappingContext<E, P> context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import org.springframework.core.annotation.AnnotatedElementUtils;
Expand All @@ -46,8 +47,6 @@
import org.springframework.lang.Nullable;
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 @@ -117,9 +116,9 @@ public BasicPersistentEntity(TypeInformation<T> information, @Nullable Comparato
this.associations = comparator == null ? new HashSet<>() : new TreeSet<>(new AssociationComparator<>(comparator));

this.propertyCache = new HashMap<>(16, 1f);
this.annotationCache = new ConcurrentReferenceHashMap<>(16, ReferenceType.WEAK);
this.annotationCache = new ConcurrentHashMap<>(16);
this.propertyAnnotationCache = CollectionUtils
.toMultiValueMap(new ConcurrentReferenceHashMap<>(16, ReferenceType.WEAK));
.toMultiValueMap(new ConcurrentHashMap<>(16));
this.propertyAccessorFactory = BeanWrapperPropertyAccessorFactory.INSTANCE;
this.typeAlias = Lazy.of(() -> getAliasFromAnnotation(getType()));
this.isNewStrategy = Lazy.of(() -> Persistable.class.isAssignableFrom(information.getType()) //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.springframework.data.util.KotlinReflectionUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ConcurrentReferenceHashMap;
import org.springframework.util.ReflectionUtils;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,7 @@ private static int getInvokeOp(Method method, boolean interfaceDefinition) {
private static Map<String, PropertyStackAddress> createPropertyStackMap(
List<PersistentProperty<?>> persistentProperties) {

Map<String, PropertyStackAddress> stackmap = new HashMap<>();
Map<String, PropertyStackAddress> stackmap = new HashMap<>(persistentProperties.size());

for (PersistentProperty<?> property : persistentProperties) {
stackmap.put(property.getName(), new PropertyStackAddress(new Label(), property.getName().hashCode()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.ProxyMethodInvocation;
import org.springframework.lang.Nullable;
import org.springframework.util.ConcurrentReferenceHashMap;
import org.springframework.util.ConcurrentReferenceHashMap.ReferenceType;
import org.springframework.util.ReflectionUtils;

/**
Expand All @@ -43,7 +42,7 @@
public class DefaultMethodInvokingMethodInterceptor implements MethodInterceptor {

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

/**
* Returns whether the {@code interfaceClass} declares {@link Method#isDefault() default methods}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
Expand All @@ -34,7 +35,6 @@
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ConcurrentReferenceHashMap;

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

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

private final Lazy<DefaultMethodInvokingMethodInterceptor> defaultMethodInvokingMethodInterceptor = Lazy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ public SpelEvaluatingMethodInterceptor(MethodInterceptor delegate, Object target
private static Map<Integer, Expression> potentiallyCreateExpressionsForMethodsOnTargetInterface(
ExpressionParser parser, Class<?> targetInterface) {

Map<Integer, Expression> expressions = new HashMap<>();
Method[] methods = targetInterface.getMethods();
Map<Integer, Expression> expressions = new HashMap<>(methods.length);

for (Method method : targetInterface.getMethods()) {
for (Method method : methods) {

Value value = AnnotationUtils.findAnnotation(method, Value.class);
if (value == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import org.springframework.beans.BeanUtils;
Expand All @@ -30,7 +31,6 @@
import org.springframework.data.repository.support.Repositories;
import org.springframework.data.util.TypeInformation;
import org.springframework.util.Assert;
import org.springframework.util.ConcurrentReferenceHashMap;

import com.querydsl.core.types.EntityPath;

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

this.entityPathResolver = entityPathResolver;
this.entityPaths = new ConcurrentReferenceHashMap<>();
this.entityPaths = new ConcurrentHashMap<>();
this.beanFactory = Optional.empty();
this.repositories = Optional.empty();
this.defaultCustomizer = NoOpCustomizer.INSTANCE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.lang.annotation.ElementType;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
Expand Down Expand Up @@ -49,7 +50,7 @@
public class MethodInvocationValidator implements MethodInterceptor {

private final ParameterNameDiscoverer discoverer = new DefaultParameterNameDiscoverer();
private final Map<Method, Nullability> nullabilityCache = new ConcurrentReferenceHashMap<>(16, ReferenceType.WEAK);
private final Map<Method, Nullability> nullabilityCache = new ConcurrentHashMap<>(16);

/**
* Returns {@literal true} if the {@code repositoryInterface} is supported by this interceptor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ public QueryExecutorMethodInterceptor(RepositoryInformation repositoryInformatio
private Map<Method, RepositoryQuery> mapMethodsToQuery(RepositoryInformation repositoryInformation,
QueryLookupStrategy lookupStrategy, ProjectionFactory projectionFactory) {

Map<Method, RepositoryQuery> result = new HashMap<>();
List<Method> queryMethods = repositoryInformation.getQueryMethods().toList();
Map<Method, RepositoryQuery> result = new HashMap<>(queryMethods.size());

for (Method method : repositoryInformation.getQueryMethods()) {
for (Method method : queryMethods) {

Pair<Method, RepositoryQuery> pair = lookupQuery(method, repositoryInformation, lookupStrategy,
projectionFactory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ConcurrentReferenceHashMap;
import org.springframework.util.ObjectUtils;
import org.springframework.util.ReflectionUtils;

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

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

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

private final Map<Method, RepositoryFragment<?>> fragmentCache = new ConcurrentReferenceHashMap<>();
private final Map<Method, RepositoryFragment<?>> fragmentCache = new ConcurrentHashMap<>();
private final Map<Method, RepositoryMethodInvoker> invocationMetadataCache = new ConcurrentHashMap<>();
private final List<RepositoryFragment<?>> fragments;

Expand Down
Loading