Search in sources :

Example 1 with UnsetOwnerFieldManager

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

the class StateManagerImpl method makeTransient.

/**
 * Method to change the object state to transient.
 * @param state Object containing the state of any fetchplan processing
 */
public void makeTransient(FetchPlanState state) {
    if ((flags & FLAG_MAKING_TRANSIENT) != 0) {
        // In the process of becoming transient
        return;
    }
    try {
        flags |= FLAG_MAKING_TRANSIENT;
        if (state == null) {
            // No FetchPlan in use so just unset the owner of all loaded SCO fields
            int[] fieldNumbers = ClassUtils.getFlagsSetTo(loadedFields, cmd.getSCOMutableMemberPositions(), true);
            if (fieldNumbers != null && fieldNumbers.length > 0) {
                provideFields(fieldNumbers, new UnsetOwnerFieldManager());
            }
        } else {
            // Make all loaded SCO fields transient appropriate to this fetch plan
            loadUnloadedFieldsInFetchPlan();
            int[] fieldNumbers = ClassUtils.getFlagsSetTo(loadedFields, cmd.getAllMemberPositions(), true);
            if (fieldNumbers != null && fieldNumbers.length > 0) {
                // TODO Fix this to just access the fields of the FieldManager yet this actually does a replaceField
                replaceFields(fieldNumbers, new MakeTransientFieldManager(this, cmd.getSCOMutableMemberFlags(), myFP, state));
            }
        }
        preStateChange();
        try {
            myLC = myLC.transitionMakeTransient(this, state != null, myEC.isRunningDetachAllOnCommit());
        } finally {
            postStateChange();
        }
    } finally {
        flags &= ~FLAG_MAKING_TRANSIENT;
    }
}
Also used : MakeTransientFieldManager(org.datanucleus.store.fieldmanager.MakeTransientFieldManager) UnsetOwnerFieldManager(org.datanucleus.store.fieldmanager.UnsetOwnerFieldManager)

Example 2 with UnsetOwnerFieldManager

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

the class StateManagerImpl method clearNonPrimaryKeyFields.

/**
 * Method to clear all fields that are not part of the primary key of the object.
 */
public void clearNonPrimaryKeyFields() {
    try {
        getCallbackHandler().preClear(myPC);
    } finally {
        int[] nonpkFields = cmd.getNonPKMemberPositions();
        // Unset owner of any SCO wrapper so if the user holds on to a wrapper it doesn't affect the datastore
        int[] nonPkScoFields = ClassUtils.getFlagsSetTo(cmd.getSCOMutableMemberFlags(), ClassUtils.getFlagsSetTo(loadedFields, cmd.getNonPKMemberPositions(), true), true);
        if (nonPkScoFields != null) {
            provideFields(nonPkScoFields, new UnsetOwnerFieldManager());
        }
        clearFieldsByNumbers(nonpkFields);
        clearDirtyFlags(nonpkFields);
        if (myEC.getStoreManager() instanceof ObjectReferencingStoreManager) {
            // For datastores that manage the object reference
            ((ObjectReferencingStoreManager) myEC.getStoreManager()).notifyObjectIsOutdated(this);
        }
        persistenceFlags = Persistable.LOAD_REQUIRED;
        myPC.dnReplaceFlags();
        getCallbackHandler().postClear(myPC);
    }
}
Also used : UnsetOwnerFieldManager(org.datanucleus.store.fieldmanager.UnsetOwnerFieldManager) ObjectReferencingStoreManager(org.datanucleus.store.ObjectReferencingStoreManager)

Example 3 with UnsetOwnerFieldManager

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

the class StateManagerImpl method disconnect.

/**
 * Disconnect from the ExecutionContext and persistable object.
 */
public void disconnect() {
    if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
        NucleusLogger.PERSISTENCE.debug(Localiser.msg("026011", StringUtils.toJVMIDString(myPC), this));
    }
    // fields were loaded during this action which triggered a dnPostLoad event
    if (isPostLoadPending()) {
        // hack to make sure postLoad does not return without processing
        flags &= ~FLAG_CHANGING_STATE;
        setPostLoadPending(false);
        postLoad();
    }
    // Call unsetOwner() on all loaded SCO fields.
    int[] fieldNumbers = ClassUtils.getFlagsSetTo(loadedFields, cmd.getSCOMutableMemberPositions(), true);
    if (fieldNumbers != null && fieldNumbers.length > 0) {
        provideFields(fieldNumbers, new UnsetOwnerFieldManager());
    }
    myEC.removeObjectProviderFromCache(this);
    persistenceFlags = Persistable.READ_WRITE_OK;
    myPC.dnReplaceFlags();
    flags |= FLAG_DISCONNECTING;
    try {
        replaceStateManager(myPC, null);
    } finally {
        flags &= ~FLAG_DISCONNECTING;
    }
    clearSavedFields();
    preDeleteLoadedFields = null;
    objectType = 0;
    myPC = null;
    myID = null;
    myInternalID = null;
    myLC = null;
    myEC = null;
    myFP = null;
    myVersion = null;
    persistenceFlags = 0;
    flags = 0;
    transactionalVersion = null;
    currFM = null;
    dirty = false;
    cmd = null;
    dirtyFields = null;
    loadedFields = null;
// TODO Remove the object from any pooling (when we enable it) via nucCtx.getObjectProviderFactory().disconnectObjectProvider(this);
}
Also used : UnsetOwnerFieldManager(org.datanucleus.store.fieldmanager.UnsetOwnerFieldManager)

Aggregations

UnsetOwnerFieldManager (org.datanucleus.store.fieldmanager.UnsetOwnerFieldManager)3 ObjectReferencingStoreManager (org.datanucleus.store.ObjectReferencingStoreManager)1 MakeTransientFieldManager (org.datanucleus.store.fieldmanager.MakeTransientFieldManager)1