throw new IllegalArgumentException("Illegal element Name "
+ column.getName());
}
Object localColumnName
= column.getAttribute(TorqueSchemaAttributeName.NAME);
SourceElement localTable = column.getParent();
Object localTableName
= localTable.getAttribute(TorqueSchemaAttributeName.NAME);
SourceElement database = localTable.getParent();
// create the referencedColumn elements
{
List<SourceElement> tableForeignKeys
= localTable.getChildren(
TorqueSchemaElementName.FOREIGN_KEY.getName());
// find foreign keys with this column as local reference
// and create a referencedColumn element for each.
for (SourceElement foreignKey : tableForeignKeys)
{
List<SourceElement> references
= foreignKey.getChildren(
TorqueSchemaElementName.REFERENCE.getName());
for (SourceElement reference : references)
{
if (localColumnName.equals(reference.getAttribute(
TorqueSchemaAttributeName.LOCAL)))
{
SourceElement referencedColumn
= new SourceElement(
ColumnChildElementName.REFERENCED_COLUMN);
referencedColumn.getChildren().add(foreignKey);
String foreignTableName
= (String) foreignKey.getAttribute(
TorqueSchemaAttributeName.FOREIGN_TABLE);
String foreignColumnName
= (String) reference.getAttribute(
TorqueSchemaAttributeName.FOREIGN);
SourceElement foreignTable = FindHelper.findTable(
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(