JPA and class enhancers

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Tue Mar 07 2006 - 04:45:53 EST

  • Next message: Andrus Adamchik: "M12, Wiki docs?"

    I did a little research on bytecode enhancement (CAY-460) and wanted
    to share some thoughts.

    It turned out that it is fairly simple to modify bytecode with the
    ASM framework:

    http://asm.objectweb.org/

    I checked in a basic enhancer that adds objectId and persistenceState
    properties to POJOs already. Coding the rest of the DataObject
    enhancements shouldn't be a problem, however ASM code is not
    something that is easy to maintain by hand (so if say
    CayenneDataObject changes internally, I'd like the enhancer to pick
    up such changes automatically). I guess we may implement some sort of
    template based approach. ASM allows to take an existing class X and
    generate regular Java code that can act as a script for creating
    class X bytcode from scratch. So theoretically an enhancer itself can
    be generated.

    BTW, ASM visitor API can be used for another purpose - processing
    annotations (CAY-456), thus solving two problems at once.

    Another issue is integrating the enhancer in the provider. The
    requirement is that enhanced classes must be accessible to the
    application ClassLoader, so my original solution with a specialized
    child ClassLoader won't work. I see three ways to do the integration
    (we may implement all three of them).

    1. "cgen" - by merging all CayenneDataObject code in the class
    generator template. This will work for people who use Cayenne to
    model their ORM classes, but want a superclass that is not a
    DataObject. This is not suitable for persistent classes created
    outside Cayenne and deployed with Cayenne provider.

    2. "cdeploy" - enhancing compiler Ant task ala JDO.

    3. Runtime - this would use JDK 1.5 java.lang.instrument API. On the
    one hand it is the least intrusive option, but on the other it
    requires a special runtime parameter (-javaagent:cayenne.jar).

    Ideas, comments?

    Andrus



    This archive was generated by hypermail 2.0.0 : Tue Mar 07 2006 - 04:46:05 EST