, D extends ValueConversionContext> PropertyValueConverter getValueConverter(
P property) {
- PropertyValueConverter converter = requireConverterFactory().getConverter(property);
+ PropertyValueConverter converter = doGetConverter(property);
Assert.notNull(converter, String.format("No PropertyValueConverter registered for %s", property));
return converter;
}
+ @SuppressWarnings("unchecked")
+ @Nullable
+ private , D extends ValueConversionContext> PropertyValueConverter doGetConverter(
+ PersistentProperty> property) {
+
+ PropertyValueConverter, ?, ?> converter = converterCache.get(property);
+
+ if (converter == null) {
+
+ synchronized (this) {
+
+ PropertyValueConverter, ?, ?> fromCache = converterCache.get(property);
+ if (fromCache != null) {
+ converter = fromCache;
+ } else {
+
+ converter = requireConverterFactory().getConverter(property);
+
+ Map, PropertyValueConverter, ?, ?>> converterCache = new HashMap<>(
+ this.converterCache);
+ converterCache.put(property, converter != null ? converter : NoOpConverter.INSTANCE);
+ this.converterCache = converterCache;
+ }
+ }
+ }
+
+ if (converter == NoOpConverter.INSTANCE) {
+ return null;
+ }
+
+ return (PropertyValueConverter) converter;
+ }
+
/**
* May be called just once to initialize the underlying factory with its values.
*/
diff --git a/src/main/java/org/springframework/data/mapping/InstanceCreatorMetadataSupport.java b/src/main/java/org/springframework/data/mapping/InstanceCreatorMetadataSupport.java
index 59b1823ef7..6f0868f7b0 100644
--- a/src/main/java/org/springframework/data/mapping/InstanceCreatorMetadataSupport.java
+++ b/src/main/java/org/springframework/data/mapping/InstanceCreatorMetadataSupport.java
@@ -17,9 +17,9 @@
import java.lang.reflect.Executable;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
import org.springframework.util.Assert;
@@ -35,7 +35,7 @@ class InstanceCreatorMetadataSupport> impleme
private final Executable executable;
private final List> parameters;
- private final Map, Boolean> isPropertyParameterCache = new ConcurrentHashMap<>();
+ private volatile Map, Boolean> isPropertyParameterCache = new HashMap<>();
/**
* Creates a new {@link InstanceCreatorMetadataSupport} from the given {@link Executable} and {@link Parameter}s.
@@ -90,15 +90,25 @@ public boolean isCreatorParameter(PersistentProperty> property) {
Boolean cached = isPropertyParameterCache.get(property);
- if (cached != null) {
- return cached;
- }
+ if (cached == null) {
+
+ synchronized (this) {
+
+ Boolean fromCache = isPropertyParameterCache.get(property);
+ if (fromCache != null) {
+ cached = fromCache;
+ } else {
- boolean result = doGetIsCreatorParameter(property);
+ cached = doGetIsCreatorParameter(property);
- isPropertyParameterCache.put(property, result);
+ Map, Boolean> isPropertyParameterCache = new HashMap<>(this.isPropertyParameterCache);
+ isPropertyParameterCache.put(property, cached);
+ this.isPropertyParameterCache = isPropertyParameterCache;
+ }
+ }
+ }
- return result;
+ return cached;
}
@Override
diff --git a/src/main/java/org/springframework/data/util/ClassTypeInformation.java b/src/main/java/org/springframework/data/util/ClassTypeInformation.java
index 554c41f436..35df8f48b8 100644
--- a/src/main/java/org/springframework/data/util/ClassTypeInformation.java
+++ b/src/main/java/org/springframework/data/util/ClassTypeInformation.java
@@ -31,15 +31,19 @@
*
* @author Oliver Gierke
* @author Christoph Strobl
+ * @author Mark Paluch
* @deprecated since 3.0 to go package protected at some point. Refer to {@link TypeInformation} only.
*/
@Deprecated(since = "3.0", forRemoval = true)
@SuppressWarnings({ "rawtypes", "unchecked" })
public class ClassTypeInformation extends TypeDiscoverer {
- private static final ConcurrentLruCache> cache = new ConcurrentLruCache<>(64,
+ private static final ConcurrentLruCache> cache = new ConcurrentLruCache<>(128,
ClassTypeInformation::new);
+ private static final ConcurrentLruCache, ResolvableType> resolvableTypeCache = new ConcurrentLruCache<>(128,
+ ResolvableType::forClass);
+
public static final ClassTypeInformation COLLECTION;
public static final ClassTypeInformation LIST;
public static final ClassTypeInformation SET;
@@ -48,11 +52,11 @@ public class ClassTypeInformation extends TypeDiscoverer {
static {
- OBJECT = (ClassTypeInformation