- Type Parameters:
T- buffer type
- All Implemented Interfaces:
AutoCloseable
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classObject has already been closed and the operation is therefore prohibited.static final classObject has already been opened and the operation is therefore prohibited.static final classBuilder for configuring and opening Env.static final classFile is not a valid LMDB file.static final classThe specified copy destination is invalid.static final classEnvironment mapsize reached.static final classEnvironment maxreaders reached.static final classEnvironment version mismatch. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringJava system property name that can be set to disable optional checks.static final booleanIndicates whether optional checks should be applied in LmdbJava. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the handle.voidCopies an LMDB environment to the specified destination path.static Env.Builder<ByteBuffer>create()Create anEnvusing theByteBufferProxy.PROXY_OPTIMAL.static <T> Env.Builder<T>create(BufferProxy<T> proxy) Create anEnvusing the passedBufferProxy.List<byte[]>Obtain the DBI names.intGet the maximum size of keys and MDB_DUPSORT data we can write.info()Return information about this environment.booleanisClosed()Indicates whether this environment has been closed.booleanIndicates if this environment was opened withEnvFlags.MDB_RDONLY_ENV.static Env<ByteBuffer>Opens an environment with a single default database in 0664 mode using theByteBufferProxy.PROXY_OPTIMAL.openDbi(byte[] name, Comparator<T> comparator, DbiFlags... flags) Open theDbi.Open theDbi.openDbi(String name, Comparator<T> comparator, DbiFlags... flags) Convenience method that opens aDbiwith a UTF-8 database name and custom comparator.Convenience method that opens aDbiwith a UTF-8 database name.voidsetMapSize(long mapSize) Set the size of the data memory map.stat()Return statistics about this environment.voidsync(boolean force) Flushes the data buffers to disk.Obtain a transaction with the requested parent and flags.txnRead()Obtain a read-only transaction.txnWrite()Obtain a read-write transaction.
-
Field Details
-
DISABLE_CHECKS_PROP
Java system property name that can be set to disable optional checks.- See Also:
-
SHOULD_CHECK
public static final boolean SHOULD_CHECKIndicates whether optional checks should be applied in LmdbJava. Optional checks are only disabled in critical paths (see package-level JavaDocs). Non-critical paths have optional checks performed at all times, regardless of this property.
-
-
Method Details
-
create
Create anEnvusing theByteBufferProxy.PROXY_OPTIMAL.- Returns:
- the environment (never null)
-
create
Create anEnvusing the passedBufferProxy.- Type Parameters:
T- buffer type- Parameters:
proxy- the proxy to use (required)- Returns:
- the environment (never null)
-
open
Opens an environment with a single default database in 0664 mode using theByteBufferProxy.PROXY_OPTIMAL.- Parameters:
path- file system destinationsize- size in megabytesflags- the flags for this new environment- Returns:
- env the environment (never null)
-
close
public void close()Close the handle.Will silently return if already closed or never opened.
- Specified by:
closein interfaceAutoCloseable
-
copy
Copies an LMDB environment to the specified destination path.This function may be used to make a backup of an existing environment. No lockfile is created, since it gets recreated at need.
If this environment was created using
EnvFlags.MDB_NOSUBDIR, the destination path must be a directory that exists but contains no files. IfEnvFlags.MDB_NOSUBDIRwas used, the destination path must not exist, but it must be possible to create a file at the provided path.Note: This call can trigger significant file size growth if run in parallel with write transactions, because it employs a read-only transaction. See long-lived transactions under "Caveats" in the LMDB native documentation.
- Parameters:
path- writable destination path as described aboveflags- special options for this copy
-
getDbiNames
Obtain the DBI names.This method is only compatible with
Envs that use named databases. If an unnamedDbiis being used to store data, this method will attempt to return all such keys from the unnamed database.- Returns:
- a list of DBI names (never null)
-
setMapSize
public void setMapSize(long mapSize) Set the size of the data memory map.- Parameters:
mapSize- the new size, in bytes
-
getMaxKeySize
public int getMaxKeySize()Get the maximum size of keys and MDB_DUPSORT data we can write.- Returns:
- the maximum size of keys.
-
info
Return information about this environment.- Returns:
- an immutable information object.
-
isClosed
public boolean isClosed()Indicates whether this environment has been closed.- Returns:
- true if closed
-
isReadOnly
public boolean isReadOnly()Indicates if this environment was opened withEnvFlags.MDB_RDONLY_ENV.- Returns:
- true if read-only
-
openDbi
Convenience method that opens aDbiwith a UTF-8 database name.- Parameters:
name- name of the database (or null if no name is required)flags- to open the database with- Returns:
- a database that is ready to use
-
openDbi
Convenience method that opens aDbiwith a UTF-8 database name and custom comparator.- Parameters:
name- name of the database (or null if no name is required)comparator- custom comparator callback (or null to use LMDB default)flags- to open the database with- Returns:
- a database that is ready to use
-
openDbi
Open theDbi.- Parameters:
name- name of the database (or null if no name is required)flags- to open the database with- Returns:
- a database that is ready to use
-
openDbi
Open theDbi.If a custom comparator is specified, this comparator is called from LMDB any time it needs to compare two keys. The comparator must be used any time any time this database is opened, otherwise database corruption may occur. The custom comparator will also be used whenever a
CursorIterableis created from the returnedDbi. If a custom comparator is not specified, LMDB's native default lexicographical order is used. The default comparator is typically more efficient (as there is no need for the native library to call back into Java for the comparator result).- Parameters:
name- name of the database (or null if no name is required)comparator- custom comparator callback (or null to use LMDB default)flags- to open the database with- Returns:
- a database that is ready to use
-
stat
Return statistics about this environment.- Returns:
- an immutable statistics object.
-
sync
public void sync(boolean force) Flushes the data buffers to disk.- Parameters:
force- force a synchronous flush (otherwise if the environment has the MDB_NOSYNC flag set the flushes will be omitted, and with MDB_MAPASYNC they will be asynchronous)
-
txn
Obtain a transaction with the requested parent and flags.- Parameters:
parent- parent transaction (may be null if no parent)flags- applicable flags (eg for a reusable, read-only transaction)- Returns:
- a transaction (never null)
-
txnRead
Obtain a read-only transaction.- Returns:
- a read-only transaction
-
txnWrite
Obtain a read-write transaction.- Returns:
- a read-write transaction
-