Interface KeyValueStorage

  • All Superinterfaces:
    java.lang.AutoCloseable, java.io.Closeable
    All Known Implementing Classes:
    KeyValueStorageRocksDB

    public interface KeyValueStorage
    extends java.io.Closeable
    Abstraction of a generic key-value local database.
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default void compact()
      Compact storage full range.
      default void compact​(byte[] firstKey, byte[] lastKey)
      Compact storage within a specified range.
      long count()  
      void delete​(byte[] key)  
      byte[] get​(byte[] key)
      Get the value associated with the given key.
      int get​(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.String getDBPath()
      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.Batch newBatch()  
      void put​(byte[] key, byte[] value)  
      void sync()
      Commit all pending write to durable storage.
      • Methods inherited from interface java.io.Closeable

        close
    • 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.IOException
        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:
        java.io.IOException
      • get

        int get​(byte[] key,
                byte[] value)
         throws java.io.IOException
        Get the value associated with the given key.

        This method will use the provided array store the value

        Parameters:
        key - the key to lookup
        value - 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.IOException
        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:
        java.io.IOException
      • getCeil

        java.util.Map.Entry<byte[],​byte[]> getCeil​(byte[] key)
                                                  throws java.io.IOException
        Get 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.IOException
        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:
        java.io.IOException
      • compact

        default void compact()
                      throws java.io.IOException
        Compact storage full range.
        Throws:
        java.io.IOException
      • getDBPath

        java.lang.String getDBPath()
        Get storage path.
      • 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