Search in sources :

Example 1 with PersistFieldManager

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

the class StateManagerImpl method makePersistent.

// ------------------------- Lifecycle Methods -----------------------------
/**
 * Method to make the object persistent.
 */
public void makePersistent() {
    if (myLC.isDeleted() && !myEC.getNucleusContext().getApiAdapter().allowPersistOfDeletedObject()) {
        // API doesnt allow repersist of deleted objects
        return;
    }
    if (activity != ActivityState.NONE) {
        // Already making persistent
        return;
    }
    if (myEC.operationQueueIsActive()) {
        myEC.addOperationToQueue(new PersistOperation(this));
    }
    if (dirty && !myLC.isDeleted() && myLC.isTransactional() && myEC.isDelayDatastoreOperationsEnabled()) {
        // to bring in any new objects that are now reachable
        if (cmd.hasRelations(myEC.getClassLoaderResolver())) {
            provideFields(cmd.getAllMemberPositions(), new PersistFieldManager(this, false));
        }
        return;
    }
    getCallbackHandler().prePersist(myPC);
    if (isFlushedNew()) {
        // With CompoundIdentity bidir relations when the SM is created for this object ("initialiseForPersistentNew") the persist
        // of the PK PC fields can cause the flush of this object, and so it is already persisted by the time we ge here
        registerTransactional();
        return;
    }
    if (cmd.isEmbeddedOnly()) {
        // Cant persist an object of this type since can only be embedded
        return;
    }
    // If this is an embedded/serialised object becoming persistent in its own right, assign an identity.
    if (myID == null) {
        setIdentity(false);
    }
    dirty = true;
    if (myEC.isDelayDatastoreOperationsEnabled()) {
        // Delaying datastore flush til later
        myEC.markDirty(this, false);
        if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
            NucleusLogger.PERSISTENCE.debug(Localiser.msg("026028", StringUtils.toJVMIDString(myPC)));
        }
        registerTransactional();
        if (myLC.isTransactional() && myLC.isDeleted()) {
            // Re-persist of a previously deleted object
            myLC = myLC.transitionMakePersistent(this);
        }
        if (cmd.hasRelations(myEC.getClassLoaderResolver())) {
            // Run reachability on all fields of this PC - JDO2 [12.6.7]
            provideFields(cmd.getAllMemberPositions(), new PersistFieldManager(this, false));
        }
    } else {
        // Persist the object and all reachables
        internalMakePersistent();
        registerTransactional();
    }
}
Also used : PersistOperation(org.datanucleus.flush.PersistOperation) PersistFieldManager(org.datanucleus.store.fieldmanager.PersistFieldManager)

Aggregations

PersistOperation (org.datanucleus.flush.PersistOperation)1 PersistFieldManager (org.datanucleus.store.fieldmanager.PersistFieldManager)1