use of javax.jdo.listener.StoreCallback in project datanucleus-api-jdo by datanucleus.
the class JDOCallbackHandler method preStore.
/**
* Callback before the object is stored.
* @param pc The Object
*/
public void preStore(Object pc) {
for (LifecycleListenerForClass listener : getListenersWorkingCopy()) {
if (listener.forClass(pc.getClass()) && listener.getListener() instanceof StoreLifecycleListener) {
ExecutionContext ec = nucleusCtx.getApiAdapter().getExecutionContext(pc);
String[] fieldNames = null;
// PRE_STORE will return the fields being stored (DataNucleus extension)
ObjectProvider op = ec.findObjectProvider(pc);
fieldNames = op.getDirtyFieldNames();
if (fieldNames == null) {
// Must be persisting so just return all loaded fields
fieldNames = op.getLoadedFieldNames();
}
((StoreLifecycleListener) listener.getListener()).preStore(new FieldInstanceLifecycleEvent(pc, InstanceLifecycleEvent.STORE, null, fieldNames));
}
}
if (pc instanceof StoreCallback) {
try {
((StoreCallback) pc).jdoPreStore();
} catch (Exception e) {
throw new JDOUserCallbackException(Localiser.msg("025001", "jdoPreStore"), e);
}
}
if (beanValidationHandler != null) {
ObjectProvider op = nucleusCtx.getApiAdapter().getExecutionContext(pc).findObjectProvider(pc);
if (!op.getLifecycleState().isNew()) {
// Don't fire this when persisting new since we will have done prePersist
beanValidationHandler.preStore(pc);
}
}
}
Aggregations