Browse Source

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).
1.3.x
Oliver Gierke 14 years ago
parent
commit
e20938a3ae
  1. 10
      spring-data-commons-core/src/main/java/org/springframework/data/mapping/PreferredConstructor.java
  2. 5
      spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/PersistentEntityParameterValueProvider.java
  3. 10
      spring-data-commons-core/src/test/java/org/springframework/data/mapping/model/PersistentEntityParameterValueProviderUnitTests.java

10
spring-data-commons-core/src/main/java/org/springframework/data/mapping/PreferredConstructor.java

@ -155,6 +155,8 @@ public class PreferredConstructor<T, P extends PersistentProperty<P>> { @@ -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>> { @@ -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;
}
/*

5
spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/PersistentEntityParameterValueProvider.java

@ -86,6 +86,11 @@ public class PersistentEntityParameterValueProvider<P extends PersistentProperty @@ -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);
}
}

10
spring-data-commons-core/src/test/java/org/springframework/data/mapping/model/PersistentEntityParameterValueProviderUnitTests.java

@ -41,6 +41,8 @@ public class PersistentEntityParameterValueProviderUnitTests<P extends Persisten @@ -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 @@ -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 @@ -65,6 +71,8 @@ public class PersistentEntityParameterValueProviderUnitTests<P extends Persisten
class Inner {
Object myObject;
Inner(Object myObject) {
}

Loading…
Cancel
Save