Iterator i = RDBMSStoreHelper.getForeignKeyInfoForTable(storeMgr, this, conn).iterator();
while (i.hasNext())
{
RDBMSIdentifierFactory idFactory = (RDBMSIdentifierFactory)storeMgr.getIdentifierFactory();
DatastoreIdentifier fkName;
ForeignKeyInfo fki = (ForeignKeyInfo) i.next();
if (fki.fkName == null)
{
fkName = idFactory.newForeignKeyIdentifier(this, foreignKeysByName.size());
}
else
{
fkName = idFactory.newIdentifier(IdentifierFactory.FOREIGN_KEY, fki.fkName);
}
boolean initiallyDeferred = fki.deferrability == DatabaseMetaData.importedKeyInitiallyDeferred;
ForeignKey fk = (ForeignKey) foreignKeysByName.get(fkName);
if (fk == null)
{
fk = new ForeignKey(initiallyDeferred);
fk.setName(fkName.getIdentifier());
foreignKeysByName.put(fkName, fk);
}
AbstractTable refTable = (AbstractTable)storeMgr.getDatastoreClass(idFactory.newDatastoreContainerIdentifier(fki.pkTableName));
if (refTable != null)
{
DatastoreIdentifier colName = idFactory.newIdentifier(IdentifierFactory.COLUMN, fki.fkColumnName);
DatastoreIdentifier refColName = idFactory.newIdentifier(IdentifierFactory.COLUMN, fki.pkColumnName);
DatastoreField col = (DatastoreField) columnsByName.get(colName);
DatastoreField refCol = (DatastoreField) refTable.columnsByName.get(refColName);
if (col != null && refCol != null)
{
fk.addDatastoreField(col, refCol);