Class XodusKVStore

java.lang.Object
io.permazen.kv.AbstractKVStore
io.permazen.kv.xodus.XodusKVStore
All Implemented Interfaces:
CloseableKVStore, KVStore, Closeable, AutoCloseable

public class XodusKVStore extends AbstractKVStore implements CloseableKVStore
Straightforward KVStore view of a Xodus Store viewed within an open Transaction.

Instances must be close()'d when no longer needed to avoid leaking resources.

  • Constructor Details

    • XodusKVStore

      public XodusKVStore(jetbrains.exodus.env.Environment env, String storeName, TransactionType txType)
      Convenience constructor.

      Equivalent to: SnapshotXodusKVStore(env, storeName, true, txType).

      Parameters:
      env - Xodus environment
      storeName - Xodus store name
      txType - transaction type
      Throws:
      IllegalArgumentException - if env, storeName, or txType is null
    • XodusKVStore

      public XodusKVStore(jetbrains.exodus.env.Environment env, String storeName, boolean keyPrefixing, TransactionType txType)
      Constructor.

      The specified Store will be created if necessary.

      Parameters:
      env - Xodus environment
      storeName - Xodus store name
      keyPrefixing - if creating a new store, true to create the store with key prefixing (StoreConfig.WITHOUT_DUPLICATES_WITH_PREFIXING), or false to create the store without key prefixing (StoreConfig.WITHOUT_DUPLICATES)
      txType - transaction type
      Throws:
      IllegalArgumentException - if env, storeName, or txType is null
  • Method Details

    • getTransactionType

      public TransactionType getTransactionType()
      Get the TransactionType associated with this instance.
      Returns:
      associated transaction type
    • getTransaction

      public jetbrains.exodus.env.Transaction getTransaction()
      Get the Transaction associated with this instance.
      Returns:
      associated transaction
    • getStore

      public jetbrains.exodus.env.Store getStore()
      Get the Store associated with this instance.
      Returns:
      associated store
    • isClosed

      public boolean isClosed()
      Determine if this instance is closed.
      Returns:
      true if closed, false if still open
    • readOnlySnapshot

      public XodusKVStore readOnlySnapshot()
      Return a read-only snapshot containing the same data as this instance.

      Though based on the same underlying data, the returned instance and this instance retain no references to each other.

      Returns:
      read-only snapshot
      Throws:
      IllegalStateException - if this instance is closed
    • get

      public byte[] get(byte[] key)
      Description copied from interface: KVStore
      Get the value associated with the given key, if any.

      Modifications to the returned byte[] array do not affect this instance.

      Specified by:
      get in interface KVStore
      Overrides:
      get in class AbstractKVStore
      Parameters:
      key - key
      Returns:
      value associated with key, or null if not found
    • getAtLeast

      public KVPair getAtLeast(byte[] minKey, byte[] maxKey)
      Description copied from interface: KVStore
      Get 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 maxKey is null, there is no upper bound; if maxKey <= minKey, null is always returned.

      If keys starting with 0xff are not supported by this instance, and minKey starts with 0xff, then this method returns null.

      Modifications to the returned byte[] arrays do not affect this instance.

      Specified by:
      getAtLeast in interface KVStore
      Overrides:
      getAtLeast in class AbstractKVStore
      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 >= minKey and key < maxKey, or null if none exists
    • getAtMost

      public KVPair getAtMost(byte[] maxKey, byte[] minKey)
      Description copied from interface: KVStore
      Get 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 minKey is null, there is no lower bound (equivalent to a lower bound of the empty byte array); if minKey >= maxKey, null is always returned.

      If keys starting with 0xff are not supported by this instance, and maxKey starts with 0xff, then this method behaves as if maxKey were null.

      Modifications to the returned byte[] arrays do not affect this instance.

      Specified by:
      getAtMost in interface KVStore
      Overrides:
      getAtMost in class AbstractKVStore
      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 < maxKey and key >= minKey, or null if none exists
    • getRange

      public CloseableIterator<KVPair> getRange(byte[] minKey, byte[] maxKey, boolean reverse)
      Description copied from interface: KVStore
      Iterate the key/value pairs in the specified range. The returned CloseableIterator's remove() method must be supported and should have the same effect as invoking remove() on the corresponding key.

      If keys starting with 0xff are not supported by this instance, and minKey starts with 0xff, then this method returns an empty iteration.

      If keys starting with 0xff are not supported by this instance, and maxKey starts with 0xff, then this method behaves as if maxKey were null.

      The returned CloseableIterator is weakly consistent (see java.util.concurrent). In short, the returned CloseableIterator must not throw ConcurrentModificationException; however, whether or not a "live" CloseableIterator reflects any modifications made after its creation is implementation dependent. Implementations that do make post-creation updates visible in the CloseableIterator, even if the update occurs after some delay, must preserve the order in which the modifications actually occurred.

      The returned CloseableIterator itself 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.

      Modifications to the returned KVPair key and value byte[] arrays do not affect this instance.

      Specified by:
      getRange in interface KVStore
      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) to maxKey (exclusive)
    • put

      public void put(byte[] key, byte[] value)
      Description copied from interface: KVStore
      Set the value associated with the given key.
      Specified by:
      put in interface KVStore
      Overrides:
      put in class AbstractKVStore
      Parameters:
      key - key
      value - value
    • remove

      public void remove(byte[] key)
      Description copied from interface: KVStore
      Remove the key/value pair with the given key, if it exists.
      Specified by:
      remove in interface KVStore
      Overrides:
      remove in class AbstractKVStore
      Parameters:
      key - key
    • removeRange

      public void removeRange(byte[] minKey, byte[] maxKey)
      Description copied from interface: KVStore
      Remove all key/value pairs whose keys are in a given range.

      The minKey must be less than or equal to maxKey; if they equal (and not null) then nothing happens; if they are both null then all entries are deleted.

      If keys starting with 0xff are not supported by this instance, then:

      • If minKey starts with 0xff, then no change occurs
      • If maxKey starts with 0xff, then this method behaves as if maxKey were null
      Specified by:
      removeRange in interface KVStore
      Overrides:
      removeRange in class AbstractKVStore
      Parameters:
      minKey - minimum key (inclusive), or null for no minimum
      maxKey - maximum key (exclusive), or null for no maximum
    • finalize

      protected void finalize() throws Throwable
      Finalize this instance. Invokes close() to close any unclosed iterators.
      Overrides:
      finalize in class Object
      Throws:
      Throwable
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • close

      public void close()
      Close this instance, discarding any changes.

      This closes the underlying Transaction and any unclosed iterators returned from getRange(). This method just invokes close(false).

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface CloseableKVStore
    • close

      public boolean close(boolean commit)
      Close this instance, optionally comitting any changes.

      This closes or commits the underlying Transaction, and closes any unclosed iterators returned from getRange(). This instance will end up being closed even if commit fails.

      Parameters:
      commit - true to commit changes (if any)
      Returns:
      true if already closed or successfully closed/commited, false if commit is true but the commit fails