database,
foreignTableName,
true);
if (foreignTable == null)
{
throw new SourceTransformerException(
"Foreign table with name "
+ foreignTableName
+ " not found for a foreignKey of table "
+ localTableName);
}
SourceElement foreignColumn = FindHelper.findColumn(
foreignTable,
foreignColumnName);
if (foreignColumn == null)
{
throw new SourceTransformerException(
"Referenced Column with table name "
+ foreignTableName
+ " and column name "
+ foreignColumnName
+ " not found for a foreignKey of table "
+ localTableName);
}
referencedColumn.getChildren().add(foreignColumn);
column.getChildren().add(referencedColumn);
break;
}
}
}
}
//create the referencing-column elements
List<SourceElement> allTables
= database.getChildren(TorqueSchemaElementName.TABLE.getName());
for (SourceElement foreignTable : allTables)
{
String foreignTableName
= (String) foreignTable.getAttribute(
TorqueSchemaAttributeName.NAME);
List<SourceElement> foreignKeys
= foreignTable.getChildren(
TorqueSchemaElementName.FOREIGN_KEY.getName());
for (SourceElement foreignKey : foreignKeys)
{
if (!localTableName.equals(foreignKey.getAttribute(
TorqueSchemaAttributeName.FOREIGN_TABLE)))
{
continue;
}
List<SourceElement> references
= foreignKey.getChildren(
TorqueSchemaElementName.REFERENCE.getName());
for (SourceElement reference : references)
{
Object referenceForeignColumnName
= reference.getAttribute(
TorqueSchemaAttributeName.FOREIGN);
String referenceLocalColumnName
= (String) reference.getAttribute(
TorqueSchemaAttributeName.LOCAL);
if (localColumnName.equals(referenceForeignColumnName))
{
SourceElement referencingColumn
= new SourceElement(
ColumnChildElementName.REFERENCING_COLUMN);
referencingColumn.getChildren().add(foreignKey);
referencingColumn.getChildren().add(foreignTable);
SourceElement localColumn = FindHelper.findColumn(
foreignTable,
referenceLocalColumnName);
if (localColumn == null)
{
throw new SourceTransformerException(
"Local Column with column name "
+ referenceLocalColumnName
+ " not found in one of the foreignKeys"
+ " of table "
+ foreignTableName);