Vector refColDescriptors = new Vector(1);
Vector fkColMap = new Vector(1);
int activeSize = activeList.size();
for (int index = 0; index < activeSize; index++)
{
ConstraintDescriptor cd = activeList.elementAt(index);
if (cd instanceof ForeignKeyConstraintDescriptor)
{
/*
** We are saving information for checking the
** primary/unique key that is referenced by this
** foreign key, so type is FOREIGN KEY.
*/
type = FKInfo.FOREIGN_KEY;
refcd = ((ForeignKeyConstraintDescriptor)cd).getReferencedConstraint();
uuids = new UUID[1];
conglomNumbers = new long[1];
fkNames = new String[1];
isSelfReferencingFK = new boolean[1];
raRules = new int[1];
fkSetupArrays(dd, (ForeignKeyConstraintDescriptor)cd,
0, uuids, conglomNumbers,
fkNames, isSelfReferencingFK, raRules);
// oops, get the right constraint name -- for error
// handling we want the FK name, not refcd name
fkNames[0] = cd.getConstraintName();
}
else if (cd instanceof ReferencedKeyConstraintDescriptor)
{
refcd = (ReferencedKeyConstraintDescriptor)cd;
/*
** We are saving information for checking the
** foreign key(s) that is dependent on this referenced
** key, so type is REFERENCED KEY.
*/
type = FKInfo.REFERENCED_KEY;
fkcdl = dd.getActiveConstraintDescriptors
( ((ReferencedKeyConstraintDescriptor)cd).getForeignKeyConstraints(ConstraintDescriptor.ENABLED) );
int size = fkcdl.size();
if (size == 0)
{
continue;
}
uuids = new UUID[size];
fkNames = new String[size];
conglomNumbers = new long[size];
isSelfReferencingFK = new boolean[size];
raRules = new int[size];
ForeignKeyConstraintDescriptor fkcd = null;
TableDescriptor fktd;
ColumnDescriptorList coldl;
int[] refColumns;
ColumnDescriptor cold;
int[] colArray = remapReferencedColumns(cd, rowMap);
for (int inner = 0; inner < size; inner++)
{
fkcd = (ForeignKeyConstraintDescriptor) fkcdl.elementAt(inner);
fkSetupArrays(dd, fkcd,
inner, uuids, conglomNumbers, fkNames,
isSelfReferencingFK, raRules);
if((raRules[inner] == StatementType.RA_CASCADE) ||
(raRules[inner] ==StatementType.RA_SETNULL))
{
//find the referencing table Name
fktd = fkcd.getTableDescriptor();
refTableNames.addElement(fktd.getSchemaName() + "." + fktd.getName());
refActions.addElement(new Integer(raRules[inner]));
//find the referencing column name required for update null.
refColumns = fkcd.getReferencedColumns();
coldl = fktd.getColumnDescriptorList();
ColumnDescriptorList releventColDes = new ColumnDescriptorList();
for(int i = 0 ; i < refColumns.length; i++)
{
cold =(ColumnDescriptor)coldl.elementAt(refColumns[i]-1);
releventColDes.add(cold);
}
refColDescriptors.addElement(releventColDes);
refIndexConglomNum.addElement(new Long(conglomNumbers[inner]));
fkColMap.addElement(colArray);
}
}
}
else
{
continue;
}
TableDescriptor pktd = refcd.getTableDescriptor();
UUID pkuuid = refcd.getIndexId();
ConglomerateDescriptor pkIndexConglom = pktd.getConglomerateDescriptor(pkuuid);
TableDescriptor refTd = cd.getTableDescriptor();
fkVector.addElement(new FKInfo(
fkNames, // foreign key names
refTd.getName(), // table being modified
statementType, // INSERT|UPDATE|DELETE
type, // FOREIGN_KEY|REFERENCED_KEY