Class JdbcXmlUserPreferencesStorage
- java.lang.Object
-
- org.apache.avalon.framework.logger.AbstractLogEnabled
-
- org.ametys.plugins.core.impl.userpref.JdbcXmlUserPreferencesStorage
-
- All Implemented Interfaces:
DefaultUserPreferencesStorage
,UserPreferencesStorage
,Configurable
,LogEnabled
,Serviceable
,ThreadSafe
public class JdbcXmlUserPreferencesStorage extends AbstractLogEnabled implements DefaultUserPreferencesStorage, ThreadSafe, Configurable, Serviceable
The JDBC implementation ofDefaultUserPreferencesStorage
. This implementation stores preferences in a database, as an XML file.
-
-
Field Summary
Fields Modifier and Type Field Description protected String
_databaseTable
The database table in which the preferences are stored.protected String
_dataSourceId
The id of the data source used.protected ServiceManager
_manager
Avalon service managerprivate SQLDatabaseTypeExtensionPoint
_sqlDatabaseTypeExtensionPoint
-
Fields inherited from interface org.ametys.core.userpref.DefaultUserPreferencesStorage
ROLE
-
-
Constructor Summary
Constructors Constructor Description JdbcXmlUserPreferencesStorage()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected byte[]
_getPreferencesXmlBytes(Map<String,String> preferences)
Write a Map of preferences as XML and return an InputStream on this XML.void
configure(Configuration configuration)
Map<String,String>
getUnTypedUserPrefs(UserIdentity user, String storageContext, Map<String,String> contextVars)
Get a user's preference values (as String) for a given context.Boolean
getUserPreferenceAsBoolean(UserIdentity user, String storageContext, Map<String,String> contextVars, String id)
Get a single boolean user preference value for a given context.Date
getUserPreferenceAsDate(UserIdentity user, String storageContext, Map<String,String> contextVars, String id)
Get a single date user preference value for a given context.Double
getUserPreferenceAsDouble(UserIdentity user, String storageContext, Map<String,String> contextVars, String id)
Get a single double user preference value for a given context.Long
getUserPreferenceAsLong(UserIdentity user, String storageContext, Map<String,String> contextVars, String id)
Get a single long user preference value for a given context.String
getUserPreferenceAsString(UserIdentity user, String storageContext, Map<String,String> contextVars, String id)
Get a single string user preference value for a given context.void
removeUserPreferences(UserIdentity user, String storageContext, Map<String,String> contextVars)
Remove the stored user preferences for a login in a given context.void
service(ServiceManager manager)
void
setUserPreferences(UserIdentity user, String storageContext, Map<String,String> contextVars, Map<String,String> preferences)
Set a user's preferences for a given context.-
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
-
-
-
Field Detail
-
_dataSourceId
protected String _dataSourceId
The id of the data source used.
-
_databaseTable
protected String _databaseTable
The database table in which the preferences are stored.
-
_manager
protected ServiceManager _manager
Avalon service manager
-
_sqlDatabaseTypeExtensionPoint
private SQLDatabaseTypeExtensionPoint _sqlDatabaseTypeExtensionPoint
-
-
Constructor Detail
-
JdbcXmlUserPreferencesStorage
public JdbcXmlUserPreferencesStorage()
-
-
Method Detail
-
configure
public void configure(Configuration configuration) throws ConfigurationException
- Specified by:
configure
in interfaceConfigurable
- Throws:
ConfigurationException
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
getUnTypedUserPrefs
public Map<String,String> getUnTypedUserPrefs(UserIdentity user, String storageContext, Map<String,String> contextVars) throws UserPreferencesException
Description copied from interface:UserPreferencesStorage
Get a user's preference values (as String) for a given context.- Specified by:
getUnTypedUserPrefs
in interfaceUserPreferencesStorage
- Parameters:
user
- the user.storageContext
- the preferences storage context.contextVars
- The context variables including environment elements- Returns:
- the user preference values as a Map of String indexed by preference ID.
- Throws:
UserPreferencesException
- if an error occurs getting the preferences.
-
removeUserPreferences
public void removeUserPreferences(UserIdentity user, String storageContext, Map<String,String> contextVars) throws UserPreferencesException
Description copied from interface:UserPreferencesStorage
Remove the stored user preferences for a login in a given context.- Specified by:
removeUserPreferences
in interfaceUserPreferencesStorage
- Parameters:
user
- the user.storageContext
- the preferences storage context.contextVars
- the context variables.- Throws:
UserPreferencesException
- if an error occurred
-
setUserPreferences
public void setUserPreferences(UserIdentity user, String storageContext, Map<String,String> contextVars, Map<String,String> preferences) throws UserPreferencesException
Description copied from interface:UserPreferencesStorage
Set a user's preferences for a given context.- Specified by:
setUserPreferences
in interfaceUserPreferencesStorage
- Parameters:
user
- the user.storageContext
- the preferences storage context.contextVars
- The context variables including environment elementspreferences
- a Map of the preference values indexed by ID.- Throws:
UserPreferencesException
- if an error occurred
-
getUserPreferenceAsString
public String getUserPreferenceAsString(UserIdentity user, String storageContext, Map<String,String> contextVars, String id) throws UserPreferencesException
Description copied from interface:UserPreferencesStorage
Get a single string user preference value for a given context.- Specified by:
getUserPreferenceAsString
in interfaceUserPreferencesStorage
- Parameters:
user
- the user.storageContext
- the preferences storage context.contextVars
- The context variables including environment elementsid
- the preference ID.- Returns:
- the user preference value as a String.
- Throws:
UserPreferencesException
- if an error occurred
-
getUserPreferenceAsLong
public Long getUserPreferenceAsLong(UserIdentity user, String storageContext, Map<String,String> contextVars, String id) throws UserPreferencesException
Description copied from interface:UserPreferencesStorage
Get a single long user preference value for a given context.- Specified by:
getUserPreferenceAsLong
in interfaceUserPreferencesStorage
- Parameters:
user
- the user.storageContext
- the preferences storage context.contextVars
- The context variables including environment elementsid
- the preference ID.- Returns:
- the user preference value as a Long.
- Throws:
UserPreferencesException
- if an error occurred
-
getUserPreferenceAsDate
public Date getUserPreferenceAsDate(UserIdentity user, String storageContext, Map<String,String> contextVars, String id) throws UserPreferencesException
Description copied from interface:UserPreferencesStorage
Get a single date user preference value for a given context.- Specified by:
getUserPreferenceAsDate
in interfaceUserPreferencesStorage
- Parameters:
user
- the user.storageContext
- the preferences storage context.contextVars
- The context variables including environment elementsid
- the preference ID.- Returns:
- the user preference value as a Date.
- Throws:
UserPreferencesException
- if an error occurred
-
getUserPreferenceAsBoolean
public Boolean getUserPreferenceAsBoolean(UserIdentity user, String storageContext, Map<String,String> contextVars, String id) throws UserPreferencesException
Description copied from interface:UserPreferencesStorage
Get a single boolean user preference value for a given context.- Specified by:
getUserPreferenceAsBoolean
in interfaceUserPreferencesStorage
- Parameters:
user
- the user.storageContext
- the preferences storage context.contextVars
- The context variables including environment elementsid
- the preference ID.- Returns:
- the user preference value as a Boolean.
- Throws:
UserPreferencesException
- if an error occurred
-
getUserPreferenceAsDouble
public Double getUserPreferenceAsDouble(UserIdentity user, String storageContext, Map<String,String> contextVars, String id) throws UserPreferencesException
Description copied from interface:UserPreferencesStorage
Get a single double user preference value for a given context.- Specified by:
getUserPreferenceAsDouble
in interfaceUserPreferencesStorage
- Parameters:
user
- the user.storageContext
- the preferences storage context.contextVars
- The context variables including environment elementsid
- the preference ID.- Returns:
- the user preference value as a Double.
- Throws:
UserPreferencesException
- if an error occurred
-
_getPreferencesXmlBytes
protected byte[] _getPreferencesXmlBytes(Map<String,String> preferences) throws UserPreferencesException
Write a Map of preferences as XML and return an InputStream on this XML.- Parameters:
preferences
- the preferences Map.- Returns:
- an InputStream on the preferences as XML.
- Throws:
UserPreferencesException
- if an error occurred
-
-