Class PrefixKVDatabase

java.lang.Object
io.permazen.kv.util.PrefixKVDatabase
All Implemented Interfaces:
KVDatabase

public class PrefixKVDatabase extends Object implements KVDatabase
Prefix KVDatabase implementation.

Instances use a fixed byte[] key prefix for all key access, thereby providing a nested KVDatabase view of the corresponding sub-range of keys within the containing KVDatabase. This allows, for example, multiple KVDatabases to exist within a single containing KVDatabase under different key prefixes.

Instances ignore invocations to start() and stop(); instead, invoke these methods on the underlying KVDatabase.

  • Constructor Details

    • PrefixKVDatabase

      public PrefixKVDatabase(KVDatabase db, byte[] keyPrefix)
      Constructor.
      Parameters:
      db - the containing KVDatabase
      keyPrefix - prefix for all keys
      Throws:
      IllegalArgumentException - if db or keyPrefix is null
  • Method Details

    • getContainingKVDatabase

      public KVDatabase getContainingKVDatabase()
      Get the containing KVDatabase associated with this instance.
      Returns:
      the containing KVDatabase
    • getKeyPrefix

      public final byte[] getKeyPrefix()
      Get the key prefix associated with this instance.
      Returns:
      (a copy of) this instance's key prefix
    • start

      public void start()
      Description copied from interface: KVDatabase
      Start this instance. This method must be called prior to creating any transactions.

      This method is idempotent: if this instance is already started, nothing happens.

      Whether an instance that has been started and stopped can be restarted is implementation-dependent.

      Specified by:
      start in interface KVDatabase
    • stop

      public void stop()
      Description copied from interface: KVDatabase
      Stop this instance.

      This method is idempotent: if this instance has not been started, or is already stopped, nothing happens.

      Specified by:
      stop in interface KVDatabase
    • createTransaction

      public PrefixKVTransaction createTransaction(Map<String,?> options)
      Description copied from interface: KVDatabase
      Create a new transaction with the specified options.
      Specified by:
      createTransaction in interface KVDatabase
      Parameters:
      options - optional transaction options; may be null
      Returns:
      newly created transaction
    • createTransaction

      public PrefixKVTransaction createTransaction()
      Description copied from interface: KVDatabase
      Create a new transaction.
      Specified by:
      createTransaction in interface KVDatabase
      Returns:
      newly created transaction