* Check that the open configuration doesn't conflict with the
* environmentImpl configuration.
*/
validateDbConfigAgainstEnv(dbConfig, databaseName);
Locker locker = null;
boolean operationOk = false;
boolean dbIsClosing = false;
try {
/*
* Does this database exist? Get a transaction to use. If the
* database exists already, we really only need a readable locker.
* If the database must be created, we need a writable one.
* Unfortunately, we have to get the readable one first before we
* know whether we have to create. However, if we need to write
* during initialization (to populate a secondary for example),
* then just create a writable locker now.
*/
boolean isWritableLocker;
if (needWritableLockerForInit) {
locker = LockerFactory.getWritableLocker
(this,
txn,
dbConfig.getTransactional(),
true, // retainNonTxnLocks
null);
isWritableLocker = true;
} else {
locker = LockerFactory.getReadableLocker
(this, txn,
dbConfig.getTransactional(),
true, // retainNonTxnLocks
false); // readCommittedIsolation
isWritableLocker = !dbConfig.getTransactional() ||
locker.isTransactional();
}
DatabaseImpl database = environmentImpl.getDb(locker,
databaseName,
newDb);
boolean databaseExists =
(database == null) ? false :
((database.isDeleted()) ? false : true);
if (databaseExists) {
if (dbConfig.getAllowCreate() &&
dbConfig.getExclusiveCreate()) {
/* We intended to create this, but it already exists. */
dbIsClosing = true;
throw new DatabaseException
("Database " + databaseName + " already exists");
}
newDb.initExisting(this, locker, database, dbConfig);
} else {
/* No database. Create if we're allowed to. */
if (dbConfig.getAllowCreate()) {
/*
* We're going to have to do some writing. Switch to a
* writable locker if we don't already have one.
*/
if (!isWritableLocker) {
locker.operationEnd(OperationStatus.SUCCESS);
locker = LockerFactory.getWritableLocker
(this,
txn,
dbConfig.getTransactional(),
true, // retainNonTxnLocks
null);
isWritableLocker = true;
}
newDb.initNew(this, locker, databaseName, dbConfig);
} else {
/* We aren't allowed to create this database. */
throw new DatabaseNotFoundException("Database " +
databaseName +
" not found.");
}
}
operationOk = true;
addReferringHandle(newDb);
} finally {
/*
* Tell the transaction that this operation is over. Some types of
* transactions (BasicLocker and AutoTxn) will actually finish. The
* transaction can decide if it is finishing and if it needs to
* transfer the db handle lock it owns to someone else.
*/
if (locker != null) {
locker.setHandleLockOwner(operationOk, newDb, dbIsClosing);
locker.operationEnd(operationOk);
}
}
}