Class Database<K,V>

java.lang.Object
io.pmem.pmemkv.Database<K,V>
Type Parameters:
K - the type of key stored in pmemkv datastore
V - the type of value stored in pmemkv datastore

public class Database<K,V> extends Object
Main Java binding pmemkv class, which is a local/embedded key-value datastore optimized for persistent memory. Rather than being tied to a single language or backing implementation, pmemkv provides different options for language bindings and storage engines.

This generic class allows to store data of any type (as both key and value). In most cases user needs to implement Converter interface, which provides functionality of converting between key and value types, and ByteBuffer.

See Also:
  • Field Details

    • keyConverter

      Converter<K> keyConverter
    • valueConverter

      Converter<V> valueConverter
    • pointer

      private final long pointer
    • stopped

      private boolean stopped
  • Constructor Details

  • Method Details

    • getDirectBuffer

      private ByteBuffer getDirectBuffer(ByteBuffer buf)
    • stop

      public void stop()
      Stops the running engine.
      Since:
      1.0
    • stopped

      public boolean stopped()
      Checks if engine is stopped
      Returns:
      true if engine is stopped, false if it is running.
      Since:
      1.0
    • getKeys

      public void getKeys(KeyCallback<K> callback)
      Executes callback function for every key stored in the pmemkv datastore.
      Parameters:
      callback - Function to be called for each key.
      Since:
      1.0
    • getKeysAbove

      public void getKeysAbove(K key, KeyCallback<K> callback)
      Executes callback function for every key stored in the pmemkv datastore, whose keys are greater than the given key.

      Comparison mechanism is based on binary comparison of bytes - by a function equivalent to std::string::compare in C++

      Parameters:
      key - Sets the lower bound for querying.
      callback - Function to be called for each key.
      Since:
      1.0
    • getKeysBelow

      public void getKeysBelow(K key, KeyCallback<K> callback)
      Executes callback function for every key stored in the pmemkv datastore, whose keys are less than the given key.

      Comparison mechanism is based on binary comparison of bytes - by a function equivalent to std::string::compare in C++

      Parameters:
      key - Sets the upper bound for querying.
      callback - Function to be called for each key.
      Since:
      1.0
    • getKeysBetween

      public void getKeysBetween(K key1, K key2, KeyCallback<K> callback)
      Executes callback function for every key stored in the pmemkv datastore, whose keys are greater than the key1 and less than the key2.

      Comparison mechanism is based on binary comparison of bytes - by a function equivalent to std::string::compare in C++

      Parameters:
      key1 - Sets the lower bound for querying.
      key2 - Sets the upper bound for querying.
      callback - Function to be called for each key.
      Since:
      1.0
    • countAll

      public long countAll()
      Returns number of currently stored key/value pairs in the pmemkv datastore.
      Returns:
      Total number of elements in the datastore.
      Since:
      1.0
    • countAbove

      public long countAbove(K key)
      Returns number of currently stored key/value pairs in the pmemkv datastore, whose keys are greater than the given key.

      Comparison mechanism is based on binary comparison of bytes - by a function equivalent to std::string::compare in C++

      Parameters:
      key - Sets the lower bound for querying.
      Returns:
      Number of key/value pairs in the datastore, whose keys are greater than the given key.
      Since:
      1.0
    • countBelow

      public long countBelow(K key)
      Returns number of currently stored key/value pairs in the pmemkv datastore, whose keys are less than the given key.

      Comparison mechanism is based on binary comparison of bytes - by a function equivalent to std::string::compare in C++

      Parameters:
      key - Sets the upper bound for querying.
      Returns:
      Number of key/value pairs in the datastore, whose keys are less than the given key.
      Since:
      1.0
    • countBetween

      public long countBetween(K key1, K key2)
      Returns number of currently stored key/value pairs in the pmemkv datastore, whose keys are greater than the key1 and less than the key2.

      Comparison mechanism is based on binary comparison of bytes - by a function equivalent to std::string::compare in C++

      Parameters:
      key1 - Sets the lower bound for querying.
      key2 - Sets the upper bound for querying.
      Returns:
      Number of key/value pairs in the datastore, between given keys.
      Since:
      1.0
    • getAll

      public void getAll(KeyValueCallback<K,V> callback)
      Executes callback function for every key/value pair stored in the pmemkv datastore.
      Parameters:
      callback - Function to be called for each key/value pair.
      Since:
      1.0
    • getAbove

      public void getAbove(K key, KeyValueCallback<K,V> callback)
      Executes callback function for every key/value pair stored in the pmemkv datastore, whose keys are greater than the given key.

      Comparison mechanism is based on binary comparison of bytes - by a function equivalent to std::string::compare in C++

      Parameters:
      key - Sets the lower bound for querying.
      callback - Function to be called for each specified key/value pair.
    • getBelow

      public void getBelow(K key, KeyValueCallback<K,V> callback)
      Executes callback function for every key/value pair stored in the pmemkv datastore, whose keys are less than the given key.

      Comparison mechanism is based on binary comparison of bytes - by a function equivalent to std::string::compare in C++

      Parameters:
      key - Sets the upper bound for querying.
      callback - Function to be called for each specified key/value pair.
    • getBetween

      public void getBetween(K key1, K key2, KeyValueCallback<K,V> callback)
      Executes callback function for every key/value pair stored in the pmemkv datastore, whose keys are greater than the key1 and less than the key2.

      Comparison mechanism is based on binary comparison of bytes - by a function equivalent to std::string::compare in C++

      Parameters:
      key1 - Sets the lower bound for querying.
      key2 - Sets the upper bound for querying.
      callback - Function to be called for each specified key/value pair.
    • exists

      public boolean exists(K key)
      Verifies the presence of an element with a given key in the pmemkv datastore.
      Parameters:
      key - to query for.
      Returns:
      true if key exists in the datastore, false otherwise
    • get

      public void get(K key, ValueCallback<V> callback)
      Executes a callback function on the value for a given key
      Parameters:
      key - key to query for.
      callback - Function to be called for each specified key/value pair.
    • getCopy

      public V getCopy(K key)
      Gets copy of value of a given key.
      Parameters:
      key - key to query for.
      Returns:
      Copy of value associated with the given key or null if not found
    • put

      public void put(K key, V value)
      Inserts the key/value pair into the pmemkv datastore.
      Parameters:
      key - the key
      value - data to be inserted for specified key
    • remove

      public boolean remove(K key)
      Removes key/value pair from the pmemkv datastore for given key.
      Parameters:
      key - key to query for, to be removed.
      Returns:
      true if element was removed, false if element didn't exist before removal.
    • database_start

      private long database_start(String engine, long config)
    • database_stop

      private void database_stop(long ptr)
    • database_get_keys_buffer

      private void database_get_keys_buffer(long ptr, GetKeysBuffersJNICallback cb)
    • database_get_keys_above_buffer

      private void database_get_keys_above_buffer(long ptr, int kb, ByteBuffer k, GetKeysBuffersJNICallback cb)
    • database_get_keys_below_buffer

      private void database_get_keys_below_buffer(long ptr, int kb, ByteBuffer k, GetKeysBuffersJNICallback cb)
    • database_get_keys_between_buffer

      private void database_get_keys_between_buffer(long ptr, int kb1, ByteBuffer k1, int kb2, ByteBuffer k2, GetKeysBuffersJNICallback cb)
    • database_count_all

      private long database_count_all(long ptr)
    • database_count_above_buffer

      private long database_count_above_buffer(long ptr, int kb, ByteBuffer k)
    • database_count_below_buffer

      private long database_count_below_buffer(long ptr, int kb, ByteBuffer k)
    • database_count_between_buffer

      private long database_count_between_buffer(long ptr, int kb1, ByteBuffer k1, int kb2, ByteBuffer k2)
    • database_get_all_buffer

      private void database_get_all_buffer(long ptr, GetAllBufferJNICallback cb)
    • database_get_above_buffer

      private void database_get_above_buffer(long ptr, int kb, ByteBuffer k, GetAllBufferJNICallback cb)
    • database_get_below_buffer

      private void database_get_below_buffer(long ptr, int kb, ByteBuffer k, GetAllBufferJNICallback cb)
    • database_get_between_buffer

      private void database_get_between_buffer(long ptr, int kb1, ByteBuffer k1, int kb2, ByteBuffer k2, GetAllBufferJNICallback cb)
    • database_exists_buffer

      private boolean database_exists_buffer(long ptr, int kb, ByteBuffer k)
    • database_get_buffer_with_callback

      private void database_get_buffer_with_callback(long ptr, int kb, ByteBuffer k, GetKeysBuffersJNICallback cb)
    • database_get_bytes

      private byte[] database_get_bytes(long ptr, int kb, ByteBuffer k)
    • database_put_buffer

      private void database_put_buffer(long ptr, int kb, ByteBuffer k, int vb, ByteBuffer v)
    • database_remove_buffer

      private boolean database_remove_buffer(long ptr, int kb, ByteBuffer k)