* @param referencedObject The referenced object or <i>null</i>
*/
private void setFKField(Object targetObject, ClassDescriptor cld, ObjectReferenceDescriptor rds, Object referencedObject)
{
ValueContainer[] refPkValues;
FieldDescriptor fld;
FieldDescriptor[] objFkFields = rds.getForeignKeyFieldDescriptors(cld);
if (objFkFields == null)
{
throw new PersistenceBrokerException("No foreign key fields defined for class '"+cld.getClassNameOfObject()+"'");
}
if(referencedObject == null)
{
refPkValues = null;
}
else
{
Class refClass = proxyFactory.getRealClass(referencedObject);
ClassDescriptor refCld = getClassDescriptor(refClass);
refPkValues = brokerHelper.getKeyValues(refCld, referencedObject, false);
}
for (int i = 0; i < objFkFields.length; i++)
{
fld = objFkFields[i];
/*
arminw:
we set the FK value when the extracted PK fields from the referenced object are not null at all
or if null, the FK field was not a PK field of target object too.
Should be ok, because the values of the extracted PK field values should never be null and never
change, so it doesn't matter if the target field is a PK too.
*/
if(refPkValues != null || !fld.isPrimaryKey())
{
fld.getPersistentField().set(targetObject, refPkValues != null ? refPkValues[i].getValue(): null);
}
}
}