Search in sources :

Example 6 with TypeManager

use of org.datanucleus.store.types.TypeManager in project datanucleus-core by datanucleus.

the class DeleteFieldManager method processContainer.

private void processContainer(int fieldNumber, Object container, AbstractMemberMetaData mmd, ExecutionContext ec, RelationType relationType) {
    TypeManager typeManager = op.getExecutionContext().getTypeManager();
    ContainerHandler containerHandler = typeManager.getContainerHandler(mmd.getType());
    if (mmd.hasMap()) {
        processMapContainer(fieldNumber, container, mmd, containerHandler);
    } else {
        processElementContainer(fieldNumber, container, mmd, containerHandler, ec, relationType);
    }
}
Also used : ContainerHandler(org.datanucleus.store.types.ContainerHandler) ElementContainerHandler(org.datanucleus.store.types.ElementContainerHandler) TypeManager(org.datanucleus.store.types.TypeManager)

Example 7 with TypeManager

use of org.datanucleus.store.types.TypeManager 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)

Example 8 with TypeManager

use of org.datanucleus.store.types.TypeManager in project datanucleus-core by datanucleus.

the class MakeTransientFieldManager method internalFetchObjectField.

/**
 * Method to fetch an object field whether it is SCO collection, PC, or whatever for the fetchplan process.
 * @param fieldNumber Number of the field
 * @return The object
 */
protected Object internalFetchObjectField(int fieldNumber) {
    SingleValueFieldManager sfv = new SingleValueFieldManager();
    op.provideFields(new int[] { fieldNumber }, sfv);
    Object value = sfv.fetchObjectField(fieldNumber);
    if (value != null) {
        AbstractMemberMetaData mmd = op.getClassMetaData().getMetaDataForManagedMemberAtAbsolutePosition(fieldNumber);
        RelationType relType = mmd.getRelationType(op.getExecutionContext().getClassLoaderResolver());
        if (relType != RelationType.NONE) {
            if (mmd.hasContainer()) {
                // Replace with SCO, when possible
                value = SCOUtils.wrapSCOField(op, fieldNumber, value, true);
                TypeManager typeManager = op.getExecutionContext().getTypeManager();
                ContainerAdapter containerAdapter = typeManager.getContainerAdapter(value);
                ApiAdapter api = op.getExecutionContext().getApiAdapter();
                // Process all elements of the Container that are PC
                for (Object object : containerAdapter) {
                    if (api.isPersistable(object)) {
                        processPersistable(object);
                    }
                }
            } else {
                processPersistable(value);
            }
        }
        if (value instanceof SCO) {
            ((SCO) value).unsetOwner();
        }
    }
    return value;
}
Also used : ApiAdapter(org.datanucleus.api.ApiAdapter) RelationType(org.datanucleus.metadata.RelationType) TypeManager(org.datanucleus.store.types.TypeManager) ContainerAdapter(org.datanucleus.store.types.ContainerAdapter) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) SCO(org.datanucleus.store.types.SCO)

Example 9 with TypeManager

use of org.datanucleus.store.types.TypeManager in project datanucleus-core by datanucleus.

the class NullifyRelationFieldManager method fetchObjectField.

/**
 * Accessor for object field.
 * @param fieldNumber Number of field
 * @return Object value
 */
public Object fetchObjectField(int fieldNumber) {
    Object value = op.provideField(fieldNumber);
    if (value != null) {
        AbstractMemberMetaData mmd = op.getClassMetaData().getMetaDataForManagedMemberAtAbsolutePosition(fieldNumber);
        RelationType relType = mmd.getRelationType(op.getExecutionContext().getClassLoaderResolver());
        // do not need to nullify fields that are not references and resides embedded in this object
        if (relType != RelationType.NONE) {
            if (mmd.hasContainer()) {
                TypeManager typeManager = op.getExecutionContext().getTypeManager();
                ContainerAdapter containerAdapter = typeManager.getContainerAdapter(value);
                containerAdapter.clear();
                return containerAdapter.getContainer();
            }
            // Process PC fields
            op.makeDirty(fieldNumber);
            return null;
        }
    }
    return value;
}
Also used : RelationType(org.datanucleus.metadata.RelationType) TypeManager(org.datanucleus.store.types.TypeManager) ContainerAdapter(org.datanucleus.store.types.ContainerAdapter) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData)

Example 10 with TypeManager

use of org.datanucleus.store.types.TypeManager in project datanucleus-core by datanucleus.

the class PersistFieldManager method processMapContainer.

private void processMapContainer(int fieldNumber, Object container, AbstractMemberMetaData mmd) {
    TypeManager typeManager = op.getExecutionContext().getTypeManager();
    ContainerHandler<Object, MapContainerAdapter<Object>> containerHandler = typeManager.getContainerHandler(mmd.getType());
    ApiAdapter api = op.getExecutionContext().getApiAdapter();
    // Process all keys, values of the Map that are PC
    MapContainerAdapter<Object> mapAdapter = containerHandler.getAdapter(container);
    for (Entry<Object, Object> entry : mapAdapter.entries()) {
        Object mapKey = entry.getKey();
        Object mapValue = entry.getValue();
        Object newMapKey = mapKey;
        Object newMapValue = mapValue;
        if (api.isPersistable(mapKey)) {
            // Persist (or attach) the key
            int mapKeyObjectType = mmd.getMap().isEmbeddedKey() || mmd.getMap().isSerializedKey() ? ObjectProvider.EMBEDDED_MAP_KEY_PC : ObjectProvider.PC;
            newMapKey = processPersistable(mapKey, fieldNumber, mapKeyObjectType);
        }
        if (api.isPersistable(mapValue)) {
            // Persist (or attach) the value
            int mapValueObjectType = mmd.getMap().isEmbeddedValue() || mmd.getMap().isSerializedValue() ? ObjectProvider.EMBEDDED_MAP_VALUE_PC : ObjectProvider.PC;
            newMapValue = processPersistable(mapValue, fieldNumber, mapValueObjectType);
        }
        if (newMapKey != mapKey || newMapValue != mapValue) {
            // Maybe we have just have attached key or value
            boolean updateKey = false;
            boolean updateValue = false;
            if (newMapKey != mapKey) {
                ObjectProvider keyOP = op.getExecutionContext().findObjectProvider(newMapKey);
                if (keyOP.getReferencedPC() != null) {
                    // Attaching the key
                    updateKey = true;
                }
            }
            if (newMapValue != mapValue) {
                ObjectProvider valOP = op.getExecutionContext().findObjectProvider(newMapValue);
                if (valOP.getReferencedPC() != null) {
                    // Attaching the value
                    updateValue = true;
                }
            }
            if (updateKey) {
                mapAdapter.remove(mapKey);
                mapAdapter.put(newMapKey, updateValue ? newMapValue : mapValue);
            } else if (updateValue) {
                mapAdapter.put(mapKey, newMapValue);
            }
        }
    }
}
Also used : MapContainerAdapter(org.datanucleus.store.types.MapContainerAdapter) ApiAdapter(org.datanucleus.api.ApiAdapter) TypeManager(org.datanucleus.store.types.TypeManager) ObjectProvider(org.datanucleus.state.ObjectProvider)

Aggregations

TypeManager (org.datanucleus.store.types.TypeManager)26 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)10 JDOTypeConverter (org.datanucleus.api.jdo.JDOTypeConverter)8 ApiAdapter (org.datanucleus.api.ApiAdapter)6 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)5 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)5 RelationType (org.datanucleus.metadata.RelationType)5 ContainerHandler (org.datanucleus.store.types.ContainerHandler)5 AttributeConverter (javax.jdo.AttributeConverter)4 PersistenceNucleusContext (org.datanucleus.PersistenceNucleusContext)4 ExecutionContext (org.datanucleus.ExecutionContext)3 NucleusException (org.datanucleus.exceptions.NucleusException)3 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)3 ColumnMetaData (org.datanucleus.metadata.ColumnMetaData)3 EmbeddedMetaData (org.datanucleus.metadata.EmbeddedMetaData)3 FieldMetaData (org.datanucleus.metadata.FieldMetaData)3 FieldPersistenceModifier (org.datanucleus.metadata.FieldPersistenceModifier)3 ObjectProvider (org.datanucleus.state.ObjectProvider)3 MultiColumnConverter (org.datanucleus.store.types.converters.MultiColumnConverter)3 TypeConverter (org.datanucleus.store.types.converters.TypeConverter)3