use of org.datanucleus.metadata.RelationType in project datanucleus-core by datanucleus.
the class StateManagerImpl method updateOwnerFieldInEmbeddedField.
/**
* Method to update the "owner-field" in an embedded object with the owner object.
* TODO Likely this should be moved into a replaceField method, or maybe Managed Relationships.
* @param fieldNumber The field number
* @param value The value to initialise the wrapper with (if any)
*/
public void updateOwnerFieldInEmbeddedField(int fieldNumber, Object value) {
if (value != null) {
AbstractMemberMetaData mmd = cmd.getMetaDataForManagedMemberAtAbsolutePosition(fieldNumber);
RelationType relationType = mmd.getRelationType(myEC.getClassLoaderResolver());
if (RelationType.isRelationSingleValued(relationType) && mmd.getEmbeddedMetaData() != null && mmd.getEmbeddedMetaData().getOwnerMember() != null) {
// Embedded field, so assign the embedded/serialised object "owner-field" if specified
ObjectProvider subSM = myEC.findObjectProvider(value);
int ownerAbsFieldNum = subSM.getClassMetaData().getAbsolutePositionOfMember(mmd.getEmbeddedMetaData().getOwnerMember());
if (ownerAbsFieldNum >= 0) {
flags |= FLAG_UPDATING_EMBEDDING_FIELDS_WITH_OWNER;
subSM.replaceFieldMakeDirty(ownerAbsFieldNum, myPC);
flags &= ~FLAG_UPDATING_EMBEDDING_FIELDS_WITH_OWNER;
}
}
}
}
use of org.datanucleus.metadata.RelationType in project datanucleus-core by datanucleus.
the class DeleteFieldManager method storeObjectField.
/**
* Method to store an object field.
* @param fieldNumber Number of the field (absolute)
* @param value Value of the field
*/
public void storeObjectField(int fieldNumber, Object value) {
if (value != null) {
AbstractMemberMetaData mmd = op.getClassMetaData().getMetaDataForManagedMemberAtAbsolutePosition(fieldNumber);
ExecutionContext ec = op.getExecutionContext();
RelationType relationType = mmd.getRelationType(ec.getClassLoaderResolver());
if (relationType != RelationType.NONE) {
if (mmd.hasContainer()) {
processContainer(fieldNumber, value, mmd, ec, relationType);
} else {
processSingleValue(value, mmd, ec, relationType);
}
}
}
}
use of org.datanucleus.metadata.RelationType in project datanucleus-core by datanucleus.
the class LoadFieldManager 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 relationType = mmd.getRelationType(op.getExecutionContext().getClassLoaderResolver());
if (relationType != RelationType.NONE) {
if (mmd.hasContainer()) {
value = processContainer(fieldNumber, value, mmd);
} else {
// Process PC fields
processPersistable(value);
}
}
}
return value;
}
use of org.datanucleus.metadata.RelationType 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.metadata.RelationType 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