Class DbPreferencesFactory
- All Implemented Interfaces:
PreferencesFactory, org.tentackle.prefs.PersistedPreferencesFactory
The DbPreferencesFactory implements PersistedPreferencesFactory which in turn
extends PreferencesFactory. As such, it can be used as a drop-in
replacement for the default JRE preferences factory. By default, however, it is available
to the application only via PersistedPreferencesFactory.getInstance(), which is the
preferred way for tentackle applications to use preferences.
- Author:
- harald
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddNodeChangeListener(DbPreferences node, NodeChangeListener ncl) Adds a node listener.voidAdds a preferences changed listener.voidChecks all preferences and tries to fix if possible.
The method is provided sinceDbPreferencesNodeandDbPreferencesKeyprovide no referential integrity via database-enforced foreign keys, but only at application level.
Invoke this method, whenever the database has been modified manually via SQL.voidflush(DbPreferences node, boolean sync) Flushes a node and all of its sub-nodes to the backing store.static DbPreferencesFactoryGets the factory singleton.getRootTree(Db db, String user) Gets the root node for given user and all of its sub-nodes and keys at once.longGets the current serial version of given user- or system root.protected StringGets the current username.voidbooleanbooleanbooleanvoidkeyChanged(DbPreferences node, DbPreferencesKey key) Invoke listeners when a key is added, updated or removed.voidnodeChanged(DbPreferences node) Invoke listeners when a node is added or removed.protected StringReturns the absolute path name of the node corresponding to the package of the specified object.protected voidReleases the session after use.voidRemoves a node listener.voidRemoves a preferences changed listener.protected voidremoveRoot(DbPreferences node) Removes a root node of given node from the repository.protected DbrequestDb(boolean forUser, boolean forWrite) Requests for a session to work with.
By default, the thread-local session is used.voidsetAutoSync(boolean autoSync) voidsetReadOnly(boolean readOnly) voidsetSystemOnly(boolean systemOnly) systemNodeForPackage(Class<?> c) protected voidupdateRepository(Db db, long nodeMaxSerial, long keyMaxSerial) Updates the repository.
Invoked whenever the data in prefnode or prefkey has changed.userNodeForPackage(Class<?> c) userRoot()
-
Constructor Details
-
DbPreferencesFactory
public DbPreferencesFactory()Creates the factory.
-
-
Method Details
-
getInstance
-
invalidate
public void invalidate()- Specified by:
invalidatein interfaceorg.tentackle.prefs.PersistedPreferencesFactory
-
isAutoSync
public boolean isAutoSync()- Specified by:
isAutoSyncin interfaceorg.tentackle.prefs.PersistedPreferencesFactory
-
setAutoSync
public void setAutoSync(boolean autoSync) - Specified by:
setAutoSyncin interfaceorg.tentackle.prefs.PersistedPreferencesFactory
-
isReadOnly
public boolean isReadOnly()- Specified by:
isReadOnlyin interfaceorg.tentackle.prefs.PersistedPreferencesFactory
-
setReadOnly
public void setReadOnly(boolean readOnly) - Specified by:
setReadOnlyin interfaceorg.tentackle.prefs.PersistedPreferencesFactory
-
isSystemOnly
public boolean isSystemOnly()- Specified by:
isSystemOnlyin interfaceorg.tentackle.prefs.PersistedPreferencesFactory
-
setSystemOnly
public void setSystemOnly(boolean systemOnly) - Specified by:
setSystemOnlyin interfaceorg.tentackle.prefs.PersistedPreferencesFactory
-
getSystemRoot
- Specified by:
getSystemRootin interfaceorg.tentackle.prefs.PersistedPreferencesFactory
-
getUserRoot
- Specified by:
getUserRootin interfaceorg.tentackle.prefs.PersistedPreferencesFactory
-
userNodeForPackage
- Specified by:
userNodeForPackagein interfaceorg.tentackle.prefs.PersistedPreferencesFactory
-
systemNodeForPackage
- Specified by:
systemNodeForPackagein interfaceorg.tentackle.prefs.PersistedPreferencesFactory
-
systemRoot
- Specified by:
systemRootin interfacePreferencesFactory
-
userRoot
- Specified by:
userRootin interfacePreferencesFactory
-
getSerial
Gets the current serial version of given user- or system root.- Parameters:
user- the username, null of "" if system- Returns:
- the serial, 0 if no such root loaded
-
addPreferenceChangeListener
Adds a preferences changed listener.Notice that when a node is removed, their listeners will not be removed. So, if the node is added again, the listeners are still there. Listeners have to be removed by the application explicitly.
- Parameters:
node- the nodepcl- the listener
-
removePreferenceChangeListener
Removes a preferences changed listener.- Parameters:
node- the nodepcl- the listener
-
addNodeChangeListener
Adds a node listener.Notice that when a node is removed, their listeners will not be removed. So, if the node is added again, the listeners are still there. Listeners have to be removed by the application explicitly.
- Parameters:
node- the nodencl- the listener
-
removeNodeChangeListener
Removes a node listener.- Parameters:
node- the nodencl- the listener
-
nodeChanged
Invoke listeners when a node is added or removed.- Parameters:
node- the added or removed node
-
keyChanged
Invoke listeners when a key is added, updated or removed.- Parameters:
node- the node holding the keykey- the changed key
-
flush
Flushes a node and all of its sub-nodes to the backing store.- Parameters:
node- the preferences nodesync- true if load modifications from storage before flush- Throws:
BackingStoreException- if failed
-
getRootTree
Gets the root node for given user and all of its sub-nodes and keys at once.- Parameters:
db- the optional db, null if request a db temporarilyuser- the username, null or empty if system user- Returns:
- the root node, never null
-
checkAllPreferences
Checks all preferences and tries to fix if possible.
The method is provided sinceDbPreferencesNodeandDbPreferencesKeyprovide no referential integrity via database-enforced foreign keys, but only at application level.
Invoke this method, whenever the database has been modified manually via SQL.- Parameters:
db- the session (must be local)
-
nodeName
Returns the absolute path name of the node corresponding to the package of the specified object.- Parameters:
clazz- the class- Returns:
- the path name
- Throws:
IllegalArgumentException- if the package has no preferences node associated with it
-
removeRoot
Removes a root node of given node from the repository.- Parameters:
node- the root node or one of its sub-nodes
-
updateRepository
Updates the repository.
Invoked whenever the data in prefnode or prefkey has changed.- Parameters:
db- the sessionnodeMaxSerial- the new table serial for prefnodeskeyMaxSerial- the new table serial for prefkeys
-
requestDb
Requests for a session to work with.
By default, the thread-local session is used. If there is no default session, the modification tracker's session is used.In preparation for replication layers, a requested session must be released after use.
- Parameters:
forUser- true if a user session is required (no modification tracker fallback)forWrite- true if the session is used for writing (flush), else read- Returns:
- the session
-
releaseDb
-
getUserName
-