} else {
err = db.get(cursor, key, data,
(pos == Db.DB_NEXT_NODUP)
? Db.DB_PREV_NODUP : Db.DB_PREV);
if (err != 0) {
throw new DbException("Range internal error", err);
}
err = Db.DB_NOTFOUND;
}
}
}
} else if (pos == Db.DB_LAST || pos == Db.DB_PREV ||
pos == Db.DB_PREV_NODUP) {
if (wasInvalid) pos = Db.DB_LAST;
if (isSingleKey) {
if (pos == Db.DB_PREV_NODUP) {
err = Db.DB_NOTFOUND;
} else if (endKey == null) {
// create end key now for use in PREV processing below
endKey = new DataThang(beginKey);
endKey.increment();
}
}
if (err != 0) {
} else if (endKey == null) {
err = db.get(cursor, key, data, pos | extraFlags);
} else {
if (pos == Db.DB_LAST) {
key.copy(endKey);
err = db.get(cursor, key, data,
Db.DB_SET_RANGE | extraFlags);
if (err == 0) {
err = db.get(cursor, key, data,
((origPos == Db.DB_PREV_NODUP)
? Db.DB_PREV_NODUP : Db.DB_PREV)
| extraFlags);
} else {
err = db.get(cursor, key, data,
Db.DB_LAST | extraFlags);
}
} else {
err = db.get(cursor, key, data, pos | extraFlags);
}
}
if (err == 0 && beginKey != null) {
int compare = key.compareTo(beginKey);
if (isSingleKey ? (compare != 0) : (compare < 0)) {
if (pos == Db.DB_LAST) {
err = setInvalid(key, data);
} else {
err = db.get(cursor, key, data,
(pos == Db.DB_PREV_NODUP)
? Db.DB_NEXT_NODUP : Db.DB_NEXT);
if (err != 0) {
throw new DbException("Range internal error", err);
}
err = Db.DB_NOTFOUND;
}
}
}
} else if (pos == Db.DB_CONSUME) {
err = db.get(cursor, key, data, flags);
} else {
throw new DbException("Unsupported flag", EINVAL);
}
if (err == 0) isCursorValid = true;
return err;