/** * @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(); } } }
public BDBCreator(String tableName, ArrayList<Integer> keyPositions, int secondaryIndex) { /* Creates and loads a BDB table with a secondary index on the column defined by*/ this.tableName = tableName.toLowerCase(); this.keyPositions = keyPositions; this.secIndexPos = secondaryIndex; this.tMap = Main.indexTypeMaps.get(this.tableName); setEnvironment(); dbConfig = new DatabaseConfig(); dbConfig.setAllowCreate(true); myDB = myDbEnvironment.openDatabase(null, this.tableName, dbConfig); SecondaryConfig secConfig = new SecondaryConfig(); secConfig.setAllowCreate(true); secConfig.setSortedDuplicates(true); createSecDB(secConfig); setConfig(dbConfig, secConfig); loadData(); if (secDB != null) { secDB.close(); } if (myDB != null) { myDB.close(); } closeEnvironment(); }
public void databaseUpdated( Database db, Locker locker, DatabaseEntry priKey, DatabaseEntry oldData, DatabaseEntry newData) throws DatabaseException { if (newData == null) { secDb.onForeignKeyDelete(locker, priKey); } }
public void triggerRemoved(Database db) { secDb.clearForeignKeyTrigger(); }