Tracer.trace(Level.FINEST,
envHandle.getEnvironmentImpl(),
"Database.truncate: txnId=" +
((txn == null) ? "null" : Long.toString(txn.getId())));
Locker locker = null;
boolean triggerLock = false;
boolean operationOk = false;
try {
locker = LockerFactory.getWritableLocker
(envHandle, txn, isTransactional(), true /*retainLocks*/,
null);
/*
* Pass true to always get a read lock on the triggers, so we are
* sure that no secondaries are added during truncation.
*/
acquireTriggerListReadLock();
triggerLock = true;
/* Truncate primary. */
int count = truncateInternal(locker, countRecords);
/* Truncate secondaries. */
for (int i = 0; i < triggerList.size(); i += 1) {
Object obj = triggerList.get(i);
if (obj instanceof SecondaryTrigger) {
SecondaryDatabase secDb = ((SecondaryTrigger) obj).getDb();
secDb.truncateInternal(locker, false);
}
}
operationOk = true;
return count;
} finally {
if (locker != null) {
locker.operationEnd(operationOk);
}
if (triggerLock) {
releaseTriggerListReadLock();
}
}