Search in sources :

Example 16 with ApiAdapter

use of org.datanucleus.api.ApiAdapter in project datanucleus-core by datanucleus.

the class DeleteFieldManager method processMapContainer.

private void processMapContainer(int fieldNumber, Object container, AbstractMemberMetaData mmd, ContainerHandler<Object, MapContainerAdapter<Object>> containerHandler) {
    boolean dependentKey = mmd.getMap().isDependentKey();
    boolean dependentValue = mmd.getMap().isDependentValue();
    if (dependentKey && dependentValue) {
        ApiAdapter api = op.getExecutionContext().getApiAdapter();
        // Process all keys and values of the Map that are PC
        for (Entry<Object, Object> entry : containerHandler.getAdapter(container).entries()) {
            Object key = entry.getKey();
            if (api.isPersistable(key)) {
                processPersistable(key);
            }
            Object value = entry.getValue();
            if (api.isPersistable(value)) {
                processPersistable(key);
            }
        }
    } else if (dependentKey) {
        ApiAdapter api = op.getExecutionContext().getApiAdapter();
        // Process all keys of the Map that are PC
        for (Object key : containerHandler.getAdapter(container).keys()) {
            if (api.isPersistable(key)) {
                processPersistable(key);
            }
        }
    } else if (dependentValue) {
        ApiAdapter api = op.getExecutionContext().getApiAdapter();
        // Process all values of the Map that are PC
        for (Object value : containerHandler.getAdapter(container).values()) {
            if (api.isPersistable(value)) {
                processPersistable(value);
            }
        }
    }
// TODO Handle nulling of bidirs - Isn't being done by the relationship manager already?
}
Also used : ApiAdapter(org.datanucleus.api.ApiAdapter)

Example 17 with ApiAdapter

use of org.datanucleus.api.ApiAdapter in project datanucleus-core by datanucleus.

the class DetachFieldManager method processPersistableCopy.

/**
 * Utility method to process the passed persistable object creating a copy.
 * @param pc The PC object
 * @return The processed object
 */
protected Object processPersistableCopy(Object pc) {
    ExecutionContext ec = op.getExecutionContext();
    ApiAdapter api = ec.getApiAdapter();
    if (!api.isDetached(pc) && api.isPersistent(pc)) {
        // Detach a copy and return the copy
        return ec.detachObjectCopy(state, pc);
    }
    return pc;
}
Also used : ExecutionContext(org.datanucleus.ExecutionContext) ApiAdapter(org.datanucleus.api.ApiAdapter)

Example 18 with ApiAdapter

use of org.datanucleus.api.ApiAdapter in project datanucleus-core by datanucleus.

the class DetachFieldManager method endOfGraphOperation.

/**
 * Method to throw and EndOfFetchPlanGraphException since we're at the end of a branch in the tree.
 * @param fieldNumber Number of the field
 * @return Object to return
 */
protected Object endOfGraphOperation(int fieldNumber) {
    // check if the object here is PC and is in the detached cache anyway
    SingleValueFieldManager sfv = new SingleValueFieldManager();
    op.provideFields(new int[] { fieldNumber }, sfv);
    Object value = sfv.fetchObjectField(fieldNumber);
    ApiAdapter api = op.getExecutionContext().getApiAdapter();
    if (api.isPersistable(value)) {
        if (copy) {
            DetachState.Entry entry = ((DetachState) state).getDetachedCopyEntry(value);
            if (entry != null) {
                // While we are at the end of a branch and this would go beyond the depth limits, the object here *is* already detached so just return it
                return entry.getDetachedCopyObject();
            }
        } else if (op.getExecutionContext().getApiAdapter().isDetached(value)) {
            return value;
        }
    }
    // we reached a leaf of the object graph to detach
    throw new EndOfFetchPlanGraphException();
}
Also used : ApiAdapter(org.datanucleus.api.ApiAdapter) DetachState(org.datanucleus.DetachState)

Example 19 with ApiAdapter

use of org.datanucleus.api.ApiAdapter in project datanucleus-core by datanucleus.

the class DetachFieldManager method processPersistable.

/**
 * Utility method to process the passed persistable object.
 * @param pc The PC object
 */
protected void processPersistable(Object pc) {
    ExecutionContext ec = op.getExecutionContext();
    ApiAdapter api = ec.getApiAdapter();
    if (!api.isDetached(pc) && api.isPersistent(pc)) {
        // Persistent object that is not yet detached so detach it
        ec.detachObject(state, pc);
    }
}
Also used : ExecutionContext(org.datanucleus.ExecutionContext) ApiAdapter(org.datanucleus.api.ApiAdapter)

Example 20 with ApiAdapter

use of org.datanucleus.api.ApiAdapter in project datanucleus-core by datanucleus.

the class LoadFieldManager method processContainer.

private Object processContainer(int fieldNumber, Object container, AbstractMemberMetaData mmd) {
    Object wrappedContainer = container;
    if (mmd.hasArray()) {
        wrappedContainer = container;
    } else {
        if (!(container instanceof SCO)) {
            // Replace with SCO
            wrappedContainer = SCOUtils.wrapSCOField(op, fieldNumber, container, true);
        }
    }
    // Process all persistable objects in the container: elements,values and keys
    ExecutionContext ec = op.getExecutionContext();
    TypeManager typeManager = ec.getTypeManager();
    ContainerHandler containerHandler = typeManager.getContainerHandler(mmd.getType());
    ApiAdapter api = ec.getApiAdapter();
    for (Object object : containerHandler.getAdapter(wrappedContainer)) {
        if (api.isPersistable(object)) {
            processPersistable(object);
        }
    }
    return wrappedContainer;
}
Also used : ExecutionContext(org.datanucleus.ExecutionContext) ApiAdapter(org.datanucleus.api.ApiAdapter) ContainerHandler(org.datanucleus.store.types.ContainerHandler) TypeManager(org.datanucleus.store.types.TypeManager) SCO(org.datanucleus.store.types.SCO)

Aggregations

ApiAdapter (org.datanucleus.api.ApiAdapter)53 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)19 ObjectProvider (org.datanucleus.state.ObjectProvider)16 ExecutionContext (org.datanucleus.ExecutionContext)12 Map (java.util.Map)11 NucleusException (org.datanucleus.exceptions.NucleusException)11 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)10 Iterator (java.util.Iterator)8 NucleusObjectNotFoundException (org.datanucleus.exceptions.NucleusObjectNotFoundException)8 JavaTypeMapping (org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping)8 Collection (java.util.Collection)7 HashMap (java.util.HashMap)7 RelationType (org.datanucleus.metadata.RelationType)7 DatastoreClass (org.datanucleus.store.rdbms.table.DatastoreClass)7 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)6 ClassNotResolvedException (org.datanucleus.exceptions.ClassNotResolvedException)6 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)5 SQLExpression (org.datanucleus.store.rdbms.sql.expression.SQLExpression)5 TypeManager (org.datanucleus.store.types.TypeManager)5 SortedMap (java.util.SortedMap)4