final DbTxn txn,
final String fileName,
final String databaseName)
throws DatabaseException, java.io.FileNotFoundException {
final Db db = createDatabase(dbenv);
// The DB_THREAD flag is inherited from the environment
// (defaulting to ON if no environment handle is supplied).
boolean threaded = (dbenv == null ||
(dbenv.get_open_flags() & DbConstants.DB_THREAD) != 0);
int openFlags = 0;
openFlags |= allowCreate ? DbConstants.DB_CREATE : 0;
openFlags |= readUncommitted ? DbConstants.DB_READ_UNCOMMITTED : 0;
openFlags |= exclusiveCreate ? DbConstants.DB_EXCL : 0;
openFlags |= multiversion ? DbConstants.DB_MULTIVERSION : 0;
openFlags |= noMMap ? DbConstants.DB_NOMMAP : 0;
openFlags |= readOnly ? DbConstants.DB_RDONLY : 0;
openFlags |= threaded ? DbConstants.DB_THREAD : 0;
openFlags |= truncate ? DbConstants.DB_TRUNCATE : 0;
if (transactional && txn == null)
openFlags |= DbConstants.DB_AUTO_COMMIT;
boolean succeeded = false;
try {
configureDatabase(db, DEFAULT);
db.open(txn, fileName, databaseName, type.getId(), openFlags, mode);
succeeded = true;
return db;
} finally {
if (!succeeded)
try {
db.close(0);
} catch (Throwable t) {
// Ignore it -- an exception is already in flight.
}
}
}