Java Reference
In-Depth Information
Order attach(Order order);
}
In addition to detaching the order, the
detach()
method also detaches the order's
restaurant, its line items, and their menu items so that they can be displayed to
the user. There are Hibernate and
JDO
implementations of this interface.
Using JDO detached objects
Listing 13.2 shows the
JDO
version of the
OrderAttachmentManager
. It detaches
orders by using a
JdoTemplate
to execute a
KodoJDODetachObjectCallback
, which is
the class we first saw in chapter 7 that uses the Kodo
JDO
detachment
API
.
Order-
AttachmentManager
attaches orders by executing a
KodoJDOAttachObjectCallback
that is similar to a
KodoJDODetachObjectCallback
. The list of fields to detach is
passed into the
JDOOrderAttachmentManager
using dependency injection.
Listing 13.2
JDOOrderAttachmentManager
public class JDOOrderAttachmentManager implements
OrderAttachmentManager {
private String[] fieldsOrFetchGroups;
private JdoTemplate jdoTemplate;
public JDOOrderAttachmentManager(
JdoTemplate jdoTemplate,
String[] fieldsOrFetchGroups) {
this.jdoTemplate = jdoTemplate;
this.fieldsOrFetchGroups = fieldsOrFetchGroups;
}
public Order detach(Order order) {
return (Order) jdoTemplate
.execute(new KodoJDODetachObjectCallback(
order, fieldsOrFetchGroups));
}
public Order attach(Order order) {
return (Order) jdoTemplate
.execute(new KodoJDOAttachObjectCallback(
order));
}
}
Both the
detach()
and
attach()
methods instantiate and execute a
JdoCallback
that calls Kodo
JDO
.
Search WWH ::
Custom Search