Search in sources :

Example 1 with DeleteFieldManager

use of org.datanucleus.store.fieldmanager.DeleteFieldManager in project datanucleus-core by datanucleus.

the class StateManagerImpl method deletePersistent.

/**
 * Method to delete the object from persistence.
 */
public void deletePersistent() {
    if (!myLC.isDeleted()) {
        if (myEC.isDelayDatastoreOperationsEnabled()) {
            // Optimistic transactions, with all updates delayed til flush/commit
            if (myEC.operationQueueIsActive()) {
                myEC.addOperationToQueue(new DeleteOperation(this));
            }
            // Call any lifecycle listeners waiting for this event
            getCallbackHandler().preDelete(myPC);
            // Delay deletion until flush/commit so run reachability now to tag all reachable instances as necessary
            myEC.markDirty(this, false);
            // Reachability
            if (myLC.stateType() == LifeCycleState.P_CLEAN || myLC.stateType() == LifeCycleState.P_DIRTY || myLC.stateType() == LifeCycleState.HOLLOW || myLC.stateType() == LifeCycleState.P_NONTRANS || myLC.stateType() == LifeCycleState.P_NONTRANS_DIRTY) {
                // Make sure all fields are loaded so we can perform reachability
                loadUnloadedRelationFields();
            }
            flags |= FLAG_BECOMING_DELETED;
            // Run reachability for relations
            if (cmd.hasRelations(myEC.getClassLoaderResolver())) {
                provideFields(cmd.getAllMemberPositions(), new DeleteFieldManager(this));
            }
            // Update lifecycle state (after running reachability since it will unload all fields)
            dirty = true;
            preStateChange();
            try {
                // Keep "loadedFields" settings til after delete is complete to save reloading
                preDeleteLoadedFields = new boolean[loadedFields.length];
                for (int i = 0; i < preDeleteLoadedFields.length; i++) {
                    preDeleteLoadedFields[i] = loadedFields[i];
                }
                myLC = myLC.transitionDeletePersistent(this);
            } finally {
                flags &= ~FLAG_BECOMING_DELETED;
                postStateChange();
            }
        } else {
            // Datastore transactions, with all updates processed now
            // Call any lifecycle listeners waiting for this event.
            getCallbackHandler().preDelete(myPC);
            // Update lifecycle state
            dirty = true;
            preStateChange();
            try {
                // Keep "loadedFields" settings til after delete is complete to save reloading
                preDeleteLoadedFields = new boolean[loadedFields.length];
                for (int i = 0; i < preDeleteLoadedFields.length; i++) {
                    preDeleteLoadedFields[i] = loadedFields[i];
                }
                myLC = myLC.transitionDeletePersistent(this);
            } finally {
                postStateChange();
            }
            // TODO If this is an embedded object (cascaded from the owner) need to make sure we cascade as required
            // Delete the object from the datastore (includes reachability)
            internalDeletePersistent();
            // Call any lifecycle listeners waiting for this event.
            getCallbackHandler().postDelete(myPC);
        }
    }
}
Also used : DeleteOperation(org.datanucleus.flush.DeleteOperation) DeleteFieldManager(org.datanucleus.store.fieldmanager.DeleteFieldManager)

Aggregations

DeleteOperation (org.datanucleus.flush.DeleteOperation)1 DeleteFieldManager (org.datanucleus.store.fieldmanager.DeleteFieldManager)1