.fetch();
}
@Override
protected void loadForeignKeys(DefaultRelations relations) throws SQLException {
ConnectionProvider provider = create().configuration().connectionProvider();
Connection connection = null;
try {
connection = provider.acquire();
DatabaseMetaData meta = connection.getMetaData();
for (String table : create()
.selectDistinct(DB_INDEX.CLASS_NAME)
.from(DB_INDEX)
.where(DB_INDEX.IS_FOREIGN_KEY.isTrue())
.fetch(DB_INDEX.CLASS_NAME)) {
for (Record record : create().fetch(meta.getImportedKeys(null, null, table))) {
String foreignKeyName =
record.getValue("FKTABLE_NAME", String.class) +
"__" +
record.getValue("FK_NAME", String.class);
String foreignKeyTableName = record.getValue("FKTABLE_NAME", String.class);
String foreignKeyColumnName = record.getValue("FKCOLUMN_NAME", String.class);
String uniqueKeyName =
record.getValue("PKTABLE_NAME", String.class) +
"__" +
record.getValue("PK_NAME", String.class);
TableDefinition referencingTable = getTable(getSchemata().get(0), foreignKeyTableName);
if (referencingTable != null) {
ColumnDefinition column = referencingTable.getColumn(foreignKeyColumnName);
relations.addForeignKey(foreignKeyName, uniqueKeyName, column, getSchemata().get(0));
}
}
}
}
finally {
if (connection != null) {
provider.release(connection);
}
}
}