for (SchemaObject obj : database.getAllSchemaObjects(DbObject.CONSTRAINT)) {
Constraint constraint = (Constraint) obj;
if (!(constraint.getConstraintType().equals(Constraint.REFERENTIAL))) {
continue;
}
ConstraintReferential ref = (ConstraintReferential) constraint;
IndexColumn[] cols = ref.getColumns();
IndexColumn[] refCols = ref.getRefColumns();
Table tab = ref.getTable();
Table refTab = ref.getRefTable();
String tableName = identifier(refTab.getName());
if (!checkIndex(session, tableName, indexFrom, indexTo)) {
continue;
}
int update = getRefAction(ref.getUpdateAction());
int delete = getRefAction(ref.getDeleteAction());
for (int j = 0; j < cols.length; j++) {
add(rows,
// PKTABLE_CATALOG
catalog,
// PKTABLE_SCHEMA
identifier(refTab.getSchema().getName()),
// PKTABLE_NAME
identifier(refTab.getName()),
// PKCOLUMN_NAME
identifier(refCols[j].column.getName()),
// FKTABLE_CATALOG
catalog,
// FKTABLE_SCHEMA
identifier(tab.getSchema().getName()),
// FKTABLE_NAME
identifier(tab.getName()),
// FKCOLUMN_NAME
identifier(cols[j].column.getName()),
// ORDINAL_POSITION
String.valueOf(j + 1),
// UPDATE_RULE SMALLINT
String.valueOf(update),
// DELETE_RULE SMALLINT
String.valueOf(delete),
// FK_NAME
identifier(ref.getName()),
// PK_NAME
null,
// DEFERRABILITY
"" + DatabaseMetaData.importedKeyNotDeferrable
);