Details
-
Bug
-
Resolution: Fixed
-
Critical
-
4.5.9, 5.0
Description
We use now the proxy based bean merger but build again and again such proxy objects. I quickly improved the info.magnolia.beanmerger.ProxyBasedBeanMerger by adding value caching.
@Override
public Object invoke(Object proxy, Method method, Object[] arguments) throws Throwable {
// only merge calls to property getters
if (arguments.length > 0) {
// invoke the method on the first possibility
for (Object source : sources) {
if(method.getDeclaringClass().isInstance(source)){
if(method.getName().startsWith("set")){
String getterMethodName = "get" + StringUtils.removeStart(method.getName(),"set");
cache.remove(getterMethodName);
}
return method.invoke(source, arguments);
}
}
throw new IllegalStateException("Can't call method " + method.getName() + " on any of the sources.");
}
// try to use cache
if(cache.containsKey(method.getName())){
return cache.get(method.getName());
}
List values = new ArrayList();
for (Object obj : sources) {
values.add(evaluate(obj, method, arguments));
}
Object merged = merger.merge(values);
cache.put(method.getName(), merged);
return merged;
}
Checklists
Acceptance criteria