// Update any detached reference to refer to the attached variant
ownerSM.replaceFieldMakeDirty(ownerFieldNumber, pcNew);
int relationType = mmd.getRelationType(clr);
if (relationType == Relation.ONE_TO_ONE_BI)
{
ObjectProvider relatedSM = ec.findObjectProvider(pcNew);
AbstractMemberMetaData[] relatedMmds = mmd.getRelatedMemberMetaData(clr);
// TODO Allow for multiple related fields
relatedSM.replaceFieldMakeDirty(relatedMmds[0].getAbsoluteFieldNumber(), ownerSM.getObject());
}
else if (relationType == Relation.MANY_TO_ONE_BI)
{
// TODO Update the container element with the attached variant
if (NucleusLogger.PERSISTENCE.isDebugEnabled())
{
NucleusLogger.PERSISTENCE.debug("PCMapping.setObject : object " + ownerSM.getInternalObjectId() +
" has field " + ownerFieldNumber +
" that is 1-N bidirectional - should really update the reference in the relation. Not yet supported");
}
}
}
}
if (getNumberOfDatastoreMappings() <= 0)
{
// If the field doesn't map to any datastore fields, omit the set process
return;
}
}
}
if (pos == null)
{
return;
}
// Obtain StateManager for the value (if persistable)
ObjectProvider sm = null;
if (value != null)
{
sm = ec.findObjectProvider(value);
}
try
{
if (sm != null)
{
sm.setStoringPC();
}
int n = 0;
NotYetFlushedException notYetFlushed = null;
for (int i=0; i<javaTypeMappings.length; i++)
{
// Set the PreparedStatement positions for this implementation mapping
int[] posMapping;
if (n >= pos.length)
{
n = 0; // store all implementations to the same columns, so we reset the index
}
if (javaTypeMappings[i].getReferenceMapping() != null)
{
posMapping = new int[javaTypeMappings[i].getReferenceMapping().getNumberOfDatastoreMappings()];
}
else
{
posMapping = new int[javaTypeMappings[i].getNumberOfDatastoreMappings()];
}
for (int j=0; j<posMapping.length; j++)
{
posMapping[j] = pos[n++];
}
try
{
if (javaTypeMappingNumber == -2 || (value != null && javaTypeMappingNumber == i))
{
// This mapping is where the value is to be stored, or using persistent interfaces
javaTypeMappings[i].setObject(ec, ps, posMapping, value);
}
else
{
// Set null for this mapping, since the value is null or is for something else
javaTypeMappings[i].setObject(ec, ps, posMapping, null);
}
}
catch (NotYetFlushedException e)
{
notYetFlushed = e;
}
}
if (notYetFlushed != null)
{
throw notYetFlushed;
}
}
finally
{
if (sm != null)
{
sm.unsetStoringPC();
}
}
}