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 Details

    • close

      public void close()
      Rollback and close transaction.
      Specified by:
      close in interface AutoCloseable
    • 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 interface KvdOperations
      Parameters:
      key - key with which the specified value is to be associated
      Returns:
      Future that evaluates either to an OutputStream to be used to stream the value in. or fails (e.g. on optimistic lock or deadlock). Close the OutputStream 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 interface KvdOperations
      Parameters:
      key - the key whose associated value is to be returned
      Returns:
      Future that evaluates either to an InputStream for keys that exist or null for keys that don't exist on the server.
    • containsAsync

      public Future<Boolean> containsAsync(byte[] key)
      Description copied from interface: KvdOperations
      The returned Future evaluates to true if the key exists on the server, false otherwise
      Specified by:
      containsAsync in interface KvdOperations
      Parameters:
      key - The key whose presence is to be tested
      Returns:
      Future evaluates to true 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 interface KvdOperations
      Parameters:
      key - key whose mapping is to be removed
      Returns:
      Future which evaluates to true 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)
    • toString

      public String toString()
      Overrides:
      toString in class Object