protected int delByScan(TableConst table, boolean batch) {
beginTransaction();
// get a full table scan operation (no scan filter defined)
final NdbScanOperation op = tx.getNdbScanOperation(table);
if (op == null)
throw new RuntimeException(toStr(tx.getNdbError()));
// define a read scan with exclusive locks
final int lock_mode = NdbOperation.LockMode.LM_Exclusive;
final int scan_flags = 0;
final int parallel = 0;
final int batch_ = 0;
if (op.readTuples(lock_mode, scan_flags, parallel, batch_) != 0)
throw new RuntimeException(toStr(tx.getNdbError()));
// start the scan; don't commit yet
executeOperations();
// delete all rows in a given scan
int count = 0;
int stat;
final boolean allowFetch = true; // request new batches when exhausted
final boolean forceSend = false; // send may be delayed
while ((stat = op.nextResult(allowFetch, forceSend)) == 0) {
// delete all tuples within a batch
do {
if (op.deleteCurrentTuple() != 0)
throw new RuntimeException(toStr(tx.getNdbError()));
count++;
// execute the operation now if in non-batching mode
if (!batch)
executeOperations();
} while ((stat = op.nextResult(!allowFetch, forceSend)) == 0);
if (stat == 1) {
// no more batches
break;
}
if (stat == 2) {
// end of current batch, fetch next
final int execType = NdbTransaction.ExecType.NoCommit;
final int abortOption = NdbOperation.AbortOption.AbortOnError;
final int force = 0;
if (tx.execute(execType, abortOption, force) != 0
|| tx.getNdbError().status() != NdbError.Status.Success)
throw new RuntimeException(toStr(tx.getNdbError()));
continue;
}
throw new RuntimeException("stat == " + stat);
}
if (stat != 1)
throw new RuntimeException("stat == " + stat);
// close the scan
final boolean forceSend_ = false;
final boolean releaseOp = false;
op.close(forceSend_, releaseOp);
commitTransaction();
closeTransaction();
return count;
}