Search in sources :

Example 6 with ContainerHandler

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

the class DeleteFieldManager method processSingleValue.

private void processSingleValue(Object value, AbstractMemberMetaData mmd, ExecutionContext ec, RelationType relationType) {
    // Process PC fields
    if (mmd.isDependent()) {
        processPersistable(value);
    } else if (manageRelationships && RelationType.isBidirectional(relationType) && !mmd.isEmbedded()) {
        ObjectProvider valueOP = ec.findObjectProvider(value);
        if (valueOP != null && !valueOP.getLifecycleState().isDeleted() && !valueOP.isDeleting()) {
            AbstractMemberMetaData relMmd = mmd.getRelatedMemberMetaData(ec.getClassLoaderResolver())[0];
            if (relationType == RelationType.ONE_TO_ONE_BI) {
                valueOP.replaceFieldMakeDirty(relMmd.getAbsoluteFieldNumber(), null);
                valueOP.flush();
            } else if (relationType == RelationType.MANY_TO_ONE_BI) {
                // Make sure field at other side is loaded, and remove from any Collection
                valueOP.loadField(relMmd.getAbsoluteFieldNumber());
                Object relValue = valueOP.provideField(relMmd.getAbsoluteFieldNumber());
                if (relValue != null) {
                    ContainerHandler containerHandler = ec.getTypeManager().getContainerHandler(relMmd.getType());
                    if (containerHandler instanceof ElementContainerHandler) {
                        ElementContainerAdapter adapter = (ElementContainerAdapter) containerHandler.getAdapter(relValue);
                        adapter.remove(op.getObject());
                    }
                }
            }
        }
    }
}
Also used : ElementContainerAdapter(org.datanucleus.store.types.ElementContainerAdapter) ContainerHandler(org.datanucleus.store.types.ContainerHandler) ElementContainerHandler(org.datanucleus.store.types.ElementContainerHandler) ObjectProvider(org.datanucleus.state.ObjectProvider) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) ElementContainerHandler(org.datanucleus.store.types.ElementContainerHandler)

Example 7 with ContainerHandler

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

the class DetachFieldManager method processContainer.

private Object processContainer(int fieldNumber, Object container, AbstractMemberMetaData mmd) {
    Object detachedContainer;
    TypeManager typeManager = op.getExecutionContext().getTypeManager();
    ContainerHandler containerHandler = typeManager.getContainerHandler(mmd.getType());
    if (mmd.hasMap()) {
        detachedContainer = processMapContainer(fieldNumber, container, mmd, containerHandler);
    } else {
        detachedContainer = processElementContainer(fieldNumber, container, mmd, containerHandler);
    }
    if (!mmd.hasArray()) {
        // Need to unset owner for mutable SCOs
        Object wrappedContainer;
        if (SCOUtils.detachAsWrapped(op)) {
            // Try to wrap the field, if possible, replacing it since it will be returned as wrapped
            wrappedContainer = SCOUtils.wrapSCOField(op, fieldNumber, detachedContainer, true);
            // Return the wrapped, if mutable, otherwise just the immutable value
            detachedContainer = wrappedContainer;
        } else {
            // Try to wrap the field, if possible, just to be able to unset the owner, so don't
            // replace it
            wrappedContainer = SCOUtils.wrapSCOField(op, fieldNumber, detachedContainer, false);
            // The container can be already an SCO so unwrap it if necessary
            if (detachedContainer instanceof SCO) {
                detachedContainer = SCOUtils.unwrapSCOField(op, fieldNumber, (SCO) detachedContainer);
            }
        }
        // It still can be an immutable collection or map, so must check if has been wrapped
        if (wrappedContainer instanceof SCO) {
            ((SCO) wrappedContainer).unsetOwner();
        }
    }
    return detachedContainer;
}
Also used : ContainerHandler(org.datanucleus.store.types.ContainerHandler) TypeManager(org.datanucleus.store.types.TypeManager) SCO(org.datanucleus.store.types.SCO)

Aggregations

ContainerHandler (org.datanucleus.store.types.ContainerHandler)7 TypeManager (org.datanucleus.store.types.TypeManager)5 ApiAdapter (org.datanucleus.api.ApiAdapter)3 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)3 ElementContainerHandler (org.datanucleus.store.types.ElementContainerHandler)2 SCO (org.datanucleus.store.types.SCO)2 Serializable (java.io.Serializable)1 AttributeConverter (javax.jdo.AttributeConverter)1 UseDefault (javax.jdo.AttributeConverter.UseDefault)1 Column (javax.jdo.annotations.Column)1 Discriminator (javax.jdo.annotations.Discriminator)1 Embedded (javax.jdo.annotations.Embedded)1 Extension (javax.jdo.annotations.Extension)1 ForeignKeyAction (javax.jdo.annotations.ForeignKeyAction)1 Persistent (javax.jdo.annotations.Persistent)1 ExecutionContext (org.datanucleus.ExecutionContext)1 PersistenceNucleusContext (org.datanucleus.PersistenceNucleusContext)1 JDOTypeConverter (org.datanucleus.api.jdo.JDOTypeConverter)1 Persistable (org.datanucleus.enhancement.Persistable)1 ClassNotResolvedException (org.datanucleus.exceptions.ClassNotResolvedException)1