public interface Cursor
extends java.io.Closeable
Cursor allows to access key/value pairs of a Store in both successive (ascending and descending)
and random order. Cursor can be opened for a Store in a Transaction. Both key
(getKey()) and value (getValue()) are accessible as ByteIterable
instances. Finally, any cursor should always be closed.
Each newly created cursor points to a "virtual" key/value pair which is prior to the first (leftmost) pair. Use
getNext() to move to the first and getPrev() to last (rightmost) key/value pair. You
can move Cursor to the last (rightmost) position from any other position using getLast().
Store,
Store.openCursor(Transaction)| Modifier and Type | Method and Description |
|---|---|
void |
close()
This method should always be called as immediately as possible to avoid unnecessary performance degradation.
|
int |
count() |
boolean |
deleteCurrent()
Deletes current key/value pair in the Store and returns
true if deletion succeeded. |
@NotNull ByteIterable |
getKey() |
boolean |
getLast()
Moves the
Cursor to the last (rightmost) key/value pair if any exists. |
boolean |
getNext()
Moves the
Cursor to the next key/value pair. |
boolean |
getNextDup()
Moves the
Cursor to the next key/value pair with the same key. |
boolean |
getNextNoDup()
Moves the
Cursor to the next key/value pair with the nearest key different from current one. |
boolean |
getPrev()
Moves the
Cursor to the previous key/value pair. |
boolean |
getPrevDup()
Moves the
Cursor to the previous key/value pair with the same key. |
boolean |
getPrevNoDup()
Moves the
Cursor to the previous key/value pair with the nearest key different from current one. |
boolean |
getSearchBoth(@NotNull ByteIterable key,
@NotNull ByteIterable value)
Moves the
Cursor to the key/value pair with the specified key and value and returns true if
the pair exists in the Store. |
@Nullable ByteIterable |
getSearchBothRange(@NotNull ByteIterable key,
@NotNull ByteIterable value)
Moves the
Cursor to the first pair in the Store whose key matches the specified key and
whose value is equal to or greater than the specified value. |
@Nullable ByteIterable |
getSearchKey(@NotNull ByteIterable key)
Moves the
Cursor to the specified key, and returns the value associated with the key. |
@Nullable ByteIterable |
getSearchKeyRange(@NotNull ByteIterable key)
Moves the
Cursor to the first pair in the Store whose key is equal to or greater than the
specified key. |
@NotNull ByteIterable |
getValue() |
boolean |
isMutable()
Cursor is mutable if it is created in a transaction which has dirty (not flushed/committed) modifications.
|
boolean getNext()
Cursor to the next key/value pair. If the Cursor is just created the method moves
it to the first (leftmost) key/value pair.
E.g., traversing all key/value pairs of a Store in ascending order looks as follows:
try (Cursor cursor = store.openCursor(txn)) {
while (cursor.getNext()) {
cursor.getKey(); // current key
cursor.getValue(); // current value
}
}
true if next pair existsgetNextDup(),
getNextNoDup(),
getPrev(),
getPrevDup(),
getPrevNoDup()boolean getNextDup()
Cursor to the next key/value pair with the same key.true if next pair with the same key existsgetNext(),
getNextNoDup(),
getPrev(),
getPrevDup(),
getPrevNoDup()boolean getNextNoDup()
Cursor to the next key/value pair with the nearest key different from current one.true if next pair existsgetNext(),
getNextDup(),
getPrev(),
getPrevDup(),
getPrevNoDup()boolean getLast()
Cursor to the last (rightmost) key/value pair if any exists. Returns true if the
Store has at least one key/value pair.true if the Cursor points to the last key/value pairgetNext(),
getNextDup(),
getNextNoDup(),
getPrev(),
getPrevDup(),
getPrevNoDup()boolean getPrev()
Cursor to the previous key/value pair. If the Cursor is just created the method moves
it to the last (rightmost) key/value pair.
E.g., traversing all key/value pairs of a Store in descending order looks as follows:
try (Cursor cursor = store.openCursor(txn)) {
while (cursor.getPrev()) {
cursor.getKey(); // current key
cursor.getValue(); // current value
}
}
true if previous pair existsgetNext(),
getNextDup(),
getNextNoDup(),
getPrevDup(),
getPrevNoDup()boolean getPrevDup()
Cursor to the previous key/value pair with the same key.true if previous pair with the same key existsgetNext(),
getNextDup(),
getNextNoDup(),
getPrev(),
getPrevNoDup()boolean getPrevNoDup()
Cursor to the previous key/value pair with the nearest key different from current one.true if previous pair existsgetNext(),
getNextDup(),
getNextNoDup(),
getPrev(),
getPrevDup()@NotNull @NotNull ByteIterable getKey()
ByteIterable,
getValue()@NotNull @NotNull ByteIterable getValue()
ByteIterable,
getKey()@Nullable @Nullable ByteIterable getSearchKey(@NotNull @NotNull ByteIterable key)
Cursor to the specified key, and returns the value associated with the key. In
stores with key duplicates, if the matching key has duplicate values, the Cursor moves
to the first (leftmost) key/value pair.
If the method fails for any reason, it returns null, and the position of the Cursor will be unchanged.
key - the key to search fornull if no such value existsgetSearchKeyRange(ByteIterable),
getSearchBoth(ByteIterable, ByteIterable),
getSearchBothRange(ByteIterable, ByteIterable)@Nullable @Nullable ByteIterable getSearchKeyRange(@NotNull @NotNull ByteIterable key)
Cursor to the first pair in the Store whose key is equal to or greater than the
specified key. It returns not-null value if it succeeds or null if nothing is found, and the position of
the Cursor will be unchanged.key - the key to search fornull if nothing is foundgetSearchKey(ByteIterable),
getSearchBoth(ByteIterable, ByteIterable),
getSearchBothRange(ByteIterable, ByteIterable)boolean getSearchBoth(@NotNull
@NotNull ByteIterable key,
@NotNull
@NotNull ByteIterable value)
Cursor to the key/value pair with the specified key and value and returns true if
the pair exists in the Store. Otherwise the position of the Cursor will be unchanged.key - the key to search forvalue - the value to search fortrue if the pair with the specified key and value exists in the StoregetSearchKey(ByteIterable),
getSearchKeyRange(ByteIterable),
getSearchBothRange(ByteIterable, ByteIterable)@Nullable @Nullable ByteIterable getSearchBothRange(@NotNull @NotNull ByteIterable key, @NotNull @NotNull ByteIterable value)
Cursor to the first pair in the Store whose key matches the specified key and
whose value is equal to or greater than the specified value. If the Store supports key duplicates, then
on matching the key, the Cursor is moved to the duplicate pair with the smallest value that is equal to
or greater than the specified value. Like the getSearchKeyRange(ByteIterable) method, it returns
not-null value if it succeeds or null if nothing is found, and the position of the Cursor will
be unchanged.key - the key to search forvalue - the value to search fornull if nothing is foundgetSearchKey(ByteIterable),
getSearchKeyRange(ByteIterable),
getSearchBoth(ByteIterable, ByteIterable)int count()
boolean isMutable()
true if cursor is mutablevoid close()
close in interface java.lang.AutoCloseableclose in interface java.io.Closeableboolean deleteCurrent()
true if deletion succeeded.true if current key/value pair was deleted