Interface View
- All Known Subinterfaces:
Index
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault Comparator<byte[]> Returns a key comparator for the ordering of this view, or null if unordered.default longcount(byte[] lowKey, boolean lowInclusive, byte[] highKey, boolean highInclusive) Non-transactionally counts the number of entries within the given range.default longcount(byte[] lowKey, byte[] highKey) Non-transactionally counts the number of entries within the given range.default booleandelete(Transaction txn, byte[] key) Unconditionally removes the entry associated with the given key.default byte[]exchange(Transaction txn, byte[] key, byte[] value) Unconditionally associates a value with the given key, returning the previous value.default booleanexists(Transaction txn, byte[] key) Checks if an entry for the given key exists.default booleaninsert(Transaction txn, byte[] key, byte[] value) Associates a value with the given key, unless a corresponding value already exists.default booleanisEmpty()Non-transactionally determines if the view has nothing in it.default booleanReturns true if the value-modifying methods of this view are atomic, even when not using transactions.booleanReturns true if any attempt to modify this view causes anUnmodifiableViewExceptionto be thrown.default byte[]load(Transaction txn, byte[] key) Returns a copy of the value for the given key, or null if no matching entry exists.lockCheck(Transaction txn, byte[] key) Checks the lock ownership for the given key.lockExclusive(Transaction txn, byte[] key) Explicitly acquire an exclusive lock for the given key, denying any additional locks.lockShared(Transaction txn, byte[] key) Explicitly acquire a shared lock for the given key, denying exclusive locks.lockUpgradable(Transaction txn, byte[] key) Explicitly acquire an upgradable lock for the given key, denying exclusive and additional upgradable locks.default CursornewAccessor(Transaction txn, byte[] key) Returns a cursor intended for accessing values in chunks, permitting them to be larger than what can fit in main memory.newCursor(Transaction txn) Returns a new cursor over this view.default TransactionnewTransaction(DurabilityMode durabilityMode) Returns a new transaction which is compatible with this view.ordering()Returns the key ordering for this view.default booleanremove(Transaction txn, byte[] key, byte[] value) Removes the entry associated with the given key, but only if the given value matches.default booleanreplace(Transaction txn, byte[] key, byte[] value) Associates a value with the given key, but only if a corresponding value already exists.default voidstore(Transaction txn, byte[] key, byte[] value) Unconditionally associates a value with the given key.default LockResulttouch(Transaction txn, byte[] key) Touch the given key as if callingload, but instead only acquiring any necessary locks.default LockResulttryLockExclusive(Transaction txn, byte[] key, long nanosTimeout) Explicitly acquire an exclusive lock for the given key, denying any additional locks.default LockResulttryLockShared(Transaction txn, byte[] key, long nanosTimeout) Explicitly acquire a shared lock for the given key, denying exclusive locks.default LockResulttryLockUpgradable(Transaction txn, byte[] key, long nanosTimeout) Explicitly acquire an upgradable lock for the given key, denying exclusive and additional upgradable locks.default booleanupdate(Transaction txn, byte[] key, byte[] value) Associates a value with the given key, but only if the given value differs from the existing value.default booleanupdate(Transaction txn, byte[] key, byte[] oldValue, byte[] newValue) Associates a value with the given key, but only if the given old value matches the existing value.default ViewviewDifference(Combiner combiner, View second) Returns a view which represents the set difference of this view and a second one.default ViewviewFiltered(Filter filter) Returns a sub-view, backed by this one, whose entries have been filtered out.default ViewviewGe(byte[] key) Returns a sub-view, backed by this one, whose keys are greater than or equal to the given key.default ViewviewGt(byte[] key) Returns a sub-view, backed by this one, whose keys are greater than the given key.default ViewviewIntersection(Combiner combiner, View second) Returns a view which represents the set intersection of this view and a second one.default ViewviewKeys()Returns a view, backed by this one, which only provides the keys.default ViewviewLe(byte[] key) Returns a sub-view, backed by this one, whose keys are less than or equal to the given key.default ViewviewLt(byte[] key) Returns a sub-view, backed by this one, whose keys are less than the given key.default ViewviewPrefix(byte[] prefix, int trim) Returns a sub-view, backed by this one, whose keys start with the given prefix.default ViewReturns a view, backed by this one, whose natural order is reversed.default ViewviewTransformed(Transformer transformer) Returns a sub-view, backed by this one, whose entries have been filtered out and transformed.default ViewReturns a view which represents the set union of this view and a second one.default ViewReturns a view, backed by this one, whose entries cannot be modified.
-
Method Details
-
ordering
Ordering ordering()Returns the key ordering for this view. -
comparator
Returns a key comparator for the ordering of this view, or null if unordered. -
newCursor
Returns a new cursor over this view.Note that passing null for the transaction doesn't provide cursor stability with respect to updates. Pass an explicit transaction and call
committo apply each update.- Parameters:
txn- optional transaction for Cursor tolinkto; pass null for auto-commit mode- Returns:
- a new unpositioned cursor
- Throws:
IllegalStateException- if transaction belongs to another database instance
-
newAccessor
Returns a cursor intended for accessing values in chunks, permitting them to be larger than what can fit in main memory. Essentially, this is a convenience method which disablesautoload, and then positions the cursor at the given key.Note that passing null for the transaction doesn't provide cursor stability with respect to updates. Instead, pass an explicit transaction and call
committo apply each update.If the entry must be locked, ownership of the key instance is transferred. The key must not be modified after calling this method.
- Parameters:
txn- optional transaction; pass null for auto-commit modekey- non-null key- Returns:
- non-null cursor
- Throws:
NullPointerException- if key is nullIllegalStateException- if transaction belongs to another database instanceViewConstraintException- if key is not allowedIOException
-
newTransaction
Returns a new transaction which is compatible with this view. If the provided durability mode is null, a default mode is selected.- Throws:
UnsupportedOperationException- if not supported
-
isEmpty
Non-transactionally determines if the view has nothing in it. If any transactions are concurrently accessing the view, the implementation might return false even though the count method would have returned zero. A return value of true always guarantees that the count is zero. In other words, false negatives are possible, but false positives aren't.- Throws:
IOException
-
count
Non-transactionally counts the number of entries within the given range. Implementations of this method typically scan over the entries, and so it shouldn't be expected to run in constant time.- Parameters:
lowKey- inclusive lowest key in the counted range; pass null for open rangehighKey- exclusive highest key in the counted range; pass null for open range- Throws:
IOException
-
count
default long count(byte[] lowKey, boolean lowInclusive, byte[] highKey, boolean highInclusive) throws IOException Non-transactionally counts the number of entries within the given range. Implementations of this method typically scan over the entries, and so it shouldn't be expected to run in constant time.- Parameters:
lowKey- lowest key in the counted range; pass null for open rangelowInclusive- true for inclusive key, false for exclusive, ignored if key is nullhighKey- highest key in the counted range; pass null for open rangehighInclusive- true for inclusive key, false for exclusive, ignored if key is null- Throws:
IOException
-
load
Returns a copy of the value for the given key, or null if no matching entry exists.If the entry must be locked, ownership of the key instance is transferred. The key must not be modified after calling this method.
- Parameters:
txn- optional transaction; pass null forREAD_COMMITTEDlocking behaviorkey- non-null key- Returns:
- copy of value, or null if entry doesn't exist
- Throws:
NullPointerException- if key is nullIllegalStateException- if transaction belongs to another database instanceIOException
-
exists
Checks if an entry for the given key exists. This method should be called only if the value doesn't need to be loaded or stored — calling exists and then calling a load or store method is typically less efficient than skipping the exists check entirely.If the entry must be locked, ownership of the key instance is transferred. The key must not be modified after calling this method.
- Parameters:
txn- optional transaction; pass null forREAD_COMMITTEDlocking behaviorkey- non-null key- Returns:
- true if entry exists
- Throws:
NullPointerException- if key is nullIllegalStateException- if transaction belongs to another database instanceIOException
-
store
Unconditionally associates a value with the given key.If the entry must be locked, ownership of the key instance is transferred. The key must not be modified after calling this method.
- Parameters:
txn- optional transaction; pass null for auto-commit modekey- non-null keyvalue- value to store; pass null to delete- Throws:
NullPointerException- if key is nullIllegalStateException- if transaction belongs to another database instanceViewConstraintException- if entry is not permittedIOException
-
exchange
Unconditionally associates a value with the given key, returning the previous value.If the entry must be locked, ownership of the key instance is transferred. The key must not be modified after calling this method.
- Parameters:
txn- optional transaction; pass null for auto-commit modekey- non-null keyvalue- value to store; pass null to delete- Returns:
- copy of previous value, or null if none
- Throws:
NullPointerException- if key is nullIllegalStateException- if transaction belongs to another database instanceViewConstraintException- if entry is not permittedIOException
-
insert
Associates a value with the given key, unless a corresponding value already exists. Equivalent to:update(txn, key, null, value)If the entry must be locked, ownership of the key instance is transferred. The key must not be modified after calling this method.
- Parameters:
txn- optional transaction; pass null for auto-commit modekey- non-null keyvalue- value to insert, which can be null- Returns:
- false if entry already exists
- Throws:
NullPointerException- if key is nullIllegalStateException- if transaction belongs to another database instanceViewConstraintException- if entry is not permittedIOException
-
replace
Associates a value with the given key, but only if a corresponding value already exists.If the entry must be locked, ownership of the key instance is transferred. The key must not be modified after calling this method.
- Parameters:
txn- optional transaction; pass null for auto-commit modekey- non-null keyvalue- value to insert; pass null to delete- Returns:
- false if no existing entry
- Throws:
NullPointerException- if key is nullIllegalStateException- if transaction belongs to another database instanceViewConstraintException- if entry is not permittedIOException
-
update
Associates a value with the given key, but only if the given value differs from the existing value.If the entry must be locked, ownership of the key instance is transferred. The key must not be modified after calling this method.
- Parameters:
txn- optional transaction; pass null for auto-commit modekey- non-null keyvalue- value to update to; pass null to delete- Returns:
- false if given value matches existing value
- Throws:
NullPointerException- if key is nullIllegalStateException- if transaction belongs to another database instanceViewConstraintException- if entry is not permittedIOException
-
update
default boolean update(Transaction txn, byte[] key, byte[] oldValue, byte[] newValue) throws IOException Associates a value with the given key, but only if the given old value matches the existing value.If the entry must be locked, ownership of the key instance is transferred. The key must not be modified after calling this method.
- Parameters:
txn- optional transaction; pass null for auto-commit modekey- non-null keyoldValue- expected existing value, which can be nullnewValue- new value to update to; pass null to delete- Returns:
- false if existing value doesn't match
- Throws:
NullPointerException- if key is nullIllegalStateException- if transaction belongs to another database instanceViewConstraintException- if entry is not permittedIOException
-
delete
Unconditionally removes the entry associated with the given key. Equivalent to:replace(txn, key, null)If the entry must be locked, ownership of the key instance is transferred. The key must not be modified after calling this method.
- Parameters:
txn- optional transaction; pass null for auto-commit modekey- non-null key- Returns:
- false if no existing entry
- Throws:
NullPointerException- if key is nullIllegalStateException- if transaction belongs to another database instanceViewConstraintException- if remove is not permittedIOException
-
remove
Removes the entry associated with the given key, but only if the given value matches. Equivalent to:update(txn, key, value, null)If the entry must be locked, ownership of the key instance is transferred. The key must not be modified after calling this method.
- Parameters:
txn- optional transaction; pass null for auto-commit modekey- non-null keyvalue- expected existing value, which can be null- Returns:
- false if existing value doesn't match
- Throws:
NullPointerException- if key is nullIllegalStateException- if transaction belongs to another database instanceViewConstraintException- if remove is not permittedIOException
-
touch
Touch the given key as if callingload, but instead only acquiring any necessary locks. Method may returnUNOWNEDif the key isn't supported by this view, or if the transactionLockModedoesn't retain locks.If the entry must be locked, ownership of the key instance is transferred. The key must not be modified after calling this method.
- Parameters:
txn- optional transaction; pass null forREAD_COMMITTEDlocking behaviorkey- non-null key- Returns:
UNOWNED,ACQUIRED,OWNED_SHARED,OWNED_UPGRADABLE, orOWNED_EXCLUSIVE- Throws:
NullPointerException- if key is nullIllegalStateException- if transaction belongs to another database instanceLockFailureException
-
tryLockUpgradable
default LockResult tryLockUpgradable(Transaction txn, byte[] key, long nanosTimeout) throws DeadlockException, LockFailureException, ViewConstraintException Explicitly acquire an upgradable lock for the given key, denying exclusive and additional upgradable locks. Lock is retained until the end of the transaction or scope.Transactions acquire locks automatically, and so use of this method is not required. Ownership of the key instance is transferred, and so the key must not be modified after calling this method.
- Parameters:
key- non-null key to lock; instance is not cloned and so it must not be modified after calling this methodnanosTimeout- maximum time to wait for lock; negative timeout is infinite- Returns:
ILLEGAL,INTERRUPTED,TIMED_OUT_LOCK,ACQUIRED,OWNED_UPGRADABLE, orOWNED_EXCLUSIVE- Throws:
IllegalStateException- if transaction belongs to another database instanceDeadlockException- if deadlock was detected after waiting the full timeout, unless the timeout is zeroViewConstraintException- if key is not allowedLockFailureException
-
lockUpgradable
LockResult lockUpgradable(Transaction txn, byte[] key) throws LockFailureException, ViewConstraintException Explicitly acquire an upgradable lock for the given key, denying exclusive and additional upgradable locks. Lock is retained until the end of the transaction or scope.Transactions acquire locks automatically, and so use of this method is not required. Ownership of the key instance is transferred, and so the key must not be modified after calling this method.
- Parameters:
key- non-null key to lock; instance is not cloned and so it must not be modified after calling this method- Returns:
ACQUIRED,OWNED_UPGRADABLE, orOWNED_EXCLUSIVE- Throws:
IllegalStateException- if transaction belongs to another database instanceLockFailureException- if interrupted, timed out, or illegal upgradeDeadlockException- if deadlock was detected after waiting the full timeoutViewConstraintException- if key is not allowed
-
tryLockExclusive
default LockResult tryLockExclusive(Transaction txn, byte[] key, long nanosTimeout) throws DeadlockException, LockFailureException, ViewConstraintException Explicitly acquire an exclusive lock for the given key, denying any additional locks. Lock is retained until the end of the transaction or scope.Transactions acquire locks automatically, and so use of this method is not required. Ownership of the key instance is transferred, and so the key must not be modified after calling this method.
- Parameters:
key- non-null key to lock; instance is not cloned and so it must not be modified after calling this methodnanosTimeout- maximum time to wait for lock; negative timeout is infinite- Returns:
ILLEGAL,INTERRUPTED,TIMED_OUT_LOCK,ACQUIRED,UPGRADED, orOWNED_EXCLUSIVE- Throws:
IllegalStateException- if transaction belongs to another database instanceDeadlockException- if deadlock was detected after waiting the full timeout, unless the timeout is zeroViewConstraintException- if key is not allowedLockFailureException
-
lockExclusive
LockResult lockExclusive(Transaction txn, byte[] key) throws LockFailureException, ViewConstraintException Explicitly acquire an exclusive lock for the given key, denying any additional locks. Lock is retained until the end of the transaction or scope.Transactions acquire locks automatically, and so use of this method is not required. Ownership of the key instance is transferred, and so the key must not be modified after calling this method.
- Parameters:
key- non-null key to lock; instance is not cloned and so it must not be modified after calling this method- Returns:
ACQUIRED,UPGRADED, orOWNED_EXCLUSIVE- Throws:
IllegalStateException- if transaction belongs to another database instanceLockFailureException- if interrupted, timed out, or illegal upgradeDeadlockException- if deadlock was detected after waiting the full timeoutViewConstraintException- if key is not allowed
-
lockCheck
Checks the lock ownership for the given key.- Returns:
UNOWNED,OWNED_SHARED,OWNED_UPGRADABLE, orOWNED_EXCLUSIVE- Throws:
IllegalStateException- if transaction belongs to another database instanceViewConstraintException- if key is not allowed
-
viewGe
Returns a sub-view, backed by this one, whose keys are greater than or equal to the given key. Ownership of the key instance is transferred, and so it must not be modified after calling this method.The returned view will throw a
ViewConstraintExceptionon an attempt to insert a key outside its range.- Throws:
UnsupportedOperationException- if view is unorderedNullPointerException- if key is null
-
viewGt
Returns a sub-view, backed by this one, whose keys are greater than the given key. Ownership of the key instance is transferred, and so it must not be modified after calling this method.The returned view will throw a
ViewConstraintExceptionon an attempt to insert a key outside its range.- Throws:
UnsupportedOperationException- if view is unorderedNullPointerException- if key is null
-
viewLe
Returns a sub-view, backed by this one, whose keys are less than or equal to the given key. Ownership of the key instance is transferred, and so it must not be modified after calling this method.The returned view will throw a
ViewConstraintExceptionon an attempt to insert a key outside its range.- Throws:
UnsupportedOperationException- if view is unorderedNullPointerException- if key is null
-
viewLt
Returns a sub-view, backed by this one, whose keys are less than the given key. Ownership of the key instance is transferred, and so it must not be modified after calling this method.The returned view will throw a
ViewConstraintExceptionon an attempt to insert a key outside its range.- Throws:
UnsupportedOperationException- if view is unorderedNullPointerException- if key is null
-
viewPrefix
Returns a sub-view, backed by this one, whose keys start with the given prefix. Ownership of the prefix instance is transferred, and so it must not be modified after calling this method.The returned view will throw a
ViewConstraintExceptionon an attempt to insert a key outside its range.- Parameters:
trim- amount of prefix length to trim from all keys in the view- Throws:
UnsupportedOperationException- if view is unorderedNullPointerException- if prefix is nullIllegalArgumentException- if trim is longer than prefix
-
viewTransformed
Returns a sub-view, backed by this one, whose entries have been filtered out and transformed.The returned view will throw a
ViewConstraintExceptionon an attempt to insert an entry not supported by the transformer.- Throws:
NullPointerException- if transformer is null
-
viewFiltered
Returns a sub-view, backed by this one, whose entries have been filtered out.The returned view will throw a
ViewConstraintExceptionon an attempt to insert an entry not supported by the filter.- Throws:
NullPointerException- if filter is null
-
viewUnion
Returns a view which represents the set union of this view and a second one. A union eliminates duplicate keys, by relying on a combiner to decide how to deal with them. If the combiner chooses todiscardduplicate keys, then the returned view represents the symmetric set difference instead.Storing entries in the union is permitted, if the combiner supports separation. The separator must supply at least one non-null value, or else a
ViewConstraintExceptionwill be thrown.- Parameters:
combiner- combines common entries together; pass null to always choose thefirstsecond- required second view in the union- Throws:
NullPointerException- if second view is nullIllegalArgumentException- if the views don't define a consistent ordering, as specified by their comparators
-
viewIntersection
Returns a view which represents the set intersection of this view and a second one. An intersection eliminates duplicate keys, by relying on a combiner to decide how to deal with them.Storing entries in the intersection is permitted, if the combiner supports separation. The separator must supply two non-null values, or else a
ViewConstraintExceptionwill be thrown.- Parameters:
combiner- combines common entries together; pass null to always choose thefirstsecond- required second view in the intersection- Throws:
NullPointerException- if second view is nullIllegalArgumentException- if the views don't define a consistent ordering, as specified by their comparators
-
viewDifference
Returns a view which represents the set difference of this view and a second one. A difference eliminates duplicate keys, by relying on a combiner to decide how to deal with them.Storing entries in the difference is permitted, if the combiner supports
separation. The separator must supply a non-null first value, or else aViewConstraintExceptionwill be thrown.- Parameters:
combiner- combines common entries together; pass null to alwaysdiscardthemsecond- required second view in the difference- Throws:
NullPointerException- if second view is nullIllegalArgumentException- if the views don't define a consistent ordering, as specified by their comparators
-
viewKeys
Returns a view, backed by this one, which only provides the keys. Values are always represented asNOT_LOADED, and attempting to store a value other than null causes aViewConstraintExceptionto be thrown. -
viewReverse
Returns a view, backed by this one, whose natural order is reversed. -
viewUnmodifiable
Returns a view, backed by this one, whose entries cannot be modified. Any attempt to do so causes anUnmodifiableViewExceptionto be thrown. -
isUnmodifiable
boolean isUnmodifiable()Returns true if any attempt to modify this view causes anUnmodifiableViewExceptionto be thrown. -
isModifyAtomic
default boolean isModifyAtomic()Returns true if the value-modifying methods of this view are atomic, even when not using transactions.
-