Interface KeyValueStorage
- All Superinterfaces:
AutoCloseable,Closeable
- All Known Implementing Classes:
KeyValueStorageRocksDB
Abstraction of a generic key-value local database.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceInterface for a batch to be written in the storage.static interfaceIterator interface. -
Method Summary
Modifier and TypeMethodDescriptiondefault voidcompact()Compact storage full range.default voidcompact(byte[] firstKey, byte[] lastKey) Compact storage within a specified range.longcount()voiddelete(byte[] key) byte[]get(byte[] key) Get the value associated with the given key.intget(byte[] key, byte[] value) Get the value associated with the given key.Map.Entry<byte[],byte[]> getCeil(byte[] key) Get the entry whose key is bigger or equal the supplied key.Get storage path.Map.Entry<byte[],byte[]> getFloor(byte[] key) Get the entry whose key is the biggest and it's lesser than the supplied key.KeyValueStorage.CloseableIterator<Map.Entry<byte[],byte[]>> iterator()Return an iterator object that can be used to sequentially scan through all the entries in the database.keys()Get an iterator over to scan sequentially through all the keys in the database.keys(byte[] firstKey, byte[] lastKey) Get an iterator over to scan sequentially through all the keys within a specified range.newBatch()voidput(byte[] key, byte[] value) voidsync()Commit all pending write to durable storage.
-
Method Details
-
put
- Throws:
IOException
-
get
Get the value associated with the given key.- Parameters:
key- the key to lookup- Returns:
- the value or null if the key was not found
- Throws:
IOException
-
get
Get the value associated with the given key.This method will use the provided array store the value
- Parameters:
key- the key to lookupvalue- an array where to store the result- Returns:
- -1 if the entry was not found or the length of the value
- Throws:
IOException- if the value array could not hold the result
-
getFloor
Get the entry whose key is the biggest and it's lesser than the supplied key.For example if the db contains :
{ 1 : 'a', 2 : 'b', 3 : 'c' }Then:
getFloor(3) --> (2, 'b')
- Parameters:
key- the non-inclusive upper limit key- Returns:
- the entry before or null if there's no entry before key
- Throws:
IOException
-
getCeil
Get the entry whose key is bigger or equal the supplied key.- Parameters:
key-- Returns:
- Throws:
IOException
-
delete
- Parameters:
key-- Throws:
IOException
-
compact
Compact storage within a specified range.- Parameters:
firstKey- the first key in the range (included)lastKey- the last key in the range (not included)- Throws:
IOException
-
compact
Compact storage full range.- Throws:
IOException
-
getDBPath
String getDBPath()Get storage path. -
keys
KeyValueStorage.CloseableIterator<byte[]> keys()Get an iterator over to scan sequentially through all the keys in the database.- Returns:
-
keys
Get an iterator over to scan sequentially through all the keys within a specified range.- Parameters:
firstKey- the first key in the range (included)lastKey- the lastKey in the range (not included)
-
iterator
KeyValueStorage.CloseableIterator<Map.Entry<byte[],byte[]>> iterator()Return an iterator object that can be used to sequentially scan through all the entries in the database. -
sync
Commit all pending write to durable storage.- Throws:
IOException
-
count
- Returns:
- the number of keys.
- Throws:
IOException
-
newBatch
KeyValueStorage.Batch newBatch()
-