/** * @deprecated It has not been possible to implement this method with correct transactional * semantics without incurring a performance penalty on all Database operations. Truncate * functionality has been moved to Environment.truncateDatabase(), which requires that all * Database handles on the database are closed before the truncate operation can execute. */ public int truncate(Transaction txn, boolean countRecords) throws DatabaseException { checkEnv(); checkRequiredDbState(OPEN, "Can't call Database.truncate"); checkWritable("truncate"); 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(); } } }
/** * Notifies associated triggers when a put() or delete() is performed on the primary. This method * is normally called only if hasTriggers() has returned true earlier. This avoids acquiring a * shared latch for primaries with no triggers. If a trigger is added during the update process, * there is no requirement to immediately start updating it. * * @param locker the internal locker. * @param priKey the primary key. * @param oldData the primary data before the change, or null if the record did not previously * exist. * @param newData the primary data after the change, or null if the record has been deleted. */ void notifyTriggers( Locker locker, DatabaseEntry priKey, DatabaseEntry oldData, DatabaseEntry newData) throws DatabaseException { acquireTriggerListReadLock(); try { for (int i = 0; i < triggerList.size(); i += 1) { DatabaseTrigger trigger = (DatabaseTrigger) triggerList.get(i); /* Notify trigger. */ trigger.databaseUpdated(this, locker, priKey, oldData, newData); } } finally { releaseTriggerListReadLock(); } }
public List getSecondaryDatabases() throws DatabaseException { List list = new ArrayList(); if (hasTriggers()) { acquireTriggerListReadLock(); try { for (int i = 0; i < triggerList.size(); i += 1) { Object obj = triggerList.get(i); if (obj instanceof SecondaryTrigger) { list.add(((SecondaryTrigger) obj).getDb()); } } } finally { releaseTriggerListReadLock(); } } else { } return list; }