// Run callbacks for each of the element classes.
for (int i=0;i<elementCmds.length;i++)
{
storeMgr.addSchemaCallback(elementCmds[i].getFullClassName(), mmd);
DatastoreClass dc = storeMgr.getDatastoreClass(elementCmds[i].getFullClassName(), clr);
if (dc == null)
{
throw new NucleusException("Unable to add foreign-key to " +
elementCmds[i].getFullClassName() + " to " + this + " since element has no table!");
}
ClassTable ct = (ClassTable) dc;
if (ct.isInitialized())
{
// if the target table is already initialized, run the callbacks
ct.runCallBacks(clr);
}
}
}
}
else if (mmd.getMap() != null && !SCOUtils.mapHasSerialisedKeysAndValues(mmd))
{
// 1-N ForeignKey map, so add FK to value table
if (mmd.getKeyMetaData() != null && mmd.getKeyMetaData().getMappedBy() != null)
{
// Key is stored in the value table so add the FK to the value table
AbstractClassMetaData valueCmd = storeMgr.getNucleusContext().getMetaDataManager().getMetaDataForClass(mmd.getMap().getValueType(), clr);
if (valueCmd == null)
{
// Interface elements will come through here and java.lang.String and others as well
NucleusLogger.METADATA.warn(LOCALISER.msg("057018",
theCmd.getFullClassName(), mmd.getMap().getValueType()));
}
else
{
AbstractClassMetaData[] valueCmds = null;
// TODO : Cater for interface values, and get the metadata for the implementation classes here
if (valueCmd.getInheritanceMetaData().getStrategy() == 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++)
{
storeMgr.addSchemaCallback(valueCmds[i].getFullClassName(), mmd);
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 (mmd.getValueMetaData() != null && mmd.getValueMetaData().getMappedBy() != null)
{
// Value is stored in the key table so add the FK to the key table
AbstractClassMetaData keyCmd = storeMgr.getNucleusContext().getMetaDataManager().getMetaDataForClass(mmd.getMap().getKeyType(), clr);
if (keyCmd == null)
{
// Interface elements will come through here and java.lang.String and others as well
NucleusLogger.METADATA.warn(LOCALISER.msg("057019",
theCmd.getFullClassName(), mmd.getMap().getKeyType()));
}
else
{
AbstractClassMetaData[] keyCmds = null;
// TODO : Cater for interface keys, and get the metadata for the implementation classes here
if (keyCmd.getInheritanceMetaData().getStrategy() == InheritanceStrategy.SUBCLASS_TABLE)
{
keyCmds = storeMgr.getClassesManagingTableForClass(keyCmd, clr);
}
else
{
keyCmds = new ClassMetaData[1];
keyCmds[0] = keyCmd;
}
// Run callbacks for each of the key classes.
for (int i=0;i<keyCmds.length;i++)
{
storeMgr.addSchemaCallback(keyCmds[i].getFullClassName(), mmd);
DatastoreClass dc = storeMgr.getDatastoreClass(keyCmds[i].getFullClassName(), clr);
ClassTable ct = (ClassTable) dc;
if (ct.isInitialized())
{
// if the target table is already initialized, run the callbacks
ct.runCallBacks(clr);