Class LMDBKVDatabase<T>

java.lang.Object
io.permazen.kv.lmdb.LMDBKVDatabase<T>
Type Parameters:
T - buffer type
All Implemented Interfaces:
KVDatabase
Direct Known Subclasses:
ByteArrayLMDBKVDatabase

@ThreadSafe public abstract class LMDBKVDatabase<T> extends Object implements KVDatabase
KVDatabase view of an LMDB database.

A database directory is the only required configuration property. Instances may be stopped and (re)started multiple times.

  • Field Details

  • Constructor Details

    • LMDBKVDatabase

      protected LMDBKVDatabase(org.lmdbjava.Env.Builder<T> defaultBuilder)
      Constructor.
      Parameters:
      defaultBuilder - the default builder
      Throws:
      IllegalArgumentException - if defaultBuilder is null
  • Method Details

    • getDirectory

      public File getDirectory()
      Get the filesystem directory containing the database.
      Returns:
      database directory
    • setDirectory

      public void setDirectory(File directory)
      Configure the filesystem directory containing the database. Required property.
      Parameters:
      directory - database directory
      Throws:
      IllegalStateException - if this instance is already start()ed
    • getDatabaseName

      public String getDatabaseName()
      Get the LMDB database name to use.
      Returns:
      configured database name
    • setDatabaseName

      public void setDatabaseName(String databaseName)
      Set the LMDB database name to use.

      Default value is DEFAULT_DATABASE_NAME.

      Parameters:
      databaseName - database name
      Throws:
      IllegalStateException - if this instance is already start()ed
      IllegalArgumentException - if databaseName is null
    • getEnvFlags

      public EnumSet<org.lmdbjava.EnvFlags> getEnvFlags()
      Get the EnvFlags that will be used when opening the associated Env.
      Returns:
      environment flags
    • setEnvBuilder

      public void setEnvBuilder(EnumSet<org.lmdbjava.EnvFlags> flags)
      Set the flags to be used when opening the associated Env.

      Default is empty set.

      Parameters:
      flags - environment flags
      Throws:
      IllegalStateException - if this instance is already start()ed
      IllegalArgumentException - if flags is null
    • getEnvBuilder

      public org.lmdbjava.Env.Builder<T> getEnvBuilder()
      Get the Env.Builder that will be used when opening the associated Env.
      Returns:
      environment builder
    • setEnvBuilder

      public void setEnvBuilder(org.lmdbjava.Env.Builder<T> builder)
      Set a custom builder to be used when opening the associated Env.
      Parameters:
      builder - environment builder
      Throws:
      IllegalStateException - if this instance is already start()ed
      IllegalArgumentException - if builder is null
    • getEnv

      public org.lmdbjava.Env<T> getEnv()
      Get the Env associated with this instance.
      Returns:
      the associated Env
      Throws:
      IllegalStateException - if this instance is not start()ed
    • start

      @PostConstruct 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

      @PreDestroy 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 LMDBKVTransaction<T> createTransaction()
      Description copied from interface: KVDatabase
      Create a new transaction.
      Specified by:
      createTransaction in interface KVDatabase
      Returns:
      newly created transaction
    • createTransaction

      public LMDBKVTransaction<T> 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
    • doCreateTransaction

      protected abstract LMDBKVTransaction<T> doCreateTransaction(org.lmdbjava.Env<T> env, org.lmdbjava.Dbi<T> db, Map<String,?> options)
    • finalize

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

      public String toString()
      Overrides:
      toString in class Object