JDO Byte Code Enhancement
by, 11-21-2011 at 05:39 PM (1364 Views)
In order to store instances of a class into data store, a class has to be persistence capable. There are different ways to make a class persistence capable. One of the way is Byte Code Enhancement.
When a Java class is compiled, a class file is generated. It contains the byte code. To make a class persistence capable, some extra code will surely be added to our source. In order to make the process transparent, byte code modification can be done. So this works even, if you dont have the source code.
JDO implementation provides tools that read a class file and insert additional byte code directly to make the class persistence-capable. The enhancement is a post compilation step and this approach is completely transparent to the Developer.
Lets go through the process. The Java classes are compiled using a Java compiler and we get class files. You have to provide JDO metadata (XML) the classes that will read by the byte code enhancement tool along with the class files. It then either updates the existing class files or creates new ones. The enhanced class files are then loaded by a JVM along with the JDO implementation and the application. The application can then use JDO to store instances of the persistence-capable classes in the data store.