Java Reference
In-Depth Information
The default-fetch-group="true" attribute specifies that the restaurant field
is a member of the PendingOrder 's default fetch group. A JDO implementation
typically loads a PendingOrder by executing a SELECT table that does a join
between the PENDING_ORDER and RESTAURANT tables. The PendingOrderLi-
neItem - MenuItem is configured in a similar fashion. Once we have configured the
fetch groups, the JDO implementation will load the related objects using a SQL join.
Adding a field to the default fetch group is a useful way to improve perfor-
mance if the relationship is always traversed when the referencing object is
loaded. However, if different requests traverse different relationships, then the
default fetch group mechanism isn't all that useful. We must instead use custom
fetch groups to dynamically control eager loading.
Using custom fetch groups to optimize object loading
A custom fetch group is defined in the XML metadata for a class and specifies one
or more of the class's fields and possibly one or more other fetch groups. An
application tells JDO to eagerly load the relationships specified by a custom fetch
group by activating the fetch group programmatically. For example, when han-
dling the update payment information request the application needs to eagerly
load the pending order's lineItems and their menu items in addition to its res-
taurants. It can do this using the following custom fetch group:
<class name="PendingOrder" identity-type="application">
<fetch-group name="PendingOrder.withLineItems">
<field name="lineItems"/>
</fetch-group>
</class>
Note that because the PendingOrder.restaurant and PendingOrderLine-
Item.menuItem fields already belong to the default fetch group, they do not
need to be specified in the custom fetch group.
Once you have defined a custom fetch group, you can use it to eagerly load
those objects by writing code to add it to the PersistenceManager 's active fetch
groups, which control which objects and fields are loaded. By default, the
“default” fetch group is the only active fetch group, which is how fields that
belong to the default fetch group are loaded. However, if there is an active fetch
group that contains a field that is a reference to another object, the JDO imple-
mentation will eagerly load that object in addition to any objects referenced by
fields in the default fetch group.
 
 
 
Search WWH ::




Custom Search