Search in sources :

Example 1 with SingleValueFieldManager

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

the class StateManagerImpl method loadUnloadedFields.

/**
 * Fetch from the database all fields that are not currently loaded regardless of whether
 * they are in the current fetch group or not. Called by lifecycle transitions.
 */
public void loadUnloadedFields() {
    int[] fieldNumbers = ClassUtils.getFlagsSetTo(loadedFields, cmd.getAllMemberPositions(), false);
    if (fieldNumbers == null || fieldNumbers.length == 0) {
        // All loaded so return
        return;
    }
    if (preDeleteLoadedFields != null && ((myLC.isDeleted() && myEC.isFlushing()) || activity == ActivityState.DELETING)) {
        // During deletion process so we know what is really loaded so only load if necessary
        fieldNumbers = ClassUtils.getFlagsSetTo(preDeleteLoadedFields, fieldNumbers, false);
    }
    if (fieldNumbers != null && fieldNumbers.length > 0) {
        boolean callPostLoad = myFP.isToCallPostLoadFetchPlan(this.loadedFields);
        int[] unloadedFieldNumbers = loadFieldsFromLevel2Cache(fieldNumbers);
        if (unloadedFieldNumbers != null) {
            loadFieldsFromDatastore(unloadedFieldNumbers);
        }
        // Make sure all SCO lazy-loaded fields have contents loaded
        int[] secondClassMutableFieldNumbers = cmd.getSCOMutableMemberPositions();
        for (int i = 0; i < secondClassMutableFieldNumbers.length; i++) {
            SingleValueFieldManager sfv = new SingleValueFieldManager();
            provideFields(new int[] { secondClassMutableFieldNumbers[i] }, sfv);
            Object value = sfv.fetchObjectField(i);
            if (value instanceof SCOContainer) {
                ((SCOContainer) value).load();
            }
        }
        updateLevel2CacheForFields(fieldNumbers);
        if (callPostLoad) {
            postLoad();
        }
    }
}
Also used : SCOContainer(org.datanucleus.store.types.SCOContainer) SingleValueFieldManager(org.datanucleus.store.fieldmanager.SingleValueFieldManager)

Example 2 with SingleValueFieldManager

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

the class StateManagerImpl method replaceField.

/**
 * Method to change the value of a field in the PC object.
 * @param pc The PC object
 * @param fieldNumber Number of field
 * @param value The new value of the field
 */
protected void replaceField(Persistable pc, int fieldNumber, Object value) {
    try {
        if (myEC.getMultithreaded()) {
            myEC.getLock().lock();
            lock.lock();
        }
        // Update the field in our PC object
        FieldManager prevFM = currFM;
        currFM = new SingleValueFieldManager();
        try {
            currFM.storeObjectField(fieldNumber, value);
            pc.dnReplaceField(fieldNumber);
        } finally {
            currFM = prevFM;
        }
    } finally {
        if (myEC.getMultithreaded()) {
            lock.unlock();
            myEC.getLock().unlock();
        }
    }
}
Also used : LoadFieldManager(org.datanucleus.store.fieldmanager.LoadFieldManager) MakeTransientFieldManager(org.datanucleus.store.fieldmanager.MakeTransientFieldManager) AttachFieldManager(org.datanucleus.store.fieldmanager.AttachFieldManager) UnsetOwnerFieldManager(org.datanucleus.store.fieldmanager.UnsetOwnerFieldManager) DetachFieldManager(org.datanucleus.store.fieldmanager.DetachFieldManager) PersistFieldManager(org.datanucleus.store.fieldmanager.PersistFieldManager) SingleValueFieldManager(org.datanucleus.store.fieldmanager.SingleValueFieldManager) DeleteFieldManager(org.datanucleus.store.fieldmanager.DeleteFieldManager) L2CachePopulateFieldManager(org.datanucleus.cache.L2CachePopulateFieldManager) FieldManager(org.datanucleus.store.fieldmanager.FieldManager) SingleTypeFieldManager(org.datanucleus.store.fieldmanager.SingleTypeFieldManager) L2CacheRetrieveFieldManager(org.datanucleus.cache.L2CacheRetrieveFieldManager) SingleValueFieldManager(org.datanucleus.store.fieldmanager.SingleValueFieldManager)

Example 3 with SingleValueFieldManager

use of org.datanucleus.store.fieldmanager.SingleValueFieldManager in project datanucleus-rdbms by datanucleus.

the class PersistableMapping method getValueForDatastoreMapping.

/**
 * Method to return the value to be stored in the specified datastore index given the overall value for this java type.
 * @param nucleusCtx Context
 * @param index The datastore index
 * @param value The overall value for this java type
 * @return The value for this datastore index
 */
public Object getValueForDatastoreMapping(NucleusContext nucleusCtx, int index, Object value) {
    ExecutionContext ec = nucleusCtx.getApiAdapter().getExecutionContext(value);
    if (cmd == null) {
        cmd = nucleusCtx.getMetaDataManager().getMetaDataForClass(getType(), ec != null ? ec.getClassLoaderResolver() : nucleusCtx.getClassLoaderResolver(null));
    }
    if (cmd.getIdentityType() == IdentityType.APPLICATION) {
        AbstractMemberMetaData mmd = cmd.getMetaDataForManagedMemberAtAbsolutePosition(cmd.getPKMemberPositions()[index]);
        ObjectProvider op = null;
        if (ec != null) {
            op = ec.findObjectProvider(value);
        }
        if (op == null) {
            // Transient or detached maybe, so use reflection to get PK field values
            if (mmd instanceof FieldMetaData) {
                return ClassUtils.getValueOfFieldByReflection(value, mmd.getName());
            }
            return ClassUtils.getValueOfMethodByReflection(value, ClassUtils.getJavaBeanGetterName(mmd.getName(), false));
        }
        if (!mmd.isPrimaryKey()) {
            // Make sure the field is loaded
            op.isLoaded(mmd.getAbsoluteFieldNumber());
        }
        FieldManager fm = new SingleValueFieldManager();
        op.provideFields(new int[] { mmd.getAbsoluteFieldNumber() }, fm);
        return fm.fetchObjectField(mmd.getAbsoluteFieldNumber());
    } else if (cmd.getIdentityType() == IdentityType.DATASTORE) {
        Object id = nucleusCtx.getApiAdapter().getIdForObject(value);
        return id != null ? IdentityUtils.getTargetKeyForDatastoreIdentity(id) : null;
    }
    return null;
}
Also used : FieldMetaData(org.datanucleus.metadata.FieldMetaData) ExecutionContext(org.datanucleus.ExecutionContext) AppIDObjectIdFieldManager(org.datanucleus.store.rdbms.mapping.AppIDObjectIdFieldManager) SingleValueFieldManager(org.datanucleus.store.fieldmanager.SingleValueFieldManager) FieldManager(org.datanucleus.store.fieldmanager.FieldManager) SingleValueFieldManager(org.datanucleus.store.fieldmanager.SingleValueFieldManager) ObjectProvider(org.datanucleus.state.ObjectProvider) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData)

Example 4 with SingleValueFieldManager

use of org.datanucleus.store.fieldmanager.SingleValueFieldManager in project datanucleus-rdbms by datanucleus.

the class ExpressionUtils method getValueForMemberOfObject.

/**
 * Get the value of a managed field/property in the provided object.
 * @param ec execution context
 * @param mmd metadata for the field/property
 * @param object the pc object
 * @return The field value
 */
public static Object getValueForMemberOfObject(ExecutionContext ec, AbstractMemberMetaData mmd, Object object) {
    if (ec == null) {
        // Transient or detached maybe
        return ClassUtils.getValueOfFieldByReflection(object, mmd.getName());
    // TODO What if this is a property?
    }
    ObjectProvider sm = ec.findObjectProvider(object);
    if (!mmd.isPrimaryKey()) {
        // Make sure the field is loaded
        sm.isLoaded(mmd.getAbsoluteFieldNumber());
    }
    FieldManager fm = new SingleValueFieldManager();
    sm.provideFields(new int[] { mmd.getAbsoluteFieldNumber() }, fm);
    return fm.fetchObjectField(mmd.getAbsoluteFieldNumber());
}
Also used : SingleValueFieldManager(org.datanucleus.store.fieldmanager.SingleValueFieldManager) FieldManager(org.datanucleus.store.fieldmanager.FieldManager) SingleValueFieldManager(org.datanucleus.store.fieldmanager.SingleValueFieldManager) ObjectProvider(org.datanucleus.state.ObjectProvider)

Example 5 with SingleValueFieldManager

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

the class StateManagerImpl method provideField.

/**
 * Method to retrieve the value of a field from the PC object. Assumes that it is loaded.
 * @param pc The PC object
 * @param fieldNumber Number of field
 * @return The value of the field
 */
protected Object provideField(Persistable pc, int fieldNumber) {
    Object obj;
    try {
        if (myEC.getMultithreaded()) {
            myEC.getLock().lock();
            lock.lock();
        }
        FieldManager prevFM = currFM;
        currFM = new SingleValueFieldManager();
        try {
            pc.dnProvideField(fieldNumber);
            obj = currFM.fetchObjectField(fieldNumber);
        } finally {
            currFM = prevFM;
        }
    } finally {
        if (myEC.getMultithreaded()) {
            lock.unlock();
            myEC.getLock().unlock();
        }
    }
    return obj;
}
Also used : LoadFieldManager(org.datanucleus.store.fieldmanager.LoadFieldManager) MakeTransientFieldManager(org.datanucleus.store.fieldmanager.MakeTransientFieldManager) AttachFieldManager(org.datanucleus.store.fieldmanager.AttachFieldManager) UnsetOwnerFieldManager(org.datanucleus.store.fieldmanager.UnsetOwnerFieldManager) DetachFieldManager(org.datanucleus.store.fieldmanager.DetachFieldManager) PersistFieldManager(org.datanucleus.store.fieldmanager.PersistFieldManager) SingleValueFieldManager(org.datanucleus.store.fieldmanager.SingleValueFieldManager) DeleteFieldManager(org.datanucleus.store.fieldmanager.DeleteFieldManager) L2CachePopulateFieldManager(org.datanucleus.cache.L2CachePopulateFieldManager) FieldManager(org.datanucleus.store.fieldmanager.FieldManager) SingleTypeFieldManager(org.datanucleus.store.fieldmanager.SingleTypeFieldManager) L2CacheRetrieveFieldManager(org.datanucleus.cache.L2CacheRetrieveFieldManager) SingleValueFieldManager(org.datanucleus.store.fieldmanager.SingleValueFieldManager)

Aggregations

SingleValueFieldManager (org.datanucleus.store.fieldmanager.SingleValueFieldManager)7 FieldManager (org.datanucleus.store.fieldmanager.FieldManager)5 L2CachePopulateFieldManager (org.datanucleus.cache.L2CachePopulateFieldManager)3 L2CacheRetrieveFieldManager (org.datanucleus.cache.L2CacheRetrieveFieldManager)3 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)3 AttachFieldManager (org.datanucleus.store.fieldmanager.AttachFieldManager)3 DeleteFieldManager (org.datanucleus.store.fieldmanager.DeleteFieldManager)3 DetachFieldManager (org.datanucleus.store.fieldmanager.DetachFieldManager)3 LoadFieldManager (org.datanucleus.store.fieldmanager.LoadFieldManager)3 MakeTransientFieldManager (org.datanucleus.store.fieldmanager.MakeTransientFieldManager)3 PersistFieldManager (org.datanucleus.store.fieldmanager.PersistFieldManager)3 SingleTypeFieldManager (org.datanucleus.store.fieldmanager.SingleTypeFieldManager)3 UnsetOwnerFieldManager (org.datanucleus.store.fieldmanager.UnsetOwnerFieldManager)3 ObjectProvider (org.datanucleus.state.ObjectProvider)2 SCOContainer (org.datanucleus.store.types.SCOContainer)2 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)1 ExecutionContext (org.datanucleus.ExecutionContext)1 Persistable (org.datanucleus.enhancement.Persistable)1 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)1 FieldMetaData (org.datanucleus.metadata.FieldMetaData)1