Search in sources :

Example 1 with StoreCallback

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);
        }
    }
}
Also used : JDOUserCallbackException(javax.jdo.JDOUserCallbackException) ExecutionContext(org.datanucleus.ExecutionContext) StoreLifecycleListener(javax.jdo.listener.StoreLifecycleListener) StoreCallback(javax.jdo.listener.StoreCallback) ObjectProvider(org.datanucleus.state.ObjectProvider) JDOUserCallbackException(javax.jdo.JDOUserCallbackException)

Aggregations

JDOUserCallbackException (javax.jdo.JDOUserCallbackException)1 StoreCallback (javax.jdo.listener.StoreCallback)1 StoreLifecycleListener (javax.jdo.listener.StoreLifecycleListener)1 ExecutionContext (org.datanucleus.ExecutionContext)1 ObjectProvider (org.datanucleus.state.ObjectProvider)1