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:
-
Field Summary
Fields inherited from class java.util.prefs.Preferences
MAX_KEY_LENGTH, MAX_NAME_LENGTH, MAX_VALUE_LENGTH
-
Constructor Summary
ConstructorDescriptionDbPreferences
(DbPreferences parent, DbPreferencesNode prefNode, Collection<DbPreferences> children, Collection<DbPreferencesKey> keys) Creates a preferences node. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addChild
(DbPreferences child) Adds a child node.void
void
String[]
void
clear()
boolean
protected void
exportImpl
(OutputStream os, boolean subtree) Exports a preferences node.
XmlSupport is package scope.void
void
void
flush()
protected boolean
Recursive implementation of flush.boolean
getBoolean
(String key, boolean def) byte[]
getByteArray
(String key, byte[] def) Gets the child with given relative name.Gets the child nodes.double
float
int
getKeys()
Gets the persistent keys.long
getPersistentKey
(String name) Gets the persistent key.Gets the persistent node.getRoot()
Gets the root of this node.
If this is a root, "this" will be returned.getUser()
Gets the username.int
hashCode()
boolean
Returns whether this is a root node.boolean
String[]
keys()
name()
boolean
nodeExists
(String pathName) parent()
void
void
putBoolean
(String key, boolean value) void
putByteArray
(String key, byte[] value) void
void
void
void
Adds a key.void
removeChild
(String name) Removes a child node.void
void
removePersistentKey
(String name) Removes a key.void
void
sync()
toString()
Returns the string representation of this node.boolean
Updates the persistent key.boolean
updatePersistentNode
(DbPreferencesNode prefNode) Updates the persistent node.Methods inherited from class java.util.prefs.Preferences
importPreferences, systemNodeForPackage, systemRoot, userNodeForPackage, userRoot
-
Constructor Details
-
DbPreferences
public DbPreferences(DbPreferences parent, DbPreferencesNode prefNode, Collection<DbPreferences> children, Collection<DbPreferencesKey> keys) Creates a preferences node.- Parameters:
parent
- the parent node, null if this is a root nodeprefNode
- the persistent nodechildren
- the child preferences nodeskeys
- the persistent keys
-
-
Method Details
-
hashCode
public int hashCode() -
equals
-
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 classPreferences
- Returns:
- the string
-
put
- Specified by:
put
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
put
in classPreferences
-
get
- Specified by:
get
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
get
in classPreferences
-
remove
- Specified by:
remove
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
remove
in classPreferences
-
clear
- Specified by:
clear
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
clear
in classPreferences
- Throws:
BackingStoreException
-
putInt
- Specified by:
putInt
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
putInt
in classPreferences
-
getInt
- Specified by:
getInt
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
getInt
in classPreferences
-
putLong
- Specified by:
putLong
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
putLong
in classPreferences
-
getLong
- Specified by:
getLong
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
getLong
in classPreferences
-
putBoolean
- Specified by:
putBoolean
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
putBoolean
in classPreferences
-
getBoolean
- Specified by:
getBoolean
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
getBoolean
in classPreferences
-
putFloat
- Specified by:
putFloat
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
putFloat
in classPreferences
-
getFloat
- Specified by:
getFloat
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
getFloat
in classPreferences
-
putDouble
- Specified by:
putDouble
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
putDouble
in classPreferences
-
getDouble
- Specified by:
getDouble
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
getDouble
in classPreferences
-
putByteArray
- Specified by:
putByteArray
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
putByteArray
in classPreferences
-
getByteArray
- Specified by:
getByteArray
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
getByteArray
in classPreferences
-
keys
- Specified by:
keys
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
keys
in classPreferences
- Throws:
BackingStoreException
-
childrenNames
- Specified by:
childrenNames
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
childrenNames
in classPreferences
- Throws:
BackingStoreException
-
nodeExists
- Specified by:
nodeExists
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
nodeExists
in classPreferences
- Throws:
BackingStoreException
-
removeNode
- Specified by:
removeNode
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
removeNode
in classPreferences
- Throws:
BackingStoreException
-
name
- Specified by:
name
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
name
in classPreferences
-
absolutePath
- Specified by:
absolutePath
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
absolutePath
in classPreferences
-
flush
- Specified by:
flush
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
flush
in classPreferences
- Throws:
BackingStoreException
-
sync
- Specified by:
sync
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
sync
in classPreferences
- Throws:
BackingStoreException
-
addPreferenceChangeListener
- Specified by:
addPreferenceChangeListener
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
addPreferenceChangeListener
in classPreferences
-
removePreferenceChangeListener
- Specified by:
removePreferenceChangeListener
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
removePreferenceChangeListener
in classPreferences
-
addNodeChangeListener
- Specified by:
addNodeChangeListener
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
addNodeChangeListener
in classPreferences
-
removeNodeChangeListener
- Specified by:
removeNodeChangeListener
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
removeNodeChangeListener
in classPreferences
-
exportNode
- Specified by:
exportNode
in classPreferences
- Throws:
IOException
BackingStoreException
-
exportSubtree
- Specified by:
exportSubtree
in classPreferences
- Throws:
IOException
BackingStoreException
-
parent
- Specified by:
parent
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
parent
in classPreferences
-
node
- Specified by:
node
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
node
in classPreferences
-
isUserNode
public boolean isUserNode()- Specified by:
isUserNode
in interfaceorg.tentackle.prefs.PersistedPreferences
- Specified by:
isUserNode
in classPreferences
-
getRoot
Gets the root of this node.
If this is a root, "this" will be returned.- Returns:
- the root node, never null
-
getPersistentNode
Gets the persistent node.- Returns:
- the persistent node, never null
-
updatePersistentNode
Updates the persistent node.- Parameters:
prefNode
- the persistent node- Returns:
- true if persistence status changed
-
getKeys
Gets the persistent keys.- Returns:
- the keys, never null
-
getChildren
Gets the child nodes.- Returns:
- the child nodes, never null
-
addChild
Adds a child node.- Parameters:
child
- the child node
-
removeChild
Removes a child node.- Parameters:
name
- the name relative to this node- Returns:
- the removed child, null if no such name
-
getChild
Gets the child with given relative name.- Parameters:
name
- the name relative to this node- Returns:
- the child, null if no such name
-
putPersistentKey
Adds a key.- Parameters:
key
- the key- Returns:
- the replaced key, null if key was new
-
removePersistentKey
Removes a key.- Parameters:
name
- the key name- Returns:
- the removed persistent key, null if no such key
-
getPersistentKey
Gets the persistent key.- Parameters:
name
- the name of the key- Returns:
- the persistent key, null if no such name
-
updatePersistentKey
Updates the persistent key.- Parameters:
key
- the key- Returns:
- true if persistence status changed
-
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
Exports a preferences node.
XmlSupport is package scope. Hence, we must use reflection to invoke the export method.- Parameters:
os
- the output streamsubtree
- true if whole subtree, false this node only
-
flushImpl
Recursive implementation of flush.- Parameters:
db
- the sessiontriggerListeners
- true if trigger listeners- Returns:
- true if some nodes or keys were updated from storage
-