{
// Can't create a FK if we don't know where it goes to
NucleusLogger.DATASTORE_SCHEMA.warn(LOCALISER.msg("058105", acmd.getFullClassName()));
return null;
}
DatastoreIdentifier tableId = storeMgr.getIdentifierFactory().newDatastoreContainerIdentifier(fkmd.getTable());
ClassTable refTable = (ClassTable)storeMgr.getDatastoreClass(tableId);
if (refTable == null)
{
// TODO Go to the datastore and query for this table to get the columns of the PK
NucleusLogger.DATASTORE_SCHEMA.warn(LOCALISER.msg("058106", acmd.getFullClassName(),
fkmd.getTable()));
return null;
}
PrimaryKey pk = refTable.getPrimaryKey();
List targetCols = pk.getColumns();
// Generate the columns for the source of the foreign-key
List sourceCols = new ArrayList();
ColumnMetaData[] colmds = fkmd.getColumnMetaData();
AbstractMemberMetaData[] fmds = fkmd.getMemberMetaData();
if (colmds != null && colmds.length > 0)
{
// FK specified via <column>
for (int i=0;i<colmds.length;i++)
{
// Find the column and add to the source columns for the FK
DatastoreIdentifier colId = storeMgr.getIdentifierFactory().newDatastoreFieldIdentifier(colmds[i].getName());
Column sourceCol = columnsByName.get(colId);
if (sourceCol == null)
{
NucleusLogger.DATASTORE_SCHEMA.warn(LOCALISER.msg("058107",
acmd.getFullClassName(), fkmd.getTable(), colmds[i].getName(), toString()));