ConstraintDescriptorList dList,
boolean forUpdate)
throws StandardException
{
SYSCONSTRAINTSRowFactory rf = (SYSCONSTRAINTSRowFactory) ti.getCatalogRowFactory();
ConglomerateController heapCC;
ConstraintDescriptor cd = null;
ExecIndexRow indexRow1;
ExecIndexRow indexTemplateRow;
ExecRow outRow;
RowLocation baseRowLocation;
ScanController scanController;
TransactionController tc;
// Get the current transaction controller
tc = getTransactionCompile();
outRow = rf.makeEmptyRow();
heapCC =
tc.openConglomerate(
ti.getHeapConglomerate(), false, 0,
TransactionController.MODE_RECORD,
TransactionController.ISOLATION_REPEATABLE_READ);
/* Scan the index and go to the data pages for qualifying rows to
* build the column descriptor.
*/
scanController = tc.openScan(
ti.getIndexConglomerate(indexId), // conglomerate to open
false, // don't hold open across commit
(forUpdate) ? TransactionController.OPENMODE_FORUPDATE : 0,
TransactionController.MODE_RECORD,
TransactionController.ISOLATION_REPEATABLE_READ,
(FormatableBitSet) null, // all fields as objects
keyRow.getRowArray(), // start position - exact key match.
ScanController.GE, // startSearchOperation
null, //scanQualifier,
keyRow.getRowArray(), // stop position - exact key match.
ScanController.GT); // stopSearchOperation
while (scanController.next())
{
SubConstraintDescriptor subCD = null;
// create an index row template
indexRow1 = getIndexRowFromHeapRow(
ti.getIndexRowGenerator(indexId),
heapCC.newRowLocationTemplate(),
outRow);
scanController.fetch(indexRow1.getRowArray());
baseRowLocation = (RowLocation) indexRow1.getColumn(
indexRow1.nColumns());
boolean base_row_exists =
heapCC.fetch(
baseRowLocation, outRow.getRowArray(), (FormatableBitSet) null);
if (SanityManager.DEBUG)
{
// it can not be possible for heap row to disappear while
// holding scan cursor on index at ISOLATION_REPEATABLE_READ.
SanityManager.ASSERT(base_row_exists, "base row doesn't exist");
}
switch (rf.getConstraintType(outRow))
{
case DataDictionary.PRIMARYKEY_CONSTRAINT:
case DataDictionary.FOREIGNKEY_CONSTRAINT:
case DataDictionary.UNIQUE_CONSTRAINT:
subCD = getSubKeyConstraint(
rf.getConstraintId(outRow), rf.getConstraintType(outRow));
break;
case DataDictionary.CHECK_CONSTRAINT:
subCD = getSubCheckConstraint(
rf.getConstraintId(outRow));
break;
default:
if (SanityManager.DEBUG)
{
SanityManager.THROWASSERT("unexpected value "+
"from rf.getConstraintType(outRow)" +
rf.getConstraintType(outRow));
}
}
if (SanityManager.DEBUG)
{
SanityManager.ASSERT(subCD != null,
"subCD is expected to be non-null");
}
/* Cache the TD in the SCD so that
* the row factory doesn't need to go
* out to disk to get it.
*/
subCD.setTableDescriptor(td);
cd = (ConstraintDescriptor) rf.buildDescriptor(
outRow,
subCD,
this);
/* If dList is null, then caller only wants a single descriptor - we're done
* else just add the current descriptor to the list.
*/
if (dList == null)
{
break;
}
else
{
dList.add(cd);
}
}
scanController.close();
heapCC.close();
return cd;
}