views:

187

answers:

1

I have a problem where i need to walk through an object graph and pick out a particular property value. My original solution caches a linked list of property names that need to be applied in order to get from point A to point B in the object graph. I then use apache commons PropertyUtils to iterate through the linked list calling getProperty(Object bean, String name) until i have reached point B.

My question is around how this will perform compared to perhaps cahing the Method objects for each step. What is propertyUtils doing under the bonnet? Is it doing a lot of reflection / heavy lifting?

+1  A: 

You don't need to transverse manually the graph because new versions of commons beanutils also support expressions like bean1.prop1.prop2.

About the performance if you only execute once each expression the propertyutils implementations is fine, because some degree of reflection is absolutely necesary.

You can make a more real performance improvment if each expression is called several times. Then caching the final methods to execute can improve the result because you do the big reflection only one time for expression.

If you use the expression several times you can take a look to OGNL that support "compiled expressions".

lujop