Class LMDBKVStore<T>
- Type Parameters:
T
- buffer type
- All Implemented Interfaces:
CloseableKVStore
,KVStore
,Closeable
,AutoCloseable
- Direct Known Subclasses:
ByteArrayLMDBKVStore
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
LMDBKVStore
(org.lmdbjava.Dbi<T> db, org.lmdbjava.Txn<T> tx) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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>
Get theDbi
associated with this instance.org.lmdbjava.KeyRange<T>
getKeyRange
(byte[] minKey, byte[] maxKey, boolean reverse) Get theKeyRange
corresponding to the given parameters.getRange
(byte[] minKey, byte[] maxKey, boolean reverse) Iterate the key/value pairs in the specified range.org.lmdbjava.Txn<T>
Get theTxn
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.toString()
protected abstract byte[]
Unwrap the given buffer, returning its contents as abyte[]
array.protected abstract T
wrap
(byte[] buf, boolean copy) Wrap the givenbyte[]
array in a buffer appropriate for this instance.Methods inherited from class io.permazen.kv.AbstractKVStore
adjustCounter, decodeCounter, encodeCounter, getAtLeast, getAtMost
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface io.permazen.kv.KVStore
adjustCounter, apply, decodeCounter, encodeCounter, getAtLeast, getAtMost, getRange, getRange, removeRange
-
Field Details
-
log
-
-
Constructor Details
-
LMDBKVStore
Constructor.Closing this instance does not close the underlying transaction.
- Parameters:
db
- LMDB databasetx
- LMDB transaction- Throws:
IllegalArgumentException
- ifdb
ortx
is null
-
-
Method Details
-
getTransaction
Get theTxn
associated with this instance.- Returns:
- associated transaction
-
getDatabase
Get theDbi
associated with this instance.- Returns:
- associated database handle
-
isClosed
public boolean isClosed()Determine if this instance is closed.- Returns:
- true if closed, false if still open
-
get
public byte[] get(byte[] key) Description copied from interface:KVStore
Get the value associated with the given key, if any.Modifications to the returned
byte[]
array do not affect this instance.- Specified by:
get
in interfaceKVStore
- Overrides:
get
in classAbstractKVStore
- Parameters:
key
- key- Returns:
- value associated with key, or null if not found
-
getRange
Description copied from interface:KVStore
Iterate the key/value pairs in the specified range. The returnedCloseableIterator
'sremove()
method must be supported and should have the same effect as invokingremove()
on the corresponding key.If keys starting with
0xff
are not supported by this instance, andminKey
starts with0xff
, then this method returns an empty iteration.If keys starting with
0xff
are not supported by this instance, andmaxKey
starts with0xff
, then this method behaves as ifmaxKey
were null.The returned
CloseableIterator
is weakly consistent (seejava.util.concurrent
). In short, the returnedCloseableIterator
must not throwConcurrentModificationException
; however, whether or not a "live"CloseableIterator
reflects any modifications made after its creation is implementation dependent. Implementations that do make post-creation updates visible in theCloseableIterator
, even if the update occurs after some delay, must preserve the order in which the modifications actually occurred.The returned
CloseableIterator
itself is not guaranteed to be thread safe; is should only be used in the thread that created it.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 valuebyte[]
arrays do not affect this instance.- Specified by:
getRange
in interfaceKVStore
- Parameters:
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)- Returns:
- iteration of key/value pairs in the range
minKey
(inclusive) tomaxKey
(exclusive)
-
put
public void put(byte[] key, byte[] value) Description copied from interface:KVStore
Set the value associated with the given key.- Specified by:
put
in interfaceKVStore
- Overrides:
put
in classAbstractKVStore
- Parameters:
key
- keyvalue
- value
-
remove
public void remove(byte[] key) Description copied from interface:KVStore
Remove the key/value pair with the given key, if it exists.- Specified by:
remove
in interfaceKVStore
- Overrides:
remove
in classAbstractKVStore
- Parameters:
key
- key
-
removeRange
public void removeRange(byte[] minKey, byte[] maxKey) Description copied from interface:KVStore
Remove all key/value pairs whose keys are in a given range.The
minKey
must be less than or equal tomaxKey
; 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:- If
minKey
starts with0xff
, then no change occurs - If
maxKey
starts with0xff
, then this method behaves as ifmaxKey
were null
- Specified by:
removeRange
in interfaceKVStore
- Overrides:
removeRange
in classAbstractKVStore
- Parameters:
minKey
- minimum key (inclusive), or null for no minimummaxKey
- maximum key (exclusive), or null for no maximum
- If
-
getKeyRange
Get theKeyRange
corresponding to the given parameters.- Parameters:
minKey
- minimum key (inclusive), or null for nonemaxKey
- maximum key (exclusive), or null for nonereverse
- true for reverse ordering, false for forward ordering- Returns:
KeyRange
instance
-
wrap
Wrap the givenbyte[]
array in a buffer appropriate for this instance.- Parameters:
buf
- byte array data, or possibly nullcopy
- if true, then changes to the data in eitherbuf
or the returned buffer must not affect the other- Returns:
- null if
buf
is null, otherwise a buffer containing the data inbuf
-
unwrap
Unwrap the given buffer, returning its contents as abyte[]
array.- Parameters:
buf
- a buffer containingbyte[]
array data, or possibly nullcopy
- if true, then changes to the data in eitherbuf
or the returned array must not affect the other- Returns:
- byte array data in
buf
, or null ifbuf
is null
-
close
public void close()Close this instance.This closes any unclosed iterators; it does not close the underlying transaction.
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceCloseableKVStore
-
finalize
Finalize this instance. Invokesclose()
to close any unclosed iterators. -
toString
-