Package io.permazen.kv.lmdb
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
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 Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
LMDBKVDatabase
(org.lmdbjava.Env.Builder<T> defaultBuilder) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionCreate a new transaction.createTransaction
(Map<String, ?> options) Create a new transaction with the specified options.protected abstract LMDBKVTransaction<T>
doCreateTransaction
(org.lmdbjava.Env<T> env, org.lmdbjava.Dbi<T> db, Map<String, ?> options) protected void
finalize()
Finalize this instance.Get the LMDB database name to use.Get the filesystem directory containing the database.org.lmdbjava.Env<T>
getEnv()
Get theEnv
associated with this instance.org.lmdbjava.Env.Builder<T>
Get theEnv.Builder
that will be used when opening the associatedEnv
.EnumSet<org.lmdbjava.EnvFlags>
Get theEnvFlags
that will be used when opening the associatedEnv
.void
setDatabaseName
(String databaseName) Set the LMDB database name to use.void
setDirectory
(File directory) Configure the filesystem directory containing the database.void
setEnvBuilder
(EnumSet<org.lmdbjava.EnvFlags> flags) Set the flags to be used when opening the associatedEnv
.void
setEnvBuilder
(org.lmdbjava.Env.Builder<T> builder) Set a custom builder to be used when opening the associatedEnv
.void
start()
Start this instance.void
stop()
Stop this instance.toString()
-
Field Details
-
DEFAULT_DATABASE_NAME
Default LMDB database name ("permazen"). -
log
-
-
Constructor Details
-
LMDBKVDatabase
Constructor.- Parameters:
defaultBuilder
- the default builder- Throws:
IllegalArgumentException
- ifdefaultBuilder
is null
-
-
Method Details
-
getDirectory
Get the filesystem directory containing the database.- Returns:
- database directory
-
setDirectory
Configure the filesystem directory containing the database. Required property.- Parameters:
directory
- database directory- Throws:
IllegalStateException
- if this instance is alreadystart()
ed
-
getDatabaseName
Get the LMDB database name to use.- Returns:
- configured database name
-
setDatabaseName
Set the LMDB database name to use.Default value is
DEFAULT_DATABASE_NAME
.- Parameters:
databaseName
- database name- Throws:
IllegalStateException
- if this instance is alreadystart()
edIllegalArgumentException
- ifdatabaseName
is null
-
getEnvFlags
Get theEnvFlags
that will be used when opening the associatedEnv
.- Returns:
- environment flags
-
setEnvBuilder
Set the flags to be used when opening the associatedEnv
.Default is empty set.
- Parameters:
flags
- environment flags- Throws:
IllegalStateException
- if this instance is alreadystart()
edIllegalArgumentException
- ifflags
is null
-
getEnvBuilder
Get theEnv.Builder
that will be used when opening the associatedEnv
.- Returns:
- environment builder
-
setEnvBuilder
Set a custom builder to be used when opening the associatedEnv
.- Parameters:
builder
- environment builder- Throws:
IllegalStateException
- if this instance is alreadystart()
edIllegalArgumentException
- ifbuilder
is null
-
getEnv
Get theEnv
associated with this instance.- Returns:
- the associated
Env
- Throws:
IllegalStateException
- if this instance is notstart()
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 interfaceKVDatabase
-
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 interfaceKVDatabase
-
createTransaction
Description copied from interface:KVDatabase
Create a new transaction.- Specified by:
createTransaction
in interfaceKVDatabase
- Returns:
- newly created transaction
-
createTransaction
Description copied from interface:KVDatabase
Create a new transaction with the specified options.- Specified by:
createTransaction
in interfaceKVDatabase
- Parameters:
options
- optional transaction options; may be null- Returns:
- newly created transaction
-
doCreateTransaction
-
finalize
Finalize this instance. Invokesstop()
to close any unclosed iterators. -
toString
-