Enhancement Approaches
You may not be familiar with class enhancement, but it is not JDO-specific and it has been applied in other software technologies. There are several approaches that can be used to enhance a class. Enhancement can be performed by:
Implementing enhancement yourself manually
Using a source-code enhancer
Using a byte-code enhancer
Each enhancement approach requires access to the JDO metadata you have defined.
You may explicitly declare that your class implements PersistenceCapable
. In this case, you need to
implement the PersistenceCapable
contract fully, as specified by the JDO specification. An enhancer
ignores a class if you have explicitly declared that it implements
PersistenceCapable
. We do not recommend this approach; it is tedious and
error-prone.
A source-code enhancer reads your original source code and adds the source necessary to support the JDO enhancement contract. The revised source is compiled and is then ready for execution in a JDO environment. At the time this book was written, only one vendor supported a source-code enhancer; the vender also supported a byte-code enhancer.
The most common approach for enhancing a class is to use a JDO
byte-code enhancer. It reads a class file produced by the Java compiler
and generates a new class file that has been enhanced. With a byte-code
enhancer, you can make classes persistent even if you do not have the
source code. Figure 6-1
illustrates the process of using a byte-code enhancer to enhance the
Movie
class. ...
Get Java Data Objects now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.