datanucleus-enhancer provides bytecode enhancement of classes that will be involved in the persistence process. It adds in the necessary methods required to intercept changes in the objects hence providing the speed benefits of DataNucleus. It is merged into the datanucleus-core plugin as of version 3.2.0.m1 and, as such, is now inactive.
trunk can be checked out as follows
svn co https://datanucleus.svn.sourceforge.net/svnroot/datanucleus/platform/enhancer/trunk enhancer
datanucleus-enhancer is downloadable as following
datanucleus-enhancer is dependent on the following packages of software. Click on the name to go to the home page for that software to download it.
| Package | Version | Description | Required? |
|---|---|---|---|
| datanucleus-core | 3.0+ | Provides logging, localisation, and other framework facilities for DataNucleus. | Yes |
| datanucleus-api-jdo | 3.0+ | DataNucleus JDO API support | If enhancing for JDO |
| datanucleus-api-jpa | 3.0+ | DataNucleus JPA API support | If enhancing for JPA |
| JDO | 3.0+ | Apache JDO API. | Yes |
| ASM | 4.0+ | ASM byte code manipulation framework. This is used to byte code enhance the classes. v3.0 of the enhancer requires v3.x of ASM. | Yes |
| log4j | 1.2.x+ | Apache Log4J Logging framework. | No. Use it or JDK1.4 logging |
DataNucleus relies on classes implementing PersistenceCapable, and Detachable. Users could clearly do this manually but we provide the byte-code enhancement option. The DataNucleus Enhancer is structured to firstly determine from the input which classes are required to be enhanced, and secondly to enhance each class using the selected ClassEnhancer. DataNucleus has the ASMClassEnhancer (using ASM!).
ASM operates in a very similar way to BCEL, however is much more lightweight and operates using the same pattern as a SAX Parser and much faster. It uses a Visitor pattern. First the class is visited, then fields and methods, and finally an "end" point where you can add on any new fields/methods etc. The ASMClassEnhancer uses the JdoClassVisitor to obtain information about a class to be enhanced and adds on all required fields/methods.
A very useful utility when developing with ASM is its "Bytecode Outline" Eclipse plugin. To install it simply add an "Eclipse Update site" to your Eclipse config as "http://download.forge.objectweb.org/eclipse-update/" and the name "ObjectWeb". You then install the "Bytecode Outline" plugin. Once you have it installed select "Window" -> "Show View" -> "Other" -> "Java : Bytecode". This provides a window showing the Java bytecode for the class being edited. If you click on the "ASM" button on this window it shows you the ASM commands you would need to create the class, or a particular method/field!. This makes developing new ASMClassMethod implementations a doddle - just create a class with the method you want generating and then cut and paste the ASM code in.
If you ever need to check the byte-code enhanced class for correctness you can always decompile it back to the Java file. This can be done with a bytecode decompiler such as JD. Unpack the JD-GUI download so that you have the following
and invoke the following command
jd-gui
and select "Open", choosing a class file, and it shows the java code