Class BerkeleyKVDatabase

java.lang.Object
io.permazen.kv.bdb.BerkeleyKVDatabase
All Implemented Interfaces:
KVDatabase

public class BerkeleyKVDatabase extends Object implements KVDatabase
Oracle Berkeley DB Java Edition KVDatabase implementation.

A database directory is the only required configuration property, but the Environment, Database, and Transactions may all be configured. Instances may be stopped and (re)started multiple times.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Default Berkeley DB database name ("Permazen").
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    Create a new transaction.
    Create a new transaction with the specified options.
    com.sleepycat.je.Database
    Get the underlying Database associated with this instance.
    com.sleepycat.je.DatabaseConfig
    Get the DatabaseConfig to be used by this instance.
    Get the configured Database name.
    Get the filesystem directory containing the database.
    com.sleepycat.je.Environment
    Get the underlying Environment associated with this instance.
    com.sleepycat.je.EnvironmentConfig
    Get the EnvironmentConfig to be used by this instance.
    com.sleepycat.je.TransactionConfig
    Get the default TransactionConfig to be used by this instance.
    void
    setDatabaseConfig(com.sleepycat.je.DatabaseConfig config)
    Apply selected database configuration parameters from the given instance to the DatabaseConfig this instance will use when opening the Database at startup.
    void
    setDatabaseName(String databaseName)
    Configure the Database name.
    void
    setDirectory(File directory)
    Configure the filesystem directory containing the database.
    void
    setEnvironmentConfig(com.sleepycat.je.EnvironmentConfig config)
    Set a custom EnvironmentConfig to be used by this instance at startup.
    void
    setNextTransactionConfig(com.sleepycat.je.TransactionConfig config)
    Configure a custom TransactionConfig to be used for the next transaction in the current thread.
    void
    setTransactionConfig(com.sleepycat.je.TransactionConfig config)
    Configure a custom default TransactionConfig to be used by this instance for transactions.
    void
    Start this instance.
    void
    Stop this instance.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • BerkeleyKVDatabase

      public BerkeleyKVDatabase()
      Constructor.
  • 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
    • getDatabaseName

      public String getDatabaseName()
      Get the configured Database name.
      Returns:
      database name
    • setDatabaseName

      public void setDatabaseName(String databaseName)
      Configure the Database name. Defaults to DEFAULT_DATABASE_NAME.
      Parameters:
      databaseName - database name
    • getEnvironmentConfig

      public com.sleepycat.je.EnvironmentConfig getEnvironmentConfig()
      Get the EnvironmentConfig to be used by this instance.

      This method returns a copy; use setEnvironmentConfig() to change.

      Returns:
      environment config
    • setEnvironmentConfig

      public void setEnvironmentConfig(com.sleepycat.je.EnvironmentConfig config)
      Set a custom EnvironmentConfig to be used by this instance at startup.

      The default EnvironmentConfig is configured for serializable transactional operation and with allowCreate set to true.

      The given config must at least be configured for transactional operation.

      Parameters:
      config - environment config
      Throws:
      IllegalArgumentException - if config is not configured to be transactional
      IllegalArgumentException - if config is null
    • getTransactionConfig

      public com.sleepycat.je.TransactionConfig getTransactionConfig()
      Get the default TransactionConfig to be used by this instance.

      This method returns a copy; use setTransactionConfig() to change.

      Returns:
      transaction config
    • setTransactionConfig

      public void setTransactionConfig(com.sleepycat.je.TransactionConfig config)
      Configure a custom default TransactionConfig to be used by this instance for transactions.

      Note: this configures the default; this default config can be overridden for the next transaction in the current thread only via setNextTransactionConfig().

      The default setting for this property is TransactionConfig.DEFAULT.

      Parameters:
      config - transaction config
      Throws:
      IllegalArgumentException - if config is null
      See Also:
    • setNextTransactionConfig

      public void setNextTransactionConfig(com.sleepycat.je.TransactionConfig config)
      Configure a custom TransactionConfig to be used for the next transaction in the current thread. The next, and only the next, invocation of createTransaction(java.util.Map<java.lang.String, ?>) in the current thread will use the given configuration. After that, subsequent transactions will revert back to the default (even if the invocation of createTransaction(java.util.Map<java.lang.String, ?>) failed).
      Parameters:
      config - transaction config
      Throws:
      IllegalArgumentException - if config is null
      See Also:
    • getDatabaseConfig

      public com.sleepycat.je.DatabaseConfig getDatabaseConfig()
      Get the DatabaseConfig to be used by this instance.

      This method returns a copy; use setDatabaseConfig() to change.

      Returns:
      database config
    • setDatabaseConfig

      public void setDatabaseConfig(com.sleepycat.je.DatabaseConfig config)
      Apply selected database configuration parameters from the given instance to the DatabaseConfig this instance will use when opening the Database at startup.

      The default DatabaseConfig is configured for transactional operation and with allowCreate set to true. Only certain allowed configuration properties are copied. The copied properties are:

      • allowCreate
      • cacheMode
      • deferredWrite
      • exclusiveCreate
      • nodeMaxEntries
      • readOnly
      • replicated
      • temporary
      Parameters:
      config - database config
    • getEnvironment

      public com.sleepycat.je.Environment getEnvironment()
      Get the underlying Environment associated with this instance.
      Returns:
      the associated Environment
      Throws:
      IllegalStateException - if this instance is not started
    • getDatabase

      public com.sleepycat.je.Database getDatabase()
      Get the underlying Database associated with this instance.
      Returns:
      the associated Database
      Throws:
      IllegalStateException - if this instance is not started
    • createTransaction

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