T
- buffer typepublic abstract class LMDBKVStore<T> extends AbstractKVStore implements CloseableKVStore
Modifier | Constructor and Description |
---|---|
protected |
LMDBKVStore(org.lmdbjava.Dbi<T> db,
org.lmdbjava.Txn<T> tx)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close this instance.
|
protected void |
finalize()
Finalize this instance.
|
byte[] |
get(byte[] key)
Get the value associated with the given key, if any.
|
org.lmdbjava.Dbi<T> |
getDatabase()
Get the
Dbi associated with this instance. |
org.lmdbjava.KeyRange<T> |
getKeyRange(byte[] minKey,
byte[] maxKey,
boolean reverse)
Get the
KeyRange corresponding to the given parameters. |
CloseableIterator<KVPair> |
getRange(byte[] minKey,
byte[] maxKey,
boolean reverse)
Iterate the key/value pairs in the specified range.
|
org.lmdbjava.Txn<T> |
getTransaction()
Get the
Txn associated with this instance. |
boolean |
isClosed()
Determine if this instance is closed.
|
void |
put(byte[] key,
byte[] value)
Set the value associated with the given key.
|
void |
remove(byte[] key)
Remove the key/value pair with the given key, if it exists.
|
void |
removeRange(byte[] minKey,
byte[] maxKey)
Remove all key/value pairs whose keys are in a given range.
|
String |
toString() |
protected abstract byte[] |
unwrap(T buf,
boolean copy)
Unwrap the given buffer, returning its contents as a
byte[] array. |
protected abstract T |
wrap(byte[] buf,
boolean copy)
Wrap the given
byte[] array in a buffer appropriate for this instance. |
adjustCounter, decodeCounter, encodeCounter, getAtLeast, getAtMost
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
adjustCounter, apply, decodeCounter, encodeCounter, getAtLeast, getAtMost, getRange, getRange, removeRange
protected final Logger log
protected LMDBKVStore(org.lmdbjava.Dbi<T> db, org.lmdbjava.Txn<T> tx)
Closing this instance does not close the underlying transaction.
db
- LMDB databasetx
- LMDB transactionIllegalArgumentException
- if db
or tx
is nullpublic org.lmdbjava.Txn<T> getTransaction()
Txn
associated with this instance.public org.lmdbjava.Dbi<T> getDatabase()
Dbi
associated with this instance.public boolean isClosed()
public byte[] get(byte[] key)
KVStore
Modifications to the returned byte[]
array do not affect this instance.
get
in interface KVStore
get
in class AbstractKVStore
key
- keypublic CloseableIterator<KVPair> getRange(byte[] minKey, byte[] maxKey, boolean reverse)
KVStore
Iterator
's
remove()
method must be supported and should have the same effect as
invoking remove()
on the corresponding key.
If keys starting with 0xff
are not supported by this instance, and minKey
starts with 0xff
,
then this method returns an empty iteration.
If keys starting with 0xff
are not supported by this instance, and maxKey
starts with 0xff
,
then this method behaves as if maxKey
were null.
The returned Iterator
must not throw ConcurrentModificationException
;
however, whether or not a "live" Iterator
reflects any modifications made after its creation is
implementation dependent. Implementations that do make post-creation updates visible in the Iterator
,
even if the update occurs after some delay, must preserve the order in which the modifications actually occurred.
The returned Iterator
itself is not guaranteed to be thread safe.
Invokers of this method are encouraged to close()
the returned iterators,
though this is not required for correct behavior.
Modifications to the returned KVPair
key and value byte[]
arrays do not affect this instance.
getRange
in interface KVStore
minKey
- minimum key (inclusive), or null for no minimum (start at the smallest key)maxKey
- maximum key (exclusive), or null for no maximum (end at the largest key)reverse
- true to return key/value pairs in reverse order (i.e., keys descending)minKey
(inclusive) to maxKey
(exclusive)public void put(byte[] key, byte[] value)
KVStore
put
in interface KVStore
put
in class AbstractKVStore
key
- keyvalue
- valuepublic void remove(byte[] key)
KVStore
remove
in interface KVStore
remove
in class AbstractKVStore
key
- keypublic void removeRange(byte[] minKey, byte[] maxKey)
KVStore
The minKey
must be less than or equal to maxKey
; if they equal (and not null)
then nothing happens; if they are both null then all entries are deleted.
If keys starting with 0xff
are not supported by this instance, then:
minKey
starts with 0xff
, then no change occursmaxKey
starts with 0xff
, then this method behaves as if maxKey
were nullremoveRange
in interface KVStore
removeRange
in class AbstractKVStore
minKey
- minimum key (inclusive), or null for no minimummaxKey
- maximum key (exclusive), or null for no maximumpublic org.lmdbjava.KeyRange<T> getKeyRange(byte[] minKey, byte[] maxKey, boolean reverse)
KeyRange
corresponding to the given parameters.minKey
- minimum key (inclusive), or null for nonemaxKey
- maximum key (exclusive), or null for nonereverse
- true for reverse ordering, false for forward orderingKeyRange
instanceprotected abstract T wrap(byte[] buf, boolean copy)
byte[]
array in a buffer appropriate for this instance.buf
- byte array data, or possibly nullcopy
- if true, then changes to the data in either buf
or the returned buffer must not affect the otherbuf
is null, otherwise a buffer containing the data in buf
protected abstract byte[] unwrap(T buf, boolean copy)
byte[]
array.buf
- a buffer containing byte[]
array data, or possibly nullcopy
- if true, then changes to the data in either buf
or the returned array must not affect the otherbuf
, or null if buf
is nullpublic void close()
This closes any unclosed iterators; it does not close the underlying transaction.
close
in interface CloseableKVStore
close
in interface Closeable
close
in interface AutoCloseable
protected void finalize() throws Throwable
close()
to close any unclosed iterators.Copyright © 2022. All rights reserved.