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
ConstructorsConstructorDescriptionDbPreferences(DbPreferences parent, DbPreferencesNode prefNode, Collection<DbPreferences> children, Collection<DbPreferencesKey> keys) Creates a preferences node. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChild(DbPreferences child) Adds a child node.voidvoidString[]voidclear()booleanprotected voidexportImpl(OutputStream os, boolean subtree) Exports a preferences node.
XmlSupport is package scope.voidvoidvoidflush()protected booleanRecursive implementation of flush.booleangetBoolean(String key, boolean def) byte[]getByteArray(String key, byte[] def) Gets the child with given relative name.Gets the child nodes.doublefloatintgetKeys()Gets the persistent keys.longgetPersistentKey(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.inthashCode()booleanReturns whether this is a root node.booleanString[]keys()name()booleannodeExists(String pathName) parent()voidvoidputBoolean(String key, boolean value) voidputByteArray(String key, byte[] value) voidvoidvoidvoidAdds a key.voidremoveChild(String name) Removes a child node.voidvoidremovePersistentKey(String name) Removes a key.voidvoidsync()toString()Returns the string representation of this node.booleanUpdates the persistent key.booleanupdatePersistentNode(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:
toStringin classPreferences- Returns:
- the string
-
put
- Specified by:
putin interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
putin classPreferences
-
get
- Specified by:
getin interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
getin classPreferences
-
remove
- Specified by:
removein interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
removein classPreferences
-
clear
- Specified by:
clearin interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
clearin classPreferences- Throws:
BackingStoreException
-
putInt
- Specified by:
putIntin interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
putIntin classPreferences
-
getInt
- Specified by:
getIntin interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
getIntin classPreferences
-
putLong
- Specified by:
putLongin interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
putLongin classPreferences
-
getLong
- Specified by:
getLongin interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
getLongin classPreferences
-
putBoolean
- Specified by:
putBooleanin interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
putBooleanin classPreferences
-
getBoolean
- Specified by:
getBooleanin interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
getBooleanin classPreferences
-
putFloat
- Specified by:
putFloatin interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
putFloatin classPreferences
-
getFloat
- Specified by:
getFloatin interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
getFloatin classPreferences
-
putDouble
- Specified by:
putDoublein interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
putDoublein classPreferences
-
getDouble
- Specified by:
getDoublein interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
getDoublein classPreferences
-
putByteArray
- Specified by:
putByteArrayin interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
putByteArrayin classPreferences
-
getByteArray
- Specified by:
getByteArrayin interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
getByteArrayin classPreferences
-
keys
- Specified by:
keysin interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
keysin classPreferences- Throws:
BackingStoreException
-
childrenNames
- Specified by:
childrenNamesin interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
childrenNamesin classPreferences- Throws:
BackingStoreException
-
nodeExists
- Specified by:
nodeExistsin interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
nodeExistsin classPreferences- Throws:
BackingStoreException
-
removeNode
- Specified by:
removeNodein interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
removeNodein classPreferences- Throws:
BackingStoreException
-
name
- Specified by:
namein interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
namein classPreferences
-
absolutePath
- Specified by:
absolutePathin interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
absolutePathin classPreferences
-
flush
- Specified by:
flushin interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
flushin classPreferences- Throws:
BackingStoreException
-
sync
- Specified by:
syncin interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
syncin classPreferences- Throws:
BackingStoreException
-
addPreferenceChangeListener
- Specified by:
addPreferenceChangeListenerin interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
addPreferenceChangeListenerin classPreferences
-
removePreferenceChangeListener
- Specified by:
removePreferenceChangeListenerin interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
removePreferenceChangeListenerin classPreferences
-
addNodeChangeListener
- Specified by:
addNodeChangeListenerin interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
addNodeChangeListenerin classPreferences
-
removeNodeChangeListener
- Specified by:
removeNodeChangeListenerin interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
removeNodeChangeListenerin classPreferences
-
exportNode
- Specified by:
exportNodein classPreferences- Throws:
IOExceptionBackingStoreException
-
exportSubtree
- Specified by:
exportSubtreein classPreferences- Throws:
IOExceptionBackingStoreException
-
parent
- Specified by:
parentin interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
parentin classPreferences
-
node
- Specified by:
nodein interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
nodein classPreferences
-
isUserNode
public boolean isUserNode()- Specified by:
isUserNodein interfaceorg.tentackle.prefs.PersistedPreferences- Specified by:
isUserNodein 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
-