T
- buffer typepublic final class Env<T>
extends java.lang.Object
implements java.lang.AutoCloseable
Modifier and Type | Class and Description |
---|---|
static class |
Env.AlreadyClosedException
Object has already been closed and the operation is therefore prohibited.
|
static class |
Env.AlreadyOpenException
Object has already been opened and the operation is therefore prohibited.
|
static class |
Env.Builder<T>
Builder for configuring and opening Env.
|
static class |
Env.FileInvalidException
File is not a valid LMDB file.
|
static class |
Env.InvalidCopyDestination
The specified copy destination is invalid.
|
static class |
Env.MapFullException
Environment mapsize reached.
|
static class |
Env.ReadersFullException
Environment maxreaders reached.
|
static class |
Env.VersionMismatchException
Environment version mismatch.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DISABLE_CHECKS_PROP
Java system property name that can be set to disable optional checks.
|
static boolean |
SHOULD_CHECK
Indicates whether optional checks should be applied in LmdbJava.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the handle.
|
void |
copy(java.io.File path,
CopyFlags... flags)
Copies an LMDB environment to the specified destination path.
|
static Env.Builder<java.nio.ByteBuffer> |
create()
Create an
Env using the ByteBufferProxy.PROXY_OPTIMAL . |
static <T> Env.Builder<T> |
create(BufferProxy<T> proxy)
Create an
Env using the passed BufferProxy . |
java.util.List<byte[]> |
getDbiNames()
Obtain the DBI names.
|
int |
getMaxKeySize()
Get the maximum size of keys and MDB_DUPSORT data we can write.
|
EnvInfo |
info()
Return information about this environment.
|
boolean |
isClosed()
Indicates whether this environment has been closed.
|
boolean |
isReadOnly()
Indicates if this environment was opened with
EnvFlags.MDB_RDONLY_ENV . |
static Env<java.nio.ByteBuffer> |
open(java.io.File path,
int size,
EnvFlags... flags)
Opens an environment with a single default database in 0664 mode using the
ByteBufferProxy.PROXY_OPTIMAL . |
Dbi<T> |
openDbi(byte[] name,
java.util.Comparator<T> comparator,
DbiFlags... flags)
Open the
Dbi . |
Dbi<T> |
openDbi(byte[] name,
DbiFlags... flags)
Open the
Dbi . |
Dbi<T> |
openDbi(java.lang.String name,
java.util.Comparator<T> comparator,
DbiFlags... flags)
Convenience method that opens a
Dbi with a UTF-8 database name
and custom comparator. |
Dbi<T> |
openDbi(java.lang.String name,
DbiFlags... flags)
Convenience method that opens a
Dbi with a UTF-8 database name. |
Stat |
stat()
Return statistics about this environment.
|
void |
sync(boolean force)
Flushes the data buffers to disk.
|
Txn<T> |
txn(Txn<T> parent,
TxnFlags... flags)
Obtain a transaction with the requested parent and flags.
|
Txn<T> |
txnRead()
Obtain a read-only transaction.
|
Txn<T> |
txnWrite()
Obtain a read-write transaction.
|
public static final java.lang.String DISABLE_CHECKS_PROP
public static final boolean SHOULD_CHECK
public static Env.Builder<java.nio.ByteBuffer> create()
Env
using the ByteBufferProxy.PROXY_OPTIMAL
.public static <T> Env.Builder<T> create(BufferProxy<T> proxy)
Env
using the passed BufferProxy
.T
- buffer typeproxy
- the proxy to use (required)public static Env<java.nio.ByteBuffer> open(java.io.File path, int size, EnvFlags... flags)
ByteBufferProxy.PROXY_OPTIMAL
.path
- file system destinationsize
- size in megabytesflags
- the flags for this new environmentpublic void close()
Will silently return if already closed or never opened.
close
in interface java.lang.AutoCloseable
public void copy(java.io.File path, CopyFlags... flags)
This function may be used to make a backup of an existing environment. No lockfile is created, since it gets recreated at need.
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.
path
- destination directory, which must exist, be writable and emptyflags
- special options for this copypublic java.util.List<byte[]> getDbiNames()
This method is only compatible with Env
s that use named databases.
If an unnamed Dbi
is being used to store data, this method will
attempt to return all such keys from the unnamed database.
public int getMaxKeySize()
public EnvInfo info()
public boolean isClosed()
public boolean isReadOnly()
EnvFlags.MDB_RDONLY_ENV
.public Dbi<T> openDbi(java.lang.String name, DbiFlags... flags)
Dbi
with a UTF-8 database name.name
- name of the database (or null if no name is required)flags
- to open the database withpublic Dbi<T> openDbi(java.lang.String name, java.util.Comparator<T> comparator, DbiFlags... flags)
Dbi
with a UTF-8 database name
and custom comparator.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 withpublic Dbi<T> openDbi(byte[] name, DbiFlags... flags)
Dbi
.name
- name of the database (or null if no name is required)flags
- to open the database withpublic Dbi<T> openDbi(byte[] name, java.util.Comparator<T> comparator, DbiFlags... flags)
Dbi
.
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 CursorIterator
is created from the returned Dbi
. 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).
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 withpublic Stat stat()
public void sync(boolean force)
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)public Txn<T> txn(Txn<T> parent, TxnFlags... flags)
parent
- parent transaction (may be null if no parent)flags
- applicable flags (eg for a reusable, read-only transaction)Copyright © 2016–2018 The LmdbJava Open Source Project. All rights reserved.