Class LevelDBKVStore
- All Implemented Interfaces:
CloseableKVStore,KVStore,Closeable,AutoCloseable
- Direct Known Subclasses:
SnapshotLevelDBKVStore
-
Constructor Summary
ConstructorsConstructorDescriptionLevelDBKVStore(org.iq80.leveldb.DB db) Convenience constructor.LevelDBKVStore(org.iq80.leveldb.DB db, org.iq80.leveldb.ReadOptions readOptions, org.iq80.leveldb.WriteBatch writeBatch) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close this instance.protected voidfinalize()Finalize this instance.Get the value associated with the given key, if any.org.iq80.leveldb.DBgetDB()Get theDBunderlying this instance.Iterate the key/value pairs in the specified range.voidSet the value associated with the given key.voidRemove the key/value pair with the given key, if it exists.toString()Methods inherited from class io.permazen.kv.AbstractKVStore
adjustCounter, decodeCounter, encodeCounter, getAtLeast, getAtMost, removeRangeMethods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface io.permazen.kv.KVStore
adjustCounter, apply, decodeCounter, encodeCounter, getAtLeast, getAtMost, getRange, getRange, removeRange, removeRange
-
Constructor Details
-
LevelDBKVStore
public LevelDBKVStore(org.iq80.leveldb.DB db) Convenience constructor. Uses default read options and no write batching.- Parameters:
db- database
-
LevelDBKVStore
public LevelDBKVStore(org.iq80.leveldb.DB db, org.iq80.leveldb.ReadOptions readOptions, org.iq80.leveldb.WriteBatch writeBatch) Constructor.- Parameters:
db- databasereadOptions- read options, or null for the defaultwriteBatch- batch for write operations, or null for none- Throws:
IllegalArgumentException- ifdbis null
-
-
Method Details
-
getDB
public org.iq80.leveldb.DB getDB()Get theDBunderlying this instance.- Returns:
- underlying database
-
get
Description copied from interface:KVStoreGet the value associated with the given key, if any.- Specified by:
getin interfaceKVStore- Overrides:
getin classAbstractKVStore- Parameters:
key- key- Returns:
- value associated with key, or null if not found
-
getRange
Description copied from interface:KVStoreIterate 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
0xffare not supported by this instance, andminKeystarts with0xff, then this method returns an empty iteration.If keys starting with
0xffare not supported by this instance, andmaxKeystarts with0xff, then this method behaves as ifmaxKeywere null.The returned
CloseableIteratoris weakly consistent (seejava.util.concurrent). In short, the returnedCloseableIteratormust not throwConcurrentModificationException; however, whether or not a "live"CloseableIteratorreflects 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
CloseableIteratoritself 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.- Specified by:
getRangein 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
Description copied from interface:KVStoreSet the value associated with the given key.- Specified by:
putin interfaceKVStore- Overrides:
putin classAbstractKVStore- Parameters:
key- keyvalue- value
-
remove
Description copied from interface:KVStoreRemove the key/value pair with the given key, if it exists.- Specified by:
removein interfaceKVStore- Overrides:
removein classAbstractKVStore- Parameters:
key- key
-
finalize
Finalize this instance. Invokesclose()to close any unclosed iterators. -
toString
-
close
public void close()Close this instance.This closes any unclosed iterators returned from
getRange(). This does not close the underlyingDBor any associatedWriteBatch.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceCloseableKVStore
-