Search in sources :

Example 1 with ContainerAdapter

use of org.datanucleus.store.types.ContainerAdapter in project datanucleus-rdbms by datanucleus.

the class SingleCollectionMapping method setObject.

@Override
public void setObject(ExecutionContext ec, PreparedStatement ps, int[] pos, Object container) {
    Object value = null;
    if (container != null) {
        ElementContainerHandler containerHandler = ec.getTypeManager().getContainerHandler(mmd.getType());
        ContainerAdapter containerAdapter = containerHandler.getAdapter(container);
        Iterator iterator = containerAdapter.iterator();
        value = iterator.hasNext() ? iterator.next() : null;
    }
    wrappedMapping.setObject(ec, ps, pos, value);
}
Also used : Iterator(java.util.Iterator) ContainerAdapter(org.datanucleus.store.types.ContainerAdapter) ElementContainerHandler(org.datanucleus.store.types.ElementContainerHandler)

Example 2 with ContainerAdapter

use of org.datanucleus.store.types.ContainerAdapter 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 3 with ContainerAdapter

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

Aggregations

ContainerAdapter (org.datanucleus.store.types.ContainerAdapter)3 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)2 RelationType (org.datanucleus.metadata.RelationType)2 TypeManager (org.datanucleus.store.types.TypeManager)2 Iterator (java.util.Iterator)1 ApiAdapter (org.datanucleus.api.ApiAdapter)1 ElementContainerHandler (org.datanucleus.store.types.ElementContainerHandler)1 SCO (org.datanucleus.store.types.SCO)1