Java Reference
In-Depth Information
To configure the active fetch groups, you use a FetchPlan , which is accessed
by calling PersistenceManager.getFetchPlan() . You can, for example, call
FetchPlan.addGroup() to add a fetch group to the active fetch groups for the
PersistenceManager :
PersistenceManager pm = …;
FetchPlan fp = pm.getFetchPlan();
fp.addGroup("PendingOrder.withLineItems");
In this example, adding the fetch group we defined earlier to the set of active
fetch groups causes the PersistenceManager to load the pending order, its res-
taurant, its line items, and their menu items. Fetch groups are mostly a hint to the
JDO implementation when loading objects, but it is likely that a good JDO imple-
mentation would honor them.
Optimizing object loading in Kodo JDO
One of the challenges with using a new standard is that the implementations
sometimes lag behind. At the time of this writing, I didn't have access to a JDO
implementation that supported the JDO 2 custom fetch group mechanism; there-
fore, I needed to use a vendor-specific mechanism to dynamically configure eager
loading. But even though it is nonstandard, it illustrates the kinds of things you
will be able to do with JDO 2 fetch groups once they are supported.
Kodo JDO 3.3 provides a couple of ways to dynamically configuring eager load-
ing. It provides custom fetch groups that are similar to those supplied by JDO 2
but less flexible because a field can only belong to either the default fetch group
or to at most one custom fetch group. As a result, you cannot define multiple
fetch groups that have fields in common, which makes them quite difficult to use.
Fortunately, Kodo JDO also has a per-field fetch configuration mechanism that
lets you explicitly specify the fields that should be loaded eagerly. This mechanism
is more flexible than its custom fetch groups because you can specify an arbitrary
set of fields. To use this feature, you must downcast the PersistenceManager to a
KodoPersistenceManager and get its FetchConfiguration , which is similar to
the FetchPlan class discussed earlier. This class provides methods for specifying
the fields that should be loaded by its PersistenceManager . Here is an example
of how to arrange for the PendingOrder 's line items and restaurant to be eagerly
loaded:
PersistenceManager pm = …;
KodoPersistenceManager kpm = (KodoPersistenceManager)pm;
FetchConfiguration fc = pm.getFetchConfiguration();
fc.addField("net.chrisrichardson.foodToGo.PendingOrder.lineItems");
fc.addField("net.chrisrichardson.foodToGo.PendingOrder.restaurant");
 
 
 
 
 
Search WWH ::




Custom Search