throw new DatabaseException
("Database " + databaseName + " not found in map tree");
}
/* Call getCurrentLN to write lock the nameLN. */
NameLN nameLN = (NameLN)
nameCursor.getCurrentLNAlreadyLatched(LockType.WRITE);
assert nameLN != null; /* Should be locked. */
/*
* Check the open handle count after we have the write lock and no
* other transactions can open. XXX, another handle using the same
* txn could open ...
*/
int handleCount = oldDatabase.getReferringHandleCount();
if (handleCount > 1) {
throw new DatabaseException("Can't truncate database " +
databaseName + "," + handleCount +
" open databases exist");
}
/*
* Make a new database with an empty tree. Make the nameLN refer to
* the id of the new database.
*/
DatabaseImpl newDb;
DatabaseId newId = new DatabaseId(getNextDbId());
newDb = (DatabaseImpl) oldDatabase.clone();
newDb.setId(newId);
newDb.setTree(new Tree(newDb));
/* Insert the new db into id -> name map */
CursorImpl idCursor = null;
boolean operationOk = false;
AutoTxn autoTxn = null;
try {
autoTxn = new AutoTxn(envImpl, new TransactionConfig());
idCursor = new CursorImpl(idDatabase, autoTxn);
idCursor.putLN(newId.getBytes(),
new MapLN(newDb), false);
operationOk = true;
} finally {
if (idCursor != null) {
idCursor.close();
}
if (autoTxn != null) {
autoTxn.operationEnd(operationOk);
}
}
nameLN.setId(newDb.getId());
/* Record utilization profile changes for the deleted database. */
int recordCount = oldDatabase.recordObsoleteNodes();
/* Schedule database for final deletion during commit. */