DATACMNS-642 - Avoid setter lookup in BeanWrapper for if field access is used.

We now delay the lookup of the setter method until we discover we really  need to use property access.
This commit is contained in:
Oliver Gierke
2015-02-04 17:11:48 +01:00
parent bff8caba75
commit fe49e4cf14

View File

@@ -66,16 +66,18 @@ public class BeanWrapper<T> implements PersistentPropertyAccessor {
Assert.notNull(property, "PersistentProperty must not be null!");
Method setter = property.getSetter();
try {
if (!property.usePropertyAccess()) {
ReflectionUtils.makeAccessible(property.getField());
ReflectionUtils.setField(property.getField(), bean, value);
return;
}
} else if (property.usePropertyAccess() && setter != null) {
Method setter = property.getSetter();
if (property.usePropertyAccess() && setter != null) {
ReflectionUtils.makeAccessible(setter);
ReflectionUtils.invokeMethod(setter, bean, value);
@@ -123,10 +125,10 @@ public class BeanWrapper<T> implements PersistentPropertyAccessor {
ReflectionUtils.makeAccessible(getter);
return (S) ReflectionUtils.invokeMethod(getter, bean);
} else {
return null;
}
return null;
} catch (IllegalStateException e) {
throw new MappingException(String.format("Could not read property %s of %s!", property.toString(),
bean.toString()), e);