Class BerkeleyKVTransaction
- All Implemented Interfaces:
KVStore,KVTransaction,Closeable,AutoCloseable
KVTransaction implementation.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionfinal classIteratorimplementation used byBerkeleyKVTransaction.getRange(). -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidcommit()Commit this transaction.protected voidfinalize()Get the value associated with the given key, if any.getAtLeast(ByteData minKey, ByteData maxKey) Get the key/value pair having the smallest key greater than or equal to the given minimum, if any.Get the key/value pair having the largest key strictly less than the given maximum, if any.Get theKVDatabasewith which this instance is associated.Iterate the key/value pairs in the specified range.com.sleepycat.je.TransactionGet the underlyingTransactionassociated with this instance.booleanDetermine whether this transaction is read-only.voidSet the value associated with the given key.Create a read-only snapshot of the database content represented by this transaction.voidRemove the key/value pair with the given key, if it exists.voidrollback()Cancel this transaction, if not already canceled.voidsetReadOnly(boolean readOnly) Enable or disable read-only mode.voidsetTimeout(long timeout) Change the timeout for this transaction from its default value (optional operation).Watch a key to monitor for changes in its value.wrapException(com.sleepycat.je.DatabaseException e) Wrap the givenDatabaseExceptionin the appropriateKVTransactionException.Methods inherited from class io.permazen.kv.AbstractKVStore
adjustCounter, decodeCounter, encodeCounter, removeRangeMethods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.permazen.kv.KVStore
adjustCounter, apply, decodeCounter, encodeCounter, getRange, getRange, removeRange, removeRangeMethods inherited from interface io.permazen.kv.KVTransaction
withWeakConsistency
-
Method Details
-
getKVDatabase
Description copied from interface:KVTransactionGet theKVDatabasewith which this instance is associated.- Specified by:
getKVDatabasein interfaceKVTransaction- Returns:
- associated database
-
getTransaction
public com.sleepycat.je.Transaction getTransaction()Get the underlyingTransactionassociated with this instance.- Returns:
- the associated transaction
-
setTimeout
public void setTimeout(long timeout) Description copied from interface:KVTransactionChange the timeout for this transaction from its default value (optional operation).- Specified by:
setTimeoutin interfaceKVTransaction- Parameters:
timeout- transaction timeout in milliseconds, or zero for unlimited
-
watchKey
Watch a key to monitor for changes in its value.Oracle Berkeley DB Java Edition does not support key watches; the implementation in
BerkeleyKVDatabasealways throwsUnsupportedOperationException.- Specified by:
watchKeyin interfaceKVTransaction- Parameters:
key- the key to watch- Returns:
- a
Futurethat returnskeywhen the value associated withkeyis modified - Throws:
UnsupportedOperationException- always- See Also:
-
get
Description copied from interface:KVStoreGet the value associated with the given key, if any.- Specified by:
getin interfaceKVStore- Overrides:
getin classAbstractKVStore- Parameters:
key- key- Returns:
- value associated with key, or null if not found
-
getAtLeast
Description copied from interface:KVStoreGet the key/value pair having the smallest key greater than or equal to the given minimum, if any.An optional (exclusive) maximum key may also be specified; if
maxKeyis null, there is no upper bound; ifmaxKey <= minKey, null is always returned.If keys starting with
0xffare not supported by this instance, andminKeystarts with0xff, then this method returns null.- Specified by:
getAtLeastin interfaceKVStore- Overrides:
getAtLeastin classAbstractKVStore- Parameters:
minKey- minimum key (inclusive), or null for no minimum (get the smallest key)maxKey- maximum key (exclusive), or null for no maximum (no upper bound)- Returns:
- smallest key/value pair with
key >= minKeyandkey < maxKey, or null if none exists
-
getAtMost
Description copied from interface:KVStoreGet the key/value pair having the largest key strictly less than the given maximum, if any.An optional (inclusive) minimum key may also be specified; if
minKeyis null, there is no lower bound (equivalent to a lower bound of the empty byte array); ifminKey >= maxKey, null is always returned.If keys starting with
0xffare not supported by this instance, andmaxKeystarts with0xff, then this method behaves as ifmaxKeywere null.- Specified by:
getAtMostin interfaceKVStore- Overrides:
getAtMostin classAbstractKVStore- Parameters:
maxKey- maximum key (exclusive), or null for no maximum (get the largest key)minKey- minimum key (inclusive), or null for no minimum (no lower bound)- Returns:
- largest key/value pair with
key < maxKeyandkey >= minKey, or null if none exists
-
getRange
public BerkeleyKVTransaction.CursorIterator getRange(ByteData minKey, ByteData maxKey, boolean reverse) Description copied from interface:KVStoreIterate the key/value pairs in the specified range. The returnedCloseableIterator'sremove()method must be supported and should have the same effect as invokingremove()on the corresponding key.If keys starting with
0xffare not supported by this instance, andminKeystarts with0xff, then this method returns an empty iteration.If keys starting with
0xffare not supported by this instance, andmaxKeystarts with0xff, then this method behaves as ifmaxKeywere null.The returned
CloseableIteratoris weakly consistent (seejava.util.concurrent). In short, the returnedCloseableIteratormust not throwConcurrentModificationException; however, whether or not a "live"CloseableIteratorreflects any modifications made after its creation is implementation dependent. Implementations that do make post-creation updates visible in theCloseableIterator, even if the update occurs after some delay, must preserve the order in which the modifications actually occurred.The returned
CloseableIteratoritself is not guaranteed to be thread safe; is should only be used in the thread that created it.Invokers of this method are encouraged to
close()the returned iterators, though this is not required for correct behavior.- Specified by:
getRangein interfaceKVStore- Parameters:
minKey- minimum key (inclusive), or null for no minimum (start at the smallest key)maxKey- maximum key (exclusive), or null for no maximum (end at the largest key)reverse- true to return key/value pairs in reverse order (i.e., keys descending)- Returns:
- iteration of key/value pairs in the range
minKey(inclusive) tomaxKey(exclusive)
-
put
Description copied from interface:KVStoreSet the value associated with the given key.- Specified by:
putin interfaceKVStore- Overrides:
putin classAbstractKVStore- Parameters:
key- keyvalue- value
-
remove
Description copied from interface:KVStoreRemove the key/value pair with the given key, if it exists.- Specified by:
removein interfaceKVStore- Overrides:
removein classAbstractKVStore- Parameters:
key- key
-
isReadOnly
public boolean isReadOnly()Description copied from interface:KVTransactionDetermine whether this transaction is read-only.Default is false.
- Specified by:
isReadOnlyin interfaceKVTransaction- Returns:
- true if this instance is read-only
-
setReadOnly
public void setReadOnly(boolean readOnly) Description copied from interface:KVTransactionEnable or disable read-only mode.Read-only transactions allow mutations, but all changes are discarded on
KVTransaction.commit().Some implementations may impose one or more of the following restrictions on this method:
setReadOnly()may only be invoked prior to accessing data;setReadOnly()may only be invoked prior to mutating data; and/or- Once set to read-only, a transaction may not be set back to read-write
IllegalStateExceptionis thrown.Note: for some implementations, the data read from a transaction that is never
KVTransaction.commit()'ed is not guaranteed to be up to date, even if that transaction is read-only.Default is false.
- Specified by:
setReadOnlyin interfaceKVTransaction- Parameters:
readOnly- read-only setting
-
commit
public void commit()Description copied from interface:KVTransactionCommit this transaction.Note that if this method throws a
RetryKVTransactionException, the transaction was either successfully committed or rolled back. In either case, this instance is no longer usable.Note also for some implementations, even read-only transactions must be
KVTransaction.commit()'ed in order for the data accessed during the transaction to be guaranteed to be up to date.- Specified by:
commitin interfaceKVTransaction
-
rollback
public void rollback()Description copied from interface:KVTransactionCancel this transaction, if not already canceled.After this method returns, this instance is no longer usable.
Note: for some implementations, rolling back a transaction invalidates guarantees about the the data read during the transaction being up to date, even if the transaction was
setReadOnly().This method may be invoked at any time, even after a previous invocation of
KVTransaction.commit()orKVTransaction.rollback(), in which case the invocation will be ignored. In particular, this method must not throwStaleKVTransactionException.- Specified by:
rollbackin interfaceKVTransaction
-
readOnlySnapshot
Description copied from interface:KVTransactionCreate a read-only snapshot of the database content represented by this transaction.The returned
CloseableKVStoreshould be treated as read-only. It may not actually be read-only, but if it's not, then any changes should have no effect on this instance. The returnedCloseableKVStoremust be completely independent from this transaction (subsequent changes to either one do not affect the other).Note: as with any other information extracted from a
KVTransaction, the returned content should not be considered valid until this transaction has been successfully committed.The returned
CloseableKVStoreshould be promplyclose()'d when no longer needed to release any underlying resources. In particular, the caller must ensure that theCloseableKVStoreisclose()'d even if this transaction's commit fails. This may require adding a transaction synchronization callback, etc.This is an optional method; only some underlying key/value store technologies can efficiently support it. Implementations should throw
UnsupportedOperationExceptionif not supported.- Specified by:
readOnlySnapshotin interfaceKVTransaction- Returns:
- independent, read-only copy of this transaction's entire database content
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
finalize
-
wrapException
Wrap the givenDatabaseExceptionin the appropriateKVTransactionException.- Parameters:
e- Berkeley database exception- Returns:
- appropriate
KVTransactionExceptionwith chained exceptione - Throws:
NullPointerException- ifeis null
-