Class KeyValNameSpace

java.lang.Object
com.kosdev.kos.commons.core.service.keyval.KeyValNameSpace

public class KeyValNameSpace extends Object
Wrapper around KeyValService that binds all accesses to a particular namespace.
Since:
1
Version:
1
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a new namespace with the specified name
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    exists(String name)
    Return true if the specified key exists.
    get(String name)
    Get the value of the specified key.
    <T> T
    get(String name, Class<T> clazz)
    Get the value of the specified key and convert the string to an instance of the specified type.
    Return all key/val pairs in this name space.
    <T> Map<String,T>
    getAll(Class<T> clazz)
    Return all key/val pairs in this name space as instance of the specified class.
    Return all keys in this name space.
    byte[]
    Get the value of the specified key as a blob.
    Return the name space name.
    void
    remove(String name)
    Remove the specified key/val.
    void
    Remove all the key/vals in this name space.
    void
    set(String name, String val)
    Set the value of the specified key.
    void
    set(String name, String val, boolean encrypted)
    Set the value of the specified key with optional encryption.
    void
    setBlob(String name, byte[] val)
    Set the value of the specified key to the specified blob.
    void
    setBlob(String ns, String name, byte[] val, boolean encrypted)
    Set the value of the specified key to the specified blob with optional encryption.
    void
    setObj(String name, Object val)
    Set the value of the specified key to the json of the specified value object.
    void
    setObj(String name, Object val, boolean encrypted)
    Set the value of the specified key to the json of the specified value object with optional encryption.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • KeyValNameSpace

      public KeyValNameSpace(KeyValService service, String ns)
      Create a new namespace with the specified name
      Parameters:
      service - the service that manages key/val storage
      ns - the name for the namespace
      Since:
      1
  • Method Details

    • set

      public void set(String name, String val, boolean encrypted)
      Set the value of the specified key with optional encryption.
      Parameters:
      name - the key name
      val - the value
      encrypted - if true, encrypt the value
      Since:
      1
    • set

      public void set(String name, String val)
      Set the value of the specified key.
      Parameters:
      name - the key name
      val - the value
      Since:
      1
    • setObj

      public void setObj(String name, Object val)
      Set the value of the specified key to the json of the specified value object.
      Parameters:
      name - the key name
      val - the object to convert to json and store
      Since:
      1
    • setObj

      public void setObj(String name, Object val, boolean encrypted)
      Set the value of the specified key to the json of the specified value object with optional encryption.
      Parameters:
      name - the key name
      val - the object to convert to json and store
      encrypted - if true, encrypt value in the database
      Since:
      1
    • setBlob

      public void setBlob(String name, byte[] val)
      Set the value of the specified key to the specified blob.
      Parameters:
      name - the key name
      val - the array of bytes to store
      Since:
      1
    • setBlob

      public void setBlob(String ns, String name, byte[] val, boolean encrypted)
      Set the value of the specified key to the specified blob with optional encryption.
      Parameters:
      name - the key name
      val - the object to convert to json and store
      encrypted - if true, encrypt the data in storage
      Since:
      1
    • exists

      public boolean exists(String name)
      Return true if the specified key exists.
      Parameters:
      name - the key name
      Since:
      1
    • get

      public String get(String name)
      Get the value of the specified key. If the value is encrypted it will automatically be decrypted.
      Parameters:
      name - the key name
      Since:
      1
    • get

      public <T> T get(String name, Class<T> clazz) throws Exception
      Get the value of the specified key and convert the string to an instance of the specified type. If the value is encrypted it will automatically be decrypted.
      Parameters:
      name - the key name
      clazz - the type to convert the value to
      Throws:
      Exception
      Since:
      1
    • getBlob

      public byte[] getBlob(String name) throws Exception
      Get the value of the specified key as a blob. This is only valid for fetching values that were stored using setBlob() .
      Parameters:
      name - the key name
      Throws:
      Exception
      Since:
      1
    • remove

      public void remove(String name)
      Remove the specified key/val.
      Parameters:
      name - the key name
      Since:
      1
    • getAllKeys

      public Set<String> getAllKeys()
      Return all keys in this name space.
      Since:
      1
    • getAll

      public Map<String,String> getAll()
      Return all key/val pairs in this name space.
      Since:
      1
    • getAll

      public <T> Map<String,T> getAll(Class<T> clazz)
      Return all key/val pairs in this name space as instance of the specified class.
      Since:
      1
    • removeAll

      public void removeAll()
      Remove all the key/vals in this name space.
      Since:
      1
    • getNameSpace

      public String getNameSpace()
      Return the name space name.
      Since:
      1