Java Reference
In-Depth Information
G
The changeQuantities() method changes the line item quantities, which
deletes the existing line items and creates new ones.
The deletePendingOrder() method deletes the PendingOrder , which should
also delete the line items.
This test corresponds to one possible scenario in the lifetime of a pending order.
In order to thoroughly test the PendingOrder class, we would also need to write
other tests, such as one that calls updatePaymentInfo() with a Coupon . Although
developing these tests can be time consuming, they are an important part of the
test suite for JDO persistence layer. As with the O/R mapping tests, you can start
off by writing a simple test that creates and saves a PendingOrder and then add
more comprehensive tests over time. Let's look at what we have to do in order to
get these tests to pass.
H
5.2.3
Making a class persistent
Developing the persistence tests is, in some ways, the most challenging and time-
consuming part of making a class persistent. Getting them to pass is comparatively
easy. To do that, we must make some changes to the PendingOrder class and
write the JDO XML metadata files that define its object/relational mapping.
Modifying the class
We need to modify the PendingOrder in order to be able to persist it. Because we
have decided to use application identity, we have to add an ID field, which stores
the primary key, and a getter that returns its value. Here are the changes:
public class PendingOrder {
private int id;
private int getId() {
return id;
}
The rest of the class is unchanged.
Defining the O/R mapping
The final step in persisting the PendingOrder class is writing the JDO XML meta-
data that maps the PendingOrder class to the database schema and specifies vari-
ous aspects of the class, including the JDO identity type and how to generate the
primary key. Some JDO implementations provide GUI tools that help with this, but
it is fairly easy to do by hand.
 
 
 
 
Search WWH ::




Custom Search