Java Reference
In-Depth Information
model with CMP entity beans. Although quite a few design workarounds (or design patterns) have been
proposed in the recent years, none of them eliminates this fundamental limitation.
As a Java developer, you certainly favor a mechanism that abstracts away any persistent details and
has a clean, simple, object-oriented API to perform data persistence. With the recent official release of
the JDO specification, you finally have an object-oriented, data-persistent mechanism to use.
Since the JDO persistent classes are simply Java classes, you build your domain model as usual and
without worrying about the details of data persistence. This can be illustrated by using a classic example.
Assume you have three classes: Employee , ParttimeEmployee and FulltimeEmployee . Their
relationship is shown in Figure 23-1 .
Figure 23-1: Class diagrams of the employee object model
The employee name is common for both part-time and full-time employees and thus is defined in the
base class. The part -time employee is paid by hour and has an attribute hourlyRate . The full-time
employ is paid by annual salary and hence has an attribute salary . An abstract method,
computeBiweeklyPay() , is defined in the base class, and the implementation is provided in the
subclasses. The implementations of this method are certainly different in two subclasses. For example,
the part-time employee may be paid simple by the hours worked multiplied by the hourly rate. For the
full-time employees, you may have to deduct all payroll deductions, and you may also have to handle
holidays and vacations differently from the working days.
The coding of these persistent classes is straightforward. After you have written these classes, you
need to tell the JDO enhancer that they should be persisted. Your XML MetaData file may look like the
following:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jdo SYSTEM "jdo.dtd">
<jdo>
<package name="java_database.jdo">
<class name="Employee">
</class>
<class name="ParttimeEmployee" persistence-capable-
superclass="Employee">
</class>
<class name="FulltimeEmployee" persistence-capable-
superclass="Employee">
</class>
</package>
</jdo>
Search WWH ::




Custom Search