public interface Cursor
View
. Cursor instances can only be
safely used by one thread at a time, and they must be reset
when no longer needed. Instances can be exchanged by threads, as long as a
happens-before relationship is established. Without proper exclusion,
multiple threads interacting with a Cursor instance may cause database
corruption.
Methods which return LockResult
might acquire a lock to access
the requested entry. The return type indicates if the lock is still held
, and in what fashion. Except where indicated, a
LockTimeoutException
is thrown when a lock cannot be acquired in
time. When cursor is linked
to a transaction, it defines the
locking behavior and timeout. Otherwise, a lock is always acquired, with the
default
timeout.
If a LockFailureException
is thrown from any method, the Cursor
is positioned at the desired key, but the value is NOT_LOADED
.
View.newCursor
Modifier and Type | Field and Description |
---|---|
static byte[] |
NOT_LOADED
Empty marker which indicates that value exists but has not been
loaded . |
Modifier and Type | Method and Description |
---|---|
boolean |
autoload()
Returns the current autoload mode.
|
boolean |
autoload(boolean mode)
By default, values are loaded automatically, as they are seen.
|
default void |
commit(byte[] value)
Combined store and commit to the linked transaction.
|
default int |
compareKeyTo(byte[] rkey)
Compare the current key to the one given.
|
default int |
compareKeyTo(byte[] rkey,
int offset,
int length)
Compare the current key to the one given.
|
Cursor |
copy()
Returns a new independent Cursor, positioned where this one is, and
linked to the same transaction.
|
LockResult |
find(byte[] key)
Moves the Cursor to find the given key.
|
default LockResult |
findGe(byte[] key)
Moves the Cursor to find the first available entry greater than or equal
to the given key.
|
default LockResult |
findGt(byte[] key)
Moves the Cursor to find the first available entry greater than the
given key.
|
default LockResult |
findLe(byte[] key)
Moves the Cursor to find the first available entry less than or equal to
the given key.
|
default LockResult |
findLt(byte[] key)
Moves the Cursor to find the first available entry less than the given
key.
|
default LockResult |
findNearby(byte[] key)
Optimized version of the regular find method, which can perform fewer search steps if
the given key is in close proximity to the current one.
|
LockResult |
first()
Moves the Cursor to find the first available entry.
|
Ordering |
getOrdering()
Returns the key ordering for this cursor.
|
byte[] |
key()
Returns an uncopied reference to the current key, or null if Cursor is
unpositioned.
|
LockResult |
last()
Moves the Cursor to find the last available entry.
|
Transaction |
link()
Returns the transaction the cursor is currently linked to.
|
Transaction |
link(Transaction txn)
Link to a transaction, which can be null for auto-commit mode.
|
LockResult |
load()
Loads or reloads the value at the cursor's current position.
|
default LockResult |
lock()
Locks the current entry, as if by calling load.
|
LockResult |
next()
Moves to the Cursor to the next available entry.
|
default LockResult |
nextLe(byte[] limitKey)
Moves to the Cursor to the next available entry, but only when less than
or equal to the given limit key.
|
default LockResult |
nextLt(byte[] limitKey)
Moves to the Cursor to the next available entry, but only when less than
the given limit key.
|
LockResult |
previous()
Moves to the Cursor to the previous available entry.
|
default LockResult |
previousGe(byte[] limitKey)
Moves to the Cursor to the previous available entry, but only when
greater than or equal to the given limit key.
|
default LockResult |
previousGt(byte[] limitKey)
Moves to the Cursor to the previous available entry, but only when
greater than the given limit key.
|
LockResult |
random(byte[] lowKey,
byte[] highKey)
Moves the Cursor to a random entry, but not guaranteed to be chosen from
a uniform distribution.
|
void |
reset()
Resets Cursor and moves it to an undefined position.
|
LockResult |
skip(long amount)
Moves the Cursor by a relative amount of entries.
|
default LockResult |
skip(long amount,
byte[] limitKey,
boolean inclusive)
Moves the Cursor by a relative amount of entries, stopping sooner if the limit key is
reached.
|
void |
store(byte[] value)
Stores a value into the current entry, leaving the position
unchanged.
|
byte[] |
value()
Returns an uncopied reference to the current value, which might be null
or
NOT_LOADED . |
static final byte[] NOT_LOADED
loaded
.Ordering getOrdering()
Transaction link(Transaction txn)
IllegalArgumentException
- if transaction belongs to another database instanceTransaction link()
byte[] key()
byte[] value()
NOT_LOADED
. Array contents can be safely modified.boolean autoload(boolean mode)
manually loaded
. When a Transformer
is
used, the value might still be loaded automatically. When the value exists but hasn't
been loaded, the value field of the cursor is set to NOT_LOADED
.mode
- false to disableboolean autoload()
default int compareKeyTo(byte[] rkey)
rkey
- key to compare toNullPointerException
- if current key or rkey is nulldefault int compareKeyTo(byte[] rkey, int offset, int length)
rkey
- key to compare tooffset
- offset into rkeylength
- length of rkeyNullPointerException
- if current key or rkey is nullLockResult first() throws IOException
UNOWNED
, ACQUIRED
, OWNED_SHARED
, OWNED_UPGRADABLE
, or OWNED_EXCLUSIVE
IOException
LockResult last() throws IOException
UNOWNED
, ACQUIRED
, OWNED_SHARED
, OWNED_UPGRADABLE
, or OWNED_EXCLUSIVE
IOException
LockResult skip(long amount) throws IOException
Skipping by 1 is equivalent to calling next
, and
skipping by -1 is equivalent to calling previous
. A
skip of 0 merely checks and returns the lock state for the current
key. Lock acquisition only applies to the target entry — no locks
are acquired for entries in between.
UNOWNED
, ACQUIRED
, OWNED_SHARED
, OWNED_UPGRADABLE
, or OWNED_EXCLUSIVE
IllegalStateException
- if position is undefined at invocation timeIOException
default LockResult skip(long amount, byte[] limitKey, boolean inclusive) throws IOException
Skipping by 1 is equivalent to calling nextLe
, nextLt
or next
, depending on which type of limit was provided. Likewise, skipping
by -1 is equivalent to calling previousGe
, previousGt
or previous
. A skip of 0 merely checks and returns the
lock state for the current key. Lock acquisition only applies to the target entry
— no locks are acquired for entries in between.
limitKey
- limit key; pass null for no limitinclusive
- true if limit is inclusive, false for exclusiveUNOWNED
, ACQUIRED
, OWNED_SHARED
, OWNED_UPGRADABLE
, or OWNED_EXCLUSIVE
IllegalStateException
- if position is undefined at invocation timeIOException
LockResult next() throws IOException
UNOWNED
, ACQUIRED
, OWNED_SHARED
, OWNED_UPGRADABLE
, or OWNED_EXCLUSIVE
IllegalStateException
- if position is undefined at invocation timeIOException
default LockResult nextLe(byte[] limitKey) throws IOException
UNOWNED
, ACQUIRED
, OWNED_SHARED
, OWNED_UPGRADABLE
, or OWNED_EXCLUSIVE
NullPointerException
- if limit key is nullIllegalStateException
- if position is undefined at invocation timeIOException
default LockResult nextLt(byte[] limitKey) throws IOException
UNOWNED
, ACQUIRED
, OWNED_SHARED
, OWNED_UPGRADABLE
, or OWNED_EXCLUSIVE
NullPointerException
- if limit key is nullIllegalStateException
- if position is undefined at invocation timeIOException
LockResult previous() throws IOException
UNOWNED
, ACQUIRED
, OWNED_SHARED
, OWNED_UPGRADABLE
, or OWNED_EXCLUSIVE
IllegalStateException
- if position is undefined at invocation timeIOException
default LockResult previousGe(byte[] limitKey) throws IOException
UNOWNED
, ACQUIRED
, OWNED_SHARED
, OWNED_UPGRADABLE
, or OWNED_EXCLUSIVE
NullPointerException
- if limit key is nullIllegalStateException
- if position is undefined at invocation timeIOException
default LockResult previousGt(byte[] limitKey) throws IOException
UNOWNED
, ACQUIRED
, OWNED_SHARED
, OWNED_UPGRADABLE
, or OWNED_EXCLUSIVE
NullPointerException
- if limit key is nullIllegalStateException
- if position is undefined at invocation timeIOException
LockResult find(byte[] key) throws IOException
Ownership of the key instance transfers to the Cursor, and it must not be modified after calling this method.
UNOWNED
, ACQUIRED
, OWNED_SHARED
, OWNED_UPGRADABLE
, or OWNED_EXCLUSIVE
NullPointerException
- if key is nullIOException
default LockResult findGe(byte[] key) throws IOException
Ownership of the key instance transfers to the Cursor, and it must not be modified after calling this method.
UNOWNED
, ACQUIRED
, OWNED_SHARED
, OWNED_UPGRADABLE
, or OWNED_EXCLUSIVE
NullPointerException
- if key is nullIOException
default LockResult findGt(byte[] key) throws IOException
Ownership of the key instance transfers to the Cursor, and it must not be modified after calling this method.
UNOWNED
, ACQUIRED
, OWNED_SHARED
, OWNED_UPGRADABLE
, or OWNED_EXCLUSIVE
NullPointerException
- if key is nullIOException
default LockResult findLe(byte[] key) throws IOException
Ownership of the key instance transfers to the Cursor, and it must not be modified after calling this method.
UNOWNED
, ACQUIRED
, OWNED_SHARED
, OWNED_UPGRADABLE
, or OWNED_EXCLUSIVE
NullPointerException
- if key is nullIOException
default LockResult findLt(byte[] key) throws IOException
Ownership of the key instance transfers to the Cursor, and it must not be modified after calling this method.
UNOWNED
, ACQUIRED
, OWNED_SHARED
, OWNED_UPGRADABLE
, or OWNED_EXCLUSIVE
NullPointerException
- if key is nullIOException
default LockResult findNearby(byte[] key) throws IOException
Ownership of the key instance transfers to the Cursor, and it must not be modified after calling this method.
UNOWNED
, ACQUIRED
, OWNED_SHARED
, OWNED_UPGRADABLE
, or OWNED_EXCLUSIVE
NullPointerException
- if key is nullIOException
LockResult random(byte[] lowKey, byte[] highKey) throws IOException
lowKey
- inclusive lowest key in the selectable range; pass null for open rangehighKey
- exclusive highest key in the selectable range; pass null for open rangeUNOWNED
, ACQUIRED
, OWNED_SHARED
, OWNED_UPGRADABLE
, or OWNED_EXCLUSIVE
IOException
default LockResult lock() throws IOException
By default, this method simply calls load. Subclasses are encouraged to provide a more efficient implementation.
UNOWNED
, ACQUIRED
, OWNED_SHARED
, OWNED_UPGRADABLE
, or OWNED_EXCLUSIVE
IllegalStateException
- if position is undefined at invocation timeIOException
LockResult load() throws IOException
UNOWNED
, ACQUIRED
, OWNED_SHARED
, OWNED_UPGRADABLE
, or OWNED_EXCLUSIVE
IllegalStateException
- if position is undefined at invocation timeIOException
void store(byte[] value) throws IOException
value
method will be the same
instance as was provided to this method.value
- value to store; pass null to deleteIllegalStateException
- if position is undefined at invocation timeViewConstraintException
- if value is not permittedIOException
default void commit(byte[] value) throws IOException
value
- value to store; pass null to deleteIllegalStateException
- if position is undefined at invocation timeViewConstraintException
- if value is not permittedIOException
Cursor copy()
void reset()
Copyright © 2011–2017 Cojen. All rights reserved.