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