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());
}
}
}
}
}
}
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;
}
Aggregations