Package kvd.client
Class KvdTransaction
java.lang.Object
kvd.client.KvdTransaction
- All Implemented Interfaces:
AutoCloseable
,KvdOperations
Transaction support, Unit of Work pattern
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Rollback and close transaction.void
commit()
Commit and close the transaction.Commit and close the transaction.containsAsync
(byte[] key) The returnedFuture
evaluates to true if the key exists on the server, false otherwisegetAsync
(byte[] key) Returns the value to which the specified key is mappedboolean
lockAsync
(byte[] key) Obtain write lock on the key in the same way a put or remove operation would do.Obtain write lock on the key in the same way a put or remove operation would do.putAsync
(byte[] key) Put a new value or replace an existing.removeAsync
(byte[] key) Removes the mapping for the specified key from the server.void
rollback()
Rollback and close the transaction.Rollback and close the transaction.toString()
-
Method Details
-
close
public void close()Rollback and close transaction.- Specified by:
close
in interfaceAutoCloseable
-
commitAsync
Commit and close the transaction. No further operations are allowed on the transaction after commit and the transaction object can be discarded.- Returns:
Future
future that resolves to true or completes exceptionally.
-
commit
public void commit()Commit and close the transaction. No further operations are allowed on the transaction after commit and the transaction object can be discarded. -
rollbackAsync
Rollback and close the transaction. No further operations are allowed on the transaction after commit and the transaction object can be discarded.- Returns:
Future
that resolves to true or completes exceptionally.
-
rollback
public void rollback()Rollback and close the transaction. No further operations are allowed on the transaction after commit and the transaction object can be discarded. -
putAsync
Description copied from interface:KvdOperations
Put a new value or replace an existing.- Specified by:
putAsync
in interfaceKvdOperations
- Parameters:
key
- key with which the specified value is to be associated- Returns:
Future
that evaluates either to anOutputStream
to be used to stream the value in. or fails (e.g. on optimistic lock or deadlock). Close theOutputStream
to signal that the value is complete.
-
getAsync
Description copied from interface:KvdOperations
Returns the value to which the specified key is mapped- Specified by:
getAsync
in interfaceKvdOperations
- Parameters:
key
- the key whose associated value is to be returned- Returns:
Future
that evaluates either to anInputStream
for keys that exist ornull
for keys that don't exist on the server.
-
containsAsync
Description copied from interface:KvdOperations
The returnedFuture
evaluates to true if the key exists on the server, false otherwise- Specified by:
containsAsync
in interfaceKvdOperations
- Parameters:
key
- The key whose presence is to be tested- Returns:
Future
evaluates totrue
if the key exists on the server,false
otherwise
-
removeAsync
Description copied from interface:KvdOperations
Removes the mapping for the specified key from the server.- Specified by:
removeAsync
in interfaceKvdOperations
- Parameters:
key
- key whose mapping is to be removed- Returns:
Future
which evaluates totrue
if the key/value was removed from the server,false
otherwise.
-
lockAsync
Obtain write lock on the key in the same way a put or remove operation would do. It does not matter whether the key exists in the database or not.- Parameters:
key
- the key to write lock- Returns:
Future
that evaluates to true if concurrency mode is different from NONE or false for concurrency mode NONE or completes exceptionally if the key can't be write locked because either another transaction has a write lock on the key already in optimistic concurrency mode or a deadlock is detected in pessimistic concurrency mode
-
lockAsync
Obtain write lock on the key in the same way a put or remove operation would do. It does not matter whether the key exists in the database or not.- Parameters:
key
- the key to write lock- Returns:
Future
that evaluates to true if concurrency mode is different from NONE or false for concurrency mode NONE or completes exceptionally if the key can't be write locked because either another transaction has a write lock on the key already in optimistic concurrency mode or a deadlock is detected in pessimistic concurrency mode
-
lock
- Parameters:
key
- the key to write lock- Returns:
- see
lockAsync(String)
-
toString
-