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