this.db = db;
this.key = copyEntry(key);
logger = db.getEnvironment().getEnvironmentImpl().getLogger();
/* Perform an auto-commit transaction to create the sequence. */
Locker locker = null;
Cursor cursor = null;
OperationStatus status = OperationStatus.NOTFOUND;
try {
locker = LockerFactory.getReadableLocker
(db.getEnvironment(), txn,
db.isTransactional(),
false /*readCommitedIsolation*/);
cursor = new Cursor(db, locker, null);
boolean sequenceExists = readData(cursor, null);
boolean isWritableLocker = !db.getConfig().getTransactional() ||
(locker.isTransactional() &&
!DbInternal.getEnvironmentImpl(db.getEnvironment()).
isReplicated());
if (sequenceExists) {
if (useConfig.getAllowCreate() &&
useConfig.getExclusiveCreate()) {
throw new SequenceExistsException
("ExclusiveCreate=true and the sequence record " +
"already exists.");
}
} else {
if (useConfig.getAllowCreate()) {
if (!isWritableLocker) {
if (cursor != null) {
cursor.close();
}
locker.operationEnd(OperationStatus.SUCCESS);
locker = LockerFactory.getWritableLocker
(db.getEnvironment(),
txn,
db.getDatabaseImpl().isInternalDb(),
db.isTransactional(),
db.getDatabaseImpl().isReplicated(),
autoCommitConfig);
cursor = new Cursor(db, locker, null);
}
/* Get the persistent fields from the config. */
rangeMin = useConfig.getRangeMin();
rangeMax = useConfig.getRangeMax();
increment = !useConfig.getDecrement();
wrapAllowed = useConfig.getWrap();
storedValue = useConfig.getInitialValue();
/*
* To avoid dependence on SerializableIsolation, try
* putNoOverwrite first. If it fails, then try to get an
* existing record.
*/
status = cursor.putNoOverwrite(key, makeData());
if (!readData(cursor, null)) {
/* A retry loop should be performed here. */
throw new IllegalStateException
("Sequence record removed during openSequence.");
}
status = OperationStatus.SUCCESS;
} else {
throw new SequenceNotFoundException
("AllowCreate=false and the sequence record " +
"does not exist.");
}
}
} finally {
if (cursor != null) {
cursor.close();
}
if (locker != null) {
locker.operationEnd(status);
}
}
/*
* cacheLast is initialized such that the cache will be considered