Class DbPreferences

java.lang.Object
java.util.prefs.Preferences
org.tentackle.dbms.prefs.DbPreferences
All Implemented Interfaces:
Serializable, org.tentackle.prefs.PersistedPreferences

public class DbPreferences extends Preferences implements org.tentackle.prefs.PersistedPreferences, Serializable
Persisted preferences implementation.

The DbPreferences are an extension of the default Java Preferences. The main difference is, that the DbPreferences use the database as the backing store. The nodes are persisted via DbPreferencesNode while the key/value-pairs are persisted via DbPreferencesKey.

Implementation details:

  • Node- and key events are delivered to all JVMs, not only the local one.
  • Listeners are fired when the changes are flushed to the backing store and not as soon as a preference is changed or node is added/removed.
Author:
harald
See Also:
  • Constructor Details

  • Method Details

    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Returns the string representation of this node.
      • user node: "user:absolutePath"
      • system node: "<system>:absolutePath"
      • if node is removed: "(removed)" is appended
      Specified by:
      toString in class Preferences
      Returns:
      the string
    • put

      public void put(String key, String value)
      Specified by:
      put in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      put in class Preferences
    • get

      public String get(String key, String def)
      Specified by:
      get in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      get in class Preferences
    • remove

      public void remove(String key)
      Specified by:
      remove in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      remove in class Preferences
    • clear

      public void clear() throws BackingStoreException
      Specified by:
      clear in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      clear in class Preferences
      Throws:
      BackingStoreException
    • putInt

      public void putInt(String key, int value)
      Specified by:
      putInt in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      putInt in class Preferences
    • getInt

      public int getInt(String key, int def)
      Specified by:
      getInt in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      getInt in class Preferences
    • putLong

      public void putLong(String key, long value)
      Specified by:
      putLong in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      putLong in class Preferences
    • getLong

      public long getLong(String key, long def)
      Specified by:
      getLong in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      getLong in class Preferences
    • putBoolean

      public void putBoolean(String key, boolean value)
      Specified by:
      putBoolean in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      putBoolean in class Preferences
    • getBoolean

      public boolean getBoolean(String key, boolean def)
      Specified by:
      getBoolean in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      getBoolean in class Preferences
    • putFloat

      public void putFloat(String key, float value)
      Specified by:
      putFloat in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      putFloat in class Preferences
    • getFloat

      public float getFloat(String key, float def)
      Specified by:
      getFloat in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      getFloat in class Preferences
    • putDouble

      public void putDouble(String key, double value)
      Specified by:
      putDouble in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      putDouble in class Preferences
    • getDouble

      public double getDouble(String key, double def)
      Specified by:
      getDouble in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      getDouble in class Preferences
    • putByteArray

      public void putByteArray(String key, byte[] value)
      Specified by:
      putByteArray in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      putByteArray in class Preferences
    • getByteArray

      public byte[] getByteArray(String key, byte[] def)
      Specified by:
      getByteArray in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      getByteArray in class Preferences
    • keys

      public String[] keys() throws BackingStoreException
      Specified by:
      keys in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      keys in class Preferences
      Throws:
      BackingStoreException
    • childrenNames

      public String[] childrenNames() throws BackingStoreException
      Specified by:
      childrenNames in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      childrenNames in class Preferences
      Throws:
      BackingStoreException
    • nodeExists

      public boolean nodeExists(String pathName) throws BackingStoreException
      Specified by:
      nodeExists in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      nodeExists in class Preferences
      Throws:
      BackingStoreException
    • removeNode

      public void removeNode() throws BackingStoreException
      Specified by:
      removeNode in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      removeNode in class Preferences
      Throws:
      BackingStoreException
    • name

      public String name()
      Specified by:
      name in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      name in class Preferences
    • absolutePath

      public String absolutePath()
      Specified by:
      absolutePath in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      absolutePath in class Preferences
    • flush

      public void flush() throws BackingStoreException
      Specified by:
      flush in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      flush in class Preferences
      Throws:
      BackingStoreException
    • sync

      public void sync() throws BackingStoreException
      Specified by:
      sync in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      sync in class Preferences
      Throws:
      BackingStoreException
    • addPreferenceChangeListener

      public void addPreferenceChangeListener(PreferenceChangeListener pcl)
      Specified by:
      addPreferenceChangeListener in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      addPreferenceChangeListener in class Preferences
    • removePreferenceChangeListener

      public void removePreferenceChangeListener(PreferenceChangeListener pcl)
      Specified by:
      removePreferenceChangeListener in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      removePreferenceChangeListener in class Preferences
    • addNodeChangeListener

      public void addNodeChangeListener(NodeChangeListener ncl)
      Specified by:
      addNodeChangeListener in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      addNodeChangeListener in class Preferences
    • removeNodeChangeListener

      public void removeNodeChangeListener(NodeChangeListener ncl)
      Specified by:
      removeNodeChangeListener in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      removeNodeChangeListener in class Preferences
    • exportNode

      public void exportNode(OutputStream os) throws IOException, BackingStoreException
      Specified by:
      exportNode in class Preferences
      Throws:
      IOException
      BackingStoreException
    • exportSubtree

      public void exportSubtree(OutputStream os) throws IOException, BackingStoreException
      Specified by:
      exportSubtree in class Preferences
      Throws:
      IOException
      BackingStoreException
    • parent

      public DbPreferences parent()
      Specified by:
      parent in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      parent in class Preferences
    • node

      public DbPreferences node(String pathName)
      Specified by:
      node in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      node in class Preferences
    • isUserNode

      public boolean isUserNode()
      Specified by:
      isUserNode in interface org.tentackle.prefs.PersistedPreferences
      Specified by:
      isUserNode in class Preferences
    • getRoot

      public DbPreferences getRoot()
      Gets the root of this node.
      If this is a root, "this" will be returned.
      Returns:
      the root node, never null
    • getPersistentNode

      public DbPreferencesNode getPersistentNode()
      Gets the persistent node.
      Returns:
      the persistent node, never null
    • updatePersistentNode

      public boolean updatePersistentNode(DbPreferencesNode prefNode)
      Updates the persistent node.
      Parameters:
      prefNode - the persistent node
      Returns:
      true if persistence status changed
    • getKeys

      public Collection<DbPreferencesKey> getKeys()
      Gets the persistent keys.
      Returns:
      the keys, never null
    • getChildren

      public Collection<DbPreferences> getChildren()
      Gets the child nodes.
      Returns:
      the child nodes, never null
    • addChild

      public void addChild(DbPreferences child)
      Adds a child node.
      Parameters:
      child - the child node
    • removeChild

      public DbPreferences removeChild(String name)
      Removes a child node.
      Parameters:
      name - the name relative to this node
      Returns:
      the removed child, null if no such name
    • getChild

      public DbPreferences getChild(String name)
      Gets the child with given relative name.
      Parameters:
      name - the name relative to this node
      Returns:
      the child, null if no such name
    • putPersistentKey

      public DbPreferencesKey putPersistentKey(DbPreferencesKey key)
      Adds a key.
      Parameters:
      key - the key
      Returns:
      the replaced key, null if key was new
    • removePersistentKey

      public DbPreferencesKey removePersistentKey(String name)
      Removes a key.
      Parameters:
      name - the key name
      Returns:
      the removed persistent key, null if no such key
    • getPersistentKey

      public DbPreferencesKey getPersistentKey(String name)
      Gets the persistent key.
      Parameters:
      name - the name of the key
      Returns:
      the persistent key, null if no such name
    • updatePersistentKey

      public boolean updatePersistentKey(DbPreferencesKey key)
      Updates the persistent key.
      Parameters:
      key - the key
      Returns:
      true if persistence status changed
    • getUser

      public String getUser()
      Gets the username.
      Returns:
      the username, null if system user
    • isRootNode

      public boolean isRootNode()
      Returns whether this is a root node.
      Returns:
      true if root
    • exportImpl

      protected void exportImpl(OutputStream os, boolean subtree)
      Exports a preferences node.
      XmlSupport is package scope. Hence, we must use reflection to invoke the export method.
      Parameters:
      os - the output stream
      subtree - true if whole subtree, false this node only
    • flushImpl

      protected boolean flushImpl(Db db, boolean triggerListeners)
      Recursive implementation of flush.
      Parameters:
      db - the session
      triggerListeners - true if trigger listeners
      Returns:
      true if some nodes or keys were updated from storage