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