// 1-N uni/bidirectional using FK, so update the element side with a FK
if ((fmd.getCollection() != null && !SCOUtils.collectionHasSerialisedElements(fmd)) ||
(fmd.getArray() != null && !SCOUtils.arrayIsStoredInSingleColumn(fmd)))
{
// 1-N ForeignKey collection/array, so add FK to element table
AbstractClassMetaData elementCmd = null;
if (fmd.hasCollection())
{
// Collection
elementCmd = storeMgr.getOMFContext().getMetaDataManager().getMetaDataForClass(fmd.getCollection().getElementType(), clr);
}
else
{
// Array
elementCmd = storeMgr.getOMFContext().getMetaDataManager().getMetaDataForClass(fmd.getType().getComponentType(), clr);
}
if (elementCmd == null)
{
// Elements that are reference types or non-PC will come through here
if (fmd.hasCollection())
{
JPOXLogger.METADATA.warn(LOCALISER.msg("057016",
theCmd.getFullClassName(), fmd.getCollection().getElementType()));
}
else
{
JPOXLogger.METADATA.warn(LOCALISER.msg("057014",
theCmd.getFullClassName(), fmd.getType().getComponentType().getName()));
}
}
else
{
AbstractClassMetaData[] elementCmds = null;
// TODO : Cater for interface elements, and get the metadata for the implementation classes here
if (elementCmd.getInheritanceMetaData().getStrategyValue() == InheritanceStrategy.SUBCLASS_TABLE)
{
elementCmds = storeMgr.getClassesManagingTableForClass(elementCmd, clr);
}
else
{
elementCmds = new ClassMetaData[1];
elementCmds[0] = elementCmd;
}
// Run callbacks for each of the element classes.
for (int i=0;i<elementCmds.length;i++)
{
callbacks.put(elementCmds[i].getFullClassName(), new CallBack(fmd));
DatastoreClass dc = storeMgr.getDatastoreClass(elementCmds[i].getFullClassName(), clr);
ClassTable ct = (ClassTable) dc;
if (ct.isInitialized())
{
// if the target table is already initialized, run the callbacks
ct.runCallBacks(clr);
}
}
}
}
else if (fmd.getMap() != null && !SCOUtils.mapHasSerialisedKeysAndValues(fmd))
{
// 1-N ForeignKey map, so add FK to value table
if (fmd.getKeyMetaData() != null && fmd.getKeyMetaData().getMappedBy() != null)
{
// Key is stored in the value table so add the FK to the value table
AbstractClassMetaData valueCmd = storeMgr.getOMFContext().getMetaDataManager().getMetaDataForClass(fmd.getMap().getValueType(), clr);
if (valueCmd == null)
{
// Interface elements will come through here and java.lang.String and others as well
JPOXLogger.METADATA.warn(LOCALISER.msg("057018",
theCmd.getFullClassName(), fmd.getMap().getValueType()));
}
else
{
AbstractClassMetaData[] valueCmds = null;
// TODO : Cater for interface values, and get the metadata for the implementation classes here
if (valueCmd.getInheritanceMetaData().getStrategyValue() == InheritanceStrategy.SUBCLASS_TABLE)
{
valueCmds = storeMgr.getClassesManagingTableForClass(valueCmd, clr);
}
else
{
valueCmds = new ClassMetaData[1];
valueCmds[0] = valueCmd;
}
// Run callbacks for each of the value classes.
for (int i=0;i<valueCmds.length;i++)
{
callbacks.put(valueCmds[i].getFullClassName(), new CallBack(fmd));
DatastoreClass dc = storeMgr.getDatastoreClass(valueCmds[i].getFullClassName(), clr);
ClassTable ct = (ClassTable) dc;
if (ct.isInitialized())
{
// if the target table is already initialized, run the callbacks
ct.runCallBacks(clr);
}
}
}
}
else if (fmd.getValueMetaData() != null && fmd.getValueMetaData().getMappedBy() != null)
{
// Value is stored in the key table so add the FK to the key table
AbstractClassMetaData keyCmd = storeMgr.getOMFContext().getMetaDataManager().getMetaDataForClass(fmd.getMap().getKeyType(), clr);
if (keyCmd == null)
{
// Interface elements will come through here and java.lang.String and others as well
JPOXLogger.METADATA.warn(LOCALISER.msg("057019",
theCmd.getFullClassName(), fmd.getMap().getKeyType()));
}
else
{
AbstractClassMetaData[] keyCmds = null;
// TODO : Cater for interface keys, and get the metadata for the implementation classes here
if (keyCmd.getInheritanceMetaData().getStrategyValue() == InheritanceStrategy.SUBCLASS_TABLE)
{
keyCmds = storeMgr.getClassesManagingTableForClass(keyCmd, clr);
}
else
{