{
ConglomerateController heapCC;
ScanController drivingScan;
ExecIndexRow drivingIndexRow;
RowLocation baseRowLocation;
RowChanger rc;
ExecRow baseRow = crf.makeEmptyRow();
int rowsDeleted = 0;
boolean passedFilter = true;
rc = getRowChanger( tc, (int[])null,baseRow );
/*
** If we have a start and a stop key, then we are going to
** get row locks, otherwise, we are getting table locks.
** This may be excessive locking for the case where there
** is a start key and no stop key or vice versa.
*/
int lockMode = ((startKey != null) && (stopKey != null)) ?
tc.MODE_RECORD :
tc.MODE_TABLE;
/*
** Don't use level 3 if we have the same start/stop key.
*/
int isolation =
((startKey != null) && (stopKey != null) && (startKey == stopKey)) ?
TransactionController.ISOLATION_REPEATABLE_READ :
TransactionController.ISOLATION_SERIALIZABLE;
// Row level locking
rc.open(lockMode);
DataValueDescriptor[] startKeyRow =
startKey == null ? null : startKey.getRowArray();
DataValueDescriptor[] stopKeyRow =
stopKey == null ? null : stopKey.getRowArray();
/* Open the heap conglomerate */
heapCC = tc.openConglomerate(
getHeapConglomerate(),
false,
TransactionController.OPENMODE_FORUPDATE,
lockMode,
TransactionController.ISOLATION_REPEATABLE_READ);
drivingScan = tc.openScan(
getIndexConglomerate(indexNumber), // conglomerate to open
false, // don't hold open across commit
TransactionController.OPENMODE_FORUPDATE, // for update
lockMode,
isolation,
(FormatableBitSet) null, // all fields as objects
startKeyRow, // start position - first row
startOp, // startSearchOperation
qualifier, //scanQualifier
stopKeyRow, // stop position - through last row
stopOp); // stopSearchOperation
// Get an index row based on the base row
drivingIndexRow = getIndexRowFromHeapRow(
getIndexRowGenerator( indexNumber ),
heapCC.newRowLocationTemplate(),
crf.makeEmptyRow());
while (drivingScan.next())
{
drivingScan.fetch(drivingIndexRow.getRowArray());
baseRowLocation = (RowLocation)
drivingIndexRow.getColumn(drivingIndexRow.nColumns());
boolean base_row_exists =
heapCC.fetch(
baseRowLocation, baseRow.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 not found");
}
// only delete rows which pass the base-row filter
if ( filter != null ) { passedFilter = filter.execute( baseRow ).equals( true ); }
if ( passedFilter )
{
rc.deleteRow( baseRow, baseRowLocation );
rowsDeleted++;
}
}
heapCC.close();
drivingScan.close();
rc.close();
return rowsDeleted;
}