Package kvd.client
Class KvdTransaction
- java.lang.Object
-
- kvd.client.KvdTransaction
-
- All Implemented Interfaces:
AutoCloseable
,KvdOperations
public class KvdTransaction extends Object implements KvdOperations, AutoCloseable
Transaction support, Unit of Work pattern
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Rollback and close transaction.void
commit()
Commit and close the transaction.Future<Boolean>
commitAsync()
Commit and close the transaction.Future<Boolean>
containsAsync(byte[] key)
The returnedFuture
evaluates to true if the key exists on the server, false otherwiseFuture<InputStream>
getAsync(byte[] key)
Returns the value to which the specified key is mappedboolean
lock(String key)
Future<Boolean>
lockAsync(byte[] key)
Obtain write lock on the key in the same way a put or remove operation would do.Future<Boolean>
lockAsync(String key)
Obtain write lock on the key in the same way a put or remove operation would do.Future<OutputStream>
putAsync(byte[] key)
Put a new value or replace an existing.Future<Boolean>
removeAsync(byte[] key)
Removes the mapping for the specified key from the server.void
rollback()
Rollback and close the transaction.Future<Boolean>
rollbackAsync()
Rollback and close the transaction.String
toString()
-
-
-
Method Detail
-
close
public void close()
Rollback and close transaction.- Specified by:
close
in interfaceAutoCloseable
-
commitAsync
public Future<Boolean> 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
public Future<Boolean> 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
public Future<OutputStream> putAsync(byte[] key)
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
public Future<InputStream> getAsync(byte[] key)
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
public Future<Boolean> containsAsync(byte[] key)
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
public Future<Boolean> removeAsync(byte[] key)
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
public Future<Boolean> lockAsync(byte[] key)
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
public Future<Boolean> lockAsync(String key)
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
public boolean lock(String key)
- Parameters:
key
- the key to write lock- Returns:
- see
lockAsync(String)
-
-