private void gatherRelations(DBDatabase db, DatabaseMetaData dbMeta, ArrayList<String> tables) throws SQLException{
ResultSet relations = null;
String fkTableName, pkTableName, fkColName, pkColName, relName;
DBTableColumn fkCol, pkCol;
DBTable fkTable, pkTable;
DBColumn col;
// Add all Relations
for (String tableName :tables) {
// check for foreign-keys
relations = dbMeta.getImportedKeys(config.getDbCatalog(), config .getDbSchema(), tableName);
while (relations.next()) {
pkCol=fkCol=null;
fkTableName=relations.getString("FKTABLE_NAME");
pkTableName=relations.getString("PKTABLE_NAME");
fkColName=relations.getString("FKCOLUMN_NAME");
pkColName=relations.getString("PKCOLUMN_NAME");
// Detect relation name
relName=relations.getString("FK_NAME");
if (StringUtils.isEmpty(relName))
relName=fkTableName+"."+fkColName+"-"+pkTableName+"."+pkColName;
pkTable = db.getTable(pkTableName);
fkTable = db.getTable(fkTableName);
// check if both tables really exist in the model
if(pkTable==null || fkTable==null){
log.error("Unable to add the relation \""+relName+"\"! One of the tables could not be found.");
continue;
}
col=pkTable.getColumn(pkColName);
if(col instanceof DBTableColumn)
pkCol = (DBTableColumn) col;
col=fkTable.getColumn(fkColName);
if(col instanceof DBTableColumn)
fkCol = (DBTableColumn) col;
// check if both columns really exist in the model
if(fkCol==null || pkCol==null){