/* package */
DbEnv openEnvironment(final java.io.File home)
throws DatabaseException, java.io.FileNotFoundException {
final DbEnv dbenv = createEnvironment();
int openFlags = 0;
openFlags |= allowCreate ? DbConstants.DB_CREATE : 0;
openFlags |= initializeCache ? DbConstants.DB_INIT_MPOOL : 0;
openFlags |= initializeCDB ? DbConstants.DB_INIT_CDB : 0;
openFlags |= initializeLocking ? DbConstants.DB_INIT_LOCK : 0;
openFlags |= initializeLogging ? DbConstants.DB_INIT_LOG : 0;
openFlags |= initializeReplication ? DbConstants.DB_INIT_REP : 0;
openFlags |= joinEnvironment ? DbConstants.DB_JOINENV : 0;
openFlags |= lockDown ? DbConstants.DB_LOCKDOWN : 0;
openFlags |= isPrivate ? DbConstants.DB_PRIVATE : 0;
openFlags |= register ? DbConstants.DB_REGISTER : 0;
openFlags |= runRecovery ? DbConstants.DB_RECOVER : 0;
openFlags |= runFatalRecovery ? DbConstants.DB_RECOVER_FATAL : 0;
openFlags |= systemMemory ? DbConstants.DB_SYSTEM_MEM : 0;
openFlags |= threaded ? DbConstants.DB_THREAD : 0;
openFlags |= transactional ? DbConstants.DB_INIT_TXN : 0;
openFlags |= useEnvironment ? DbConstants.DB_USE_ENVIRON : 0;
openFlags |= useEnvironmentRoot ? DbConstants.DB_USE_ENVIRON_ROOT : 0;
boolean succeeded = false;
try {
dbenv.open((home == null) ? null : home.toString(),
openFlags, mode);
succeeded = true;
return dbenv;
} finally {
if (!succeeded)
try {
dbenv.close(0);
} catch (Throwable t) {
// Ignore it -- an exception is already in flight.
}
}
}