T
- buffer typepublic final class Dbi<T>
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
Dbi.BadDbiException
The specified DBI was changed unexpectedly.
|
static class |
Dbi.BadValueSizeException
Unsupported size of key/DB name/data, or wrong DUPFIXED size.
|
static class |
Dbi.DbFullException
Environment maxdbs reached.
|
static class |
Dbi.IncompatibleException
Operation and DB incompatible, or DB type changed.
|
static class |
Dbi.KeyExistsException
Key/data pair already exists.
|
static class |
Dbi.KeyNotFoundException
Key/data pair not found (EOF).
|
static class |
Dbi.MapResizedException
Database contents grew beyond environment mapsize.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the database handle (normally unnecessary; use with caution).
|
boolean |
delete(T key)
Starts a new read-write transaction and deletes the key.
|
boolean |
delete(Txn<T> txn,
T key)
Deletes the key using the passed transaction.
|
boolean |
delete(Txn<T> txn,
T key,
T val)
Removes key/data pairs from the database.
|
void |
drop(Txn<T> txn)
Drops the data in this database, leaving the database open for further use.
|
void |
drop(Txn<T> txn,
boolean delete)
Drops the database.
|
T |
get(Txn<T> txn,
T key)
Get items from a database, moving the
Txn.val() to the value. |
byte[] |
getName()
Obtains the name of this database.
|
CursorIterator<T> |
iterate(Txn<T> txn)
Iterate the database from the first item and forwards.
|
CursorIterator<T> |
iterate(Txn<T> txn,
CursorIterator.IteratorType type)
Deprecated.
use iterate method with a
KeyRange instead |
CursorIterator<T> |
iterate(Txn<T> txn,
KeyRange<T> range)
Iterate the database in accordance with the provided
KeyRange and
default Comparator . |
CursorIterator<T> |
iterate(Txn<T> txn,
KeyRange<T> range,
java.util.Comparator<T> comparator)
Iterate the database in accordance with the provided
KeyRange and
Comparator . |
CursorIterator<T> |
iterate(Txn<T> txn,
T key,
CursorIterator.IteratorType type)
Deprecated.
use iterate method with a
KeyRange instead |
Cursor<T> |
openCursor(Txn<T> txn)
Create a cursor handle.
|
void |
put(T key,
T val)
Starts a new read-write transaction and puts the key/data pair.
|
boolean |
put(Txn<T> txn,
T key,
T val,
PutFlags... flags)
Store a key/value pair in the database.
|
T |
reserve(Txn<T> txn,
T key,
int size,
PutFlags... op)
Reserve space for data of the given size, but don't copy the given val.
|
Stat |
stat(Txn<T> txn)
Return statistics about this database.
|
public void close()
It is very rare that closing a database handle is useful. There are also
many warnings/restrictions if closing a database handle (refer to the LMDB
C documentation). As such this is non-routine usage and this class does not
track the open/closed state of the Dbi
. Advanced users are expected
to have specific reasons for using this method and will manage their own
state accordingly.
public boolean delete(T key)
key
- key to delete from the database (not null)delete(org.lmdbjava.Txn, java.lang.Object, java.lang.Object)
public boolean delete(Txn<T> txn, T key)
txn
- transaction handle (not null; not committed; must be R-W)key
- key to delete from the database (not null)delete(org.lmdbjava.Txn, java.lang.Object, java.lang.Object)
public boolean delete(Txn<T> txn, T key, T val)
If the database does not support sorted duplicate data items
(DbiFlags.MDB_DUPSORT
) the value parameter is ignored. If the
database supports sorted duplicates and the value parameter is null, all of
the duplicate data items for the key will be deleted. Otherwise, if the
data parameter is non-null only the matching data item will be deleted.
txn
- transaction handle (not null; not committed; must be R-W)key
- key to delete from the database (not null)val
- value to delete from the database (null permitted)public void drop(Txn<T> txn)
This method slightly differs from the LMDB C API in that it does not
provide support for also closing the DB handle. If closing the DB handle is
required, please see close()
.
txn
- transaction handle (not null; not committed; must be R-W)public void drop(Txn<T> txn, boolean delete)
close()
for implication of handle
close. Otherwise, only the data in this database will be dropped.txn
- transaction handle (not null; not committed; must be R-W)delete
- whether database should be deleted.public T get(Txn<T> txn, T key)
Txn.val()
to the value.
This function retrieves key/data pairs from the database. The address and
length of the data associated with the specified \b key are returned in the
structure to which \b data refers. If the database supports duplicate keys
(DbiFlags.MDB_DUPSORT
) then the first data item for
the key will be returned. Retrieval of other items requires the use of
#mdb_cursor_get().
txn
- transaction handle (not null; not committed)key
- key to search for in the database (not null)public byte[] getName()
public CursorIterator<T> iterate(Txn<T> txn)
txn
- transaction handle (not null; not committed)@Deprecated public CursorIterator<T> iterate(Txn<T> txn, CursorIterator.IteratorType type)
KeyRange
insteadtxn
- transaction handle (not null; not committed)type
- direction of iterator (not null)@Deprecated public CursorIterator<T> iterate(Txn<T> txn, T key, CursorIterator.IteratorType type)
KeyRange
insteadtxn
- transaction handle (not null; not committed)key
- the key to search from (may be null to denote first record)type
- direction of iterator (not null)public CursorIterator<T> iterate(Txn<T> txn, KeyRange<T> range)
KeyRange
and
default Comparator
.txn
- transaction handle (not null; not committed)range
- range of acceptable keys (not null)public CursorIterator<T> iterate(Txn<T> txn, KeyRange<T> range, java.util.Comparator<T> comparator)
KeyRange
and
Comparator
.
If a comparator is provided, it must reflect the same ordering as LMDB uses for cursor operations (eg first, next, last, previous etc).
If a null comparator is provided, any comparator provided when opening the database is used. If no database comparator was specified, the buffer's default comparator is used. Such buffer comparators reflect LMDB's default lexicographical order.
txn
- transaction handle (not null; not committed)range
- range of acceptable keys (not null)comparator
- custom comparator for keys (may be null)public Cursor<T> openCursor(Txn<T> txn)
A cursor is associated with a specific transaction and database. A cursor
cannot be used when its database handle is closed. Nor when its transaction
has ended, except with Cursor.renew(org.lmdbjava.Txn)
. It can be
discarded with Cursor.close()
. A cursor in a write-transaction can
be closed before its transaction ends, and will otherwise be closed when
its transaction ends. A cursor in a read-only transaction must be closed
explicitly, before or after its transaction ends. It can be reused with
Cursor.renew(org.lmdbjava.Txn)
before finally closing it.
txn
- transaction handle (not null; not committed)public void put(T key, T val)
key
- key to store in the database (not null)val
- value to store in the database (not null)put(org.lmdbjava.Txn, java.lang.Object, java.lang.Object,
org.lmdbjava.PutFlags...)
public boolean put(Txn<T> txn, T key, T val, PutFlags... flags)
This function stores key/data pairs in the database. The default behavior
is to enter the new key/data pair, replacing any previously existing key if
duplicates are disallowed, or adding a duplicate data item if duplicates
are allowed (DbiFlags.MDB_DUPSORT
).
txn
- transaction handle (not null; not committed; must be R-W)key
- key to store in the database (not null)val
- value to store in the database (not null)flags
- Special options for this operationpublic T reserve(Txn<T> txn, T key, int size, PutFlags... op)
This flag must not be specified if the database was opened with MDB_DUPSORT
txn
- transaction handle (not null; not committed; must be R-W)key
- key to store in the database (not null)size
- size of the value to be stored in the databaseop
- options for this operationCopyright © 2016–2018 The LmdbJava Open Source Project. All rights reserved.