Announcement Announcement Module
Collapse
No announcement yet.
Retrieving the value of getters on a bean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Retrieving the value of getters on a bean

    Hello.
    I need to find out the values of getters from simple pojos. I've checked around to find already existing solutions but I couldn't find one to satisfy my requirements fully:

    1. BeanUtils from spring - nice class, has caching to provide better performance but it only returns PropertyDescriptors which don't seem to suit my case (or are too complex and provide an overhead).

    2. ASM - excellent for retrieving the content (fields values) BUT I need to see if the field has also a getter. Another approach is to get all the methods which start with "get" but I don't seem to have a hold of the Method itself - also invoking the getter through Method will ruin performance.

    3. CGLib has support for BeanMap which fits my requirements the most; the thing I'm missing is caching. In my scenario I'll work on a limited set of beans : once I have the match between fields and getters I can use that to avoid the overhead of lookup/matching fields and method names.

    I have searched google, Spring code but I couldn't find anything suitable - I feel like I'm missing something. For sure somebody had to deal with this before me and I would hate to reinvent the wheel (because it happens in a bad way usually).

    Thanks.
    Last edited by Costin Leau; Oct 28th, 2005, 06:45 AM.

  • #2
    I think jakarta commons beanutils is very useful for this.

    http://jakarta.apache.org/commons/beanutils/

    Specifically, the BeanUtils class.

    Comment


    • #3
      I've taked it into consideration but still I don't see how I can retrieve the getters (I need to know the fields values). Moreover I've checked briefly the sources and it uses standard reflection which is VERY slow on JDK 1.3 plus it doesn't seem to have any caching.

      Comment


      • #4
        As far as functionality, I think BeanUtils.describe will return return a Map with the property names as the keys.

        I cannot comment on the speed of BeanUtils, but I can say I have never had an issue with it.

        Comment


        • #5
          Thanks - I missed that from the javadocs. I'll give it a spin; however I hoped this functionally would be already part of Spring (one way or another).

          Comment


          • #6
            To tell you the truth, I'm not sure why spring's BeanUtils does not suit your needs. PropertyDescriptors do not seem very complex to me. If it's the name of the property you're looking for, you can simply call PropertyDescriptor.getName().

            Comment


            • #7
              Working with them is not a problem it's just that I'm trying to squeze as much performance as I can. I have POJOs with more then 30 fields sometime and I have to analyze their content inside an interceptor before reaching the database. Invoking readMethod 30 times is not very performant that's why I'm trying to find alternatives.
              However, I've narrowed down the functionality to 3 possible classes (right now I'm using CGLIB) so I'll do some benchmarks and see how everything goes.
              I can go further and read the field values directly, skipping the method but I have to see that I gain some real performance before I do that.

              Comment

              Working...
              X