use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$ForeignKeyUnary in project jaxdb by jaxdb.
the class DerbyDecompiler method getForeignKeys.
@Override
@SuppressWarnings("null")
Map<String, Map<String, $ForeignKeyUnary>> getForeignKeys(final Connection connection) throws SQLException {
final Map<String, List<String>> tableNameToColumns = getTables(connection);
final PreparedStatement statement = connection.prepareStatement(foreignKeySql);
final ResultSet rows = statement.executeQuery();
final Map<String, Map<String, $ForeignKeyUnary>> tableNameToForeignKeys = new HashMap<>();
String lastTable = null;
Map<String, $ForeignKeyUnary> columnNameToForeignKey = null;
while (rows.next()) {
final String tableName = rows.getString(2);
final List<String> columnNames = tableNameToColumns.get(tableName);
if (!tableName.equals(lastTable)) {
lastTable = tableName;
tableNameToForeignKeys.put(tableName, columnNameToForeignKey = new HashMap<>());
}
final String primaryTable = rows.getString(6);
final String primaryDescriptor = rows.getString(7);
final String primaryColumn = tableNameToColumns.get(primaryTable).get(Integer.valueOf(primaryDescriptor.substring(primaryDescriptor.lastIndexOf('(') + 1, primaryDescriptor.lastIndexOf(')'))) - 1);
final $ForeignKeyUnary foreignKey = new $Column.ForeignKey();
foreignKey.setReferences$(new References$(primaryTable.toLowerCase()));
foreignKey.setColumn$(new Column$(primaryColumn.toLowerCase()));
final String deleteRule = rows.getString(4);
final $ChangeRule.Enum onDelete = deleteRule == null ? null : "S".equals(deleteRule) ? $ChangeRule.RESTRICT : "C".equals(deleteRule) ? $ChangeRule.CASCADE : "U".equals(deleteRule) ? $ChangeRule.SET_20NULL : null;
if (onDelete != null)
foreignKey.setOnDelete$(new OnDelete$(onDelete));
final String updateRule = rows.getString(5);
final $ChangeRule.Enum onUpdate = updateRule == null ? null : "S".equals(updateRule) ? $ChangeRule.RESTRICT : null;
if (onUpdate != null)
foreignKey.setOnUpdate$(new OnUpdate$(onUpdate));
final String foreignDescriptor = rows.getString(3);
final String foreignColumn = columnNames.get(Integer.valueOf(foreignDescriptor.substring(foreignDescriptor.lastIndexOf('(') + 1, foreignDescriptor.lastIndexOf(')'))) - 1);
columnNameToForeignKey.put(foreignColumn, foreignKey);
}
return tableNameToForeignKeys;
}
Aggregations