int[] mainCols;
int[] refCols;
Constraint[] constraints;
Constraint constraint;
int constraintCount;
HsqlArrayList fkConstraintsList;
Object[] row;
DITableInfo pkInfo;
DITableInfo fkInfo;
// column number mappings
final int ipk_table_cat = 0;
final int ipk_table_schem = 1;
final int ipk_table_name = 2;
final int ipk_column_name = 3;
final int ifk_table_cat = 4;
final int ifk_table_schem = 5;
final int ifk_table_name = 6;
final int ifk_column_name = 7;
final int ikey_seq = 8;
final int iupdate_rule = 9;
final int idelete_rule = 10;
final int ifk_name = 11;
final int ipk_name = 12;
final int ideferrability = 13;
tables = database.schemaManager.allTablesIterator();
pkInfo = new DITableInfo();
fkInfo = new DITableInfo();
// the only deferrability rule currently supported by hsqldb is:
deferrability = ValuePool.getInt(Constraint.NOT_DEFERRABLE);
// We must consider all the constraints in all the user tables, since
// this is where reference relationships are recorded. However, we
// are only concerned with Constraint.FOREIGN_KEY constraints here
// because their corresponing Constraint.MAIN entries are essentially
// duplicate data recorded in the referenced rather than the
// referencing table. Also, we skip constraints where either
// the referenced, referencing or both tables are not accessible
// relative to the session of the calling context
fkConstraintsList = new HsqlArrayList();
while (tables.hasNext()) {
table = (Table) tables.next();
if (!isAccessibleTable(table)) {
continue;
}
constraints = table.getConstraints();
constraintCount = constraints.length;
for (int i = 0; i < constraintCount; i++) {
constraint = (Constraint) constraints[i];
if (constraint.getType() == Constraint.FOREIGN_KEY
&& isAccessibleTable(constraint.getRef())) {
fkConstraintsList.add(constraint);
}
}
}
// Now that we have all of the desired constraints, we need to
// process them, generating one row in our ouput table for each
// imported/exported column pair of each constraint.
// Do it.
for (int i = 0; i < fkConstraintsList.size(); i++) {
constraint = (Constraint) fkConstraintsList.get(i);
pkTable = constraint.getMain();
pkInfo.setTable(pkTable);
pkTableName = pkInfo.getName();