Java Reference
In-Depth Information
JDOPlaceOrderFacadeResultFactory
The
JDOPlaceOrderFacadeResultFactory
, which is shown in listing 7.2, is a simple
class. It uses a Spring
JdoTemplate
to execute the
KodoJDODetachObjectCallback
. To
completely decouple the code from the object graph that must be detached, we pass
in the names of the relationship fields to detach using dependency injection.
Listing 7.2
JDOPlaceOrderFacadeResultFactory
public class JDOPlaceOrderFacadeResultFactory implements
PlaceOrderFacadeResultFactory {
private final String[] fieldsToDetach;
public JDOPlaceOrderFacadeResultFactory(
JdoTemplate jdoTemplate,
String[] fieldsToDetach) {
setJdoTemplate(jdoTemplate);
this.fieldsToDetach = fieldsToDetach;
}
public PlaceOrderFacadeResult make(
int statusCode,
PendingOrder pendingOrder) {
PendingOrder detachedPendingOrder =
detachPendingOrder(pendingOrder);
return new PlaceOrderFacadeResult(statusCode,
detachedPendingOrder);
}
private PendingOrder detachPendingOrder(
PendingOrder pendingOrder) {
return (PendingOrder) getJdoTemplate()
.execute(
new KodoJDODetachObjectCallback(
pendingOrder,
fieldsToDetach));
}
}
JDOPlaceOrderFacadeResultFactory
has a constructor that takes a
JdoTemplate
and the names of the fields to detach as parameters. It stores the
JdoTemplate
by
calling
setJdoTemplate()
, which is provided by its superclass. The
detachPending-
Order()
method instantiates the
KodoJDODetachObjectCallback
with the
Pending-
Order
and field names to detach and passes it to the
JdoTemplate
.
Search WWH ::
Custom Search