DATAMONGO-439 - Performance improvements in mapping subsystem.
Fixed minor performance problems discovered by the fix for DATAMONGO-439. We're now caching the information whether a constructor parameter is an enclosing class parameter. PersistentEntityParameterValueProvider is throwing an exception now if the parameter is not referring to a property of the entity (via the parameter name).
This commit is contained in:
@@ -155,6 +155,8 @@ public class PreferredConstructor<T, P extends PersistentProperty<P>> {
|
||||
private final String key;
|
||||
private final PersistentEntity<T, P> entity;
|
||||
|
||||
private Boolean enclosingClassCache;
|
||||
|
||||
/**
|
||||
* Creates a new {@link Parameter} with the given name, {@link TypeInformation} as well as an array of
|
||||
* {@link Annotation}s. Will insprect the annotations for an {@link Value} annotation to lookup a key or an SpEL
|
||||
@@ -244,8 +246,12 @@ public class PreferredConstructor<T, P extends PersistentProperty<P>> {
|
||||
|
||||
private boolean isEnclosingClassParameter() {
|
||||
|
||||
Class<T> owningType = entity.getType();
|
||||
return owningType.isMemberClass() && type.getType().equals(owningType.getEnclosingClass());
|
||||
if (enclosingClassCache == null) {
|
||||
Class<T> owningType = entity.getType();
|
||||
this.enclosingClassCache = owningType.isMemberClass() && type.getType().equals(owningType.getEnclosingClass());
|
||||
}
|
||||
|
||||
return enclosingClassCache;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -86,6 +86,11 @@ public class PersistentEntityParameterValueProvider<P extends PersistentProperty
|
||||
|
||||
P property = entity.getPersistentProperty(parameter.getName());
|
||||
|
||||
if (property == null) {
|
||||
throw new MappingException(String.format("No property %s found on entity %s to bind constructor parameter to!",
|
||||
parameter.getName(), entity.getType()));
|
||||
}
|
||||
|
||||
return provider.getPropertyValue(property);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,8 @@ public class PersistentEntityParameterValueProviderUnitTests<P extends Persisten
|
||||
|
||||
@Mock
|
||||
PropertyValueProvider<P> propertyValueProvider;
|
||||
@Mock
|
||||
P property;
|
||||
|
||||
/**
|
||||
* @see DATACMNS-134
|
||||
@@ -50,7 +52,11 @@ public class PersistentEntityParameterValueProviderUnitTests<P extends Persisten
|
||||
|
||||
Object outer = new Outer();
|
||||
|
||||
PersistentEntity<Inner, P> entity = new BasicPersistentEntity<Inner, P>(ClassTypeInformation.from(Inner.class));
|
||||
PersistentEntity<Inner, P> entity = new BasicPersistentEntity<Inner, P>(ClassTypeInformation.from(Inner.class)) {
|
||||
public P getPersistentProperty(String name) {
|
||||
return property;
|
||||
}
|
||||
};
|
||||
PreferredConstructor<Inner, P> constructor = entity.getPersistenceConstructor();
|
||||
Iterator<Parameter<Object, P>> iterator = constructor.getParameters().iterator();
|
||||
|
||||
@@ -65,6 +71,8 @@ public class PersistentEntityParameterValueProviderUnitTests<P extends Persisten
|
||||
|
||||
class Inner {
|
||||
|
||||
Object myObject;
|
||||
|
||||
Inner(Object myObject) {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user