Interface KeyValueStorage
-
- All Superinterfaces:
java.lang.AutoCloseable,java.io.Closeable
- All Known Implementing Classes:
KeyValueStorageRocksDB
public interface KeyValueStorage extends java.io.CloseableAbstraction of a generic key-value local database.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceKeyValueStorage.BatchInterface for a batch to be written in the storage.static interfaceKeyValueStorage.CloseableIterator<T>Iterator interface.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default 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.java.util.Map.Entry<byte[],byte[]>getCeil(byte[] key)Get the entry whose key is bigger or equal the supplied key.java.lang.StringgetDBPath()Get storage path.java.util.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<java.util.Map.Entry<byte[],byte[]>>iterator()Return an iterator object that can be used to sequentially scan through all the entries in the database.KeyValueStorage.CloseableIterator<byte[]>keys()Get an iterator over to scan sequentially through all the keys in the database.KeyValueStorage.CloseableIterator<byte[]>keys(byte[] firstKey, byte[] lastKey)Get an iterator over to scan sequentially through all the keys within a specified range.KeyValueStorage.BatchnewBatch()voidput(byte[] key, byte[] value)voidsync()Commit all pending write to durable storage.
-
-
-
Method Detail
-
put
void put(byte[] key, byte[] value) throws java.io.IOException- Throws:
java.io.IOException
-
get
byte[] get(byte[] key) throws java.io.IOExceptionGet 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:
java.io.IOException
-
get
int get(byte[] key, byte[] value) throws java.io.IOExceptionGet 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:
java.io.IOException- if the value array could not hold the result
-
getFloor
java.util.Map.Entry<byte[],byte[]> getFloor(byte[] key) throws java.io.IOExceptionGet 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:
java.io.IOException
-
getCeil
java.util.Map.Entry<byte[],byte[]> getCeil(byte[] key) throws java.io.IOExceptionGet the entry whose key is bigger or equal the supplied key.- Parameters:
key-- Returns:
- Throws:
java.io.IOException
-
delete
void delete(byte[] key) throws java.io.IOException- Parameters:
key-- Throws:
java.io.IOException
-
compact
default void compact(byte[] firstKey, byte[] lastKey) throws java.io.IOExceptionCompact storage within a specified range.- Parameters:
firstKey- the first key in the range (included)lastKey- the last key in the range (not included)- Throws:
java.io.IOException
-
compact
default void compact() throws java.io.IOExceptionCompact storage full range.- Throws:
java.io.IOException
-
getDBPath
java.lang.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
KeyValueStorage.CloseableIterator<byte[]> keys(byte[] firstKey, byte[] lastKey)
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<java.util.Map.Entry<byte[],byte[]>> iterator()
Return an iterator object that can be used to sequentially scan through all the entries in the database.
-
sync
void sync() throws java.io.IOException
Commit all pending write to durable storage.- Throws:
java.io.IOException
-
count
long count() throws java.io.IOException- Returns:
- the number of keys.
- Throws:
java.io.IOException
-
newBatch
KeyValueStorage.Batch newBatch()
-
-