DbSequence openSequence(final Db db,
final DbTxn txn,
final DatabaseEntry key)
throws DatabaseException {
final DbSequence seq = createSequence(db);
// The DB_THREAD flag is inherited from the database
boolean threaded = ((db.get_open_flags() & DbConstants.DB_THREAD) != 0);
int openFlags = 0;
openFlags |= allowCreate ? DbConstants.DB_CREATE : 0;
openFlags |= exclusiveCreate ? DbConstants.DB_EXCL : 0;
openFlags |= threaded ? DbConstants.DB_THREAD : 0;
if (db.get_transactional() && txn == null)
openFlags |= DbConstants.DB_AUTO_COMMIT;
configureSequence(seq, DEFAULT);
boolean succeeded = false;
try {
seq.open(txn, key, openFlags);
succeeded = true;
return seq;
} finally {
if (!succeeded)
try {
seq.close(0);
} catch (Throwable t) {
// Ignore it -- an exception is already in flight.
}
}
}