Java Reference
In-Depth Information
KodoJDODetachObjectCallback
The KodoJDODetachObjectCallback , which is shown in listing 7.3, is used by the
JDOPlaceOrderResultFactory to detach the PendingOrder . Because it's a JdoCall-
back , it has a doInJdo() method, which is passed a JDO PersistenceManager by
the JdoTemplate . This method downcasts the PersistenceManager to a KodoPer-
sistenceManager and configures the FetchConfiguration with the specified
fields. After detaching the objects, it undoes the changes it made to the Fetch-
Configuration so that any other callers of the PersistenceManager can use the
default configuration.
Listing 7.3
KodoJDODetachObjectCallback
public class KodoJDODetachObjectCallback implements JdoCallback {
private final String[] fields;
private final Object object;
KodoJDODetachObjectCallback(Object object, String[] fields) {
this.object = object;
this.fields = fields;
}
public Object doInJdo(PersistenceManager pm)
throws JDOException {
KodoPersistenceManager kodoPM = (KodoPersistenceManager) pm;
if (object == null)
return null;
FetchConfiguration fc = kodoPM.getFetchConfiguration();
String[] oldFields = fc.getFields();
if (fields != null) {
fc.addFields(fields);
}
try {
return (Object) kodoPM.detach(object);
} finally {
if (fields != null) {
fc.clearFields();
fc.addFields(oldFields);
}
}
}
}
Search WWH ::




Custom Search