use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$ForeignKey.OnUpdate$ in project jaxdb by jaxdb.
the class Decompiler method getForeignKeys.
@SuppressWarnings("null")
// FIXME: This does not support composite foreign keys
Map<String, Map<String, $ForeignKeyUnary>> getForeignKeys(final Connection connection) throws SQLException {
final DatabaseMetaData metaData = connection.getMetaData();
try (final ResultSet foreignKeyRows = metaData.getImportedKeys(null, null, null)) {
final Map<String, Map<String, $ForeignKeyUnary>> tableNameToForeignKeys = new HashMap<>();
String lastTable = null;
Map<String, $ForeignKeyUnary> columnNameToForeignKey = null;
while (foreignKeyRows.next()) {
final String tableName = foreignKeyRows.getString("FKTABLE_NAME").toLowerCase();
if (!tableName.equals(lastTable)) {
lastTable = tableName;
tableNameToForeignKeys.put(tableName, columnNameToForeignKey = new HashMap<>());
}
final String primaryTable = foreignKeyRows.getString("PKTABLE_NAME").toLowerCase();
final String primaryColumn = foreignKeyRows.getString("PKCOLUMN_NAME").toLowerCase();
final String columnName = foreignKeyRows.getString("FKCOLUMN_NAME").toLowerCase();
final short updateRule = foreignKeyRows.getShort("UPDATE_RULE");
final short deleteRule = foreignKeyRows.getShort("DELETE_RULE");
final $ForeignKeyUnary foreignKey = new $Column.ForeignKey();
foreignKey.setReferences$(new References$(primaryTable));
foreignKey.setColumn$(new Column$(primaryColumn));
final $ChangeRule.Enum onUpdate = toBinding(updateRule);
if (onUpdate != null)
foreignKey.setOnUpdate$(new OnUpdate$(onUpdate));
final $ChangeRule.Enum onDelete = toBinding(deleteRule);
if (onDelete != null)
foreignKey.setOnDelete$(new OnDelete$(onDelete));
columnNameToForeignKey.put(columnName, foreignKey);
}
return tableNameToForeignKeys;
}
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$ForeignKey.OnUpdate$ 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