Package org.ametys.core.datasource
Class SQLDataSourceManager
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.core.datasource.AbstractDataSourceManager
-
- org.ametys.core.datasource.SQLDataSourceManager
-
- All Implemented Interfaces:
LogEnabled
,Disposable
,Initializable
,Component
,Serviceable
public class SQLDataSourceManager extends AbstractDataSourceManager
This component handles SQL data sources. It is associated with the configuration file $AMETYS_HOME/config/datasources-sql.xml
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.ametys.core.datasource.AbstractDataSourceManager
AbstractDataSourceManager.DataSourceDefinition
-
-
Field Summary
Fields Modifier and Type Field Description static String
AMETYS_INTERNAL_DATASOURCE_ID
The id of the internal DataSourcestatic String
PARAM_DATABASE_PASSWORD
Name of parameter for user's passwordstatic String
PARAM_DATABASE_TYPE
Name of parameter for database typestatic String
PARAM_DATABASE_URL
Name of parameter for database urlstatic String
PARAM_DATABASE_USER
Name of parameter for user's loginstatic String
ROLE
Avalon Rolestatic String
SQL_DATASOURCE_PREFIX
The id of the internal DataSource-
Fields inherited from class org.ametys.core.datasource.AbstractDataSourceManager
_currentUserProvider, _dataSourcesDef, _observationManager, DEFAULT_DATASOURCE_SUFFIX
-
-
Constructor Summary
Constructors Constructor Description SQLDataSourceManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkParameters(Map<String,Object> parameters)
Checks the parameters of a data sourceprotected void
createDataSource(AbstractDataSourceManager.DataSourceDefinition dataSourceDef)
Creates a data source from its configurationprotected void
deleteDataSource(AbstractDataSourceManager.DataSourceDefinition dataSource)
Deletes a data sourcevoid
dispose()
void
dispose(boolean preserveInternalDB)
Disposes connections.protected Map<String,AbstractDataSourceManager.DataSourceDefinition>
doReadConfiguration(File file)
Actually read configuration.protected void
editDataSource(AbstractDataSourceManager.DataSourceDefinition dataSource)
Edit a data source from its configurationAbstractDataSourceManager.DataSourceDefinition
getDataSourceDefinition(String id)
Get the data source definition or null if not foundMap<String,AbstractDataSourceManager.DataSourceDefinition>
getDataSourceDefinitions(boolean includePrivate, boolean includeInternal, boolean includeDefault)
Get the data source definitionsprotected String
getDataSourcePrefixId()
Get the prefix for data source identifierAbstractDataSourceManager.DataSourceDefinition
getDefaultDataSourceDefinition()
Get the default data source for this typeFile
getFileConfiguration()
Get the file configuration of data sourcesstatic AbstractDataSourceManager.DataSourceDefinition
getInternalDataSourceDefinition()
Get the datasource definition for internal databaseConnection
getInternalSQLDataSourceConnection()
Get a connection object the internal data sourceDataSource
getSQLDataSource(String id)
Get the SQL data source by its identifierMap<String,DataSource>
getSQLDataSources()
Get the existing SQL data sourcesstatic File
getStaticFileConfiguration()
Get the configuration file for SQL data sourcesvoid
initialize()
void
initialize(boolean preserveInternalDB)
Initializes connections.protected void
internalSetDefaultDataSource()
Set a default data source internallystatic Map<String,AbstractDataSourceManager.DataSourceDefinition>
readDataSourceDefinition(File file)
Read the read source definitionsvoid
service(ServiceManager serviceManager)
AbstractDataSourceManager.DataSourceDefinition
setDefaultDataSource(String id)
Set the data source with the given id as the default data sourcestatic void
setFilename(String filename)
Set the config filename.-
Methods inherited from class org.ametys.core.datasource.AbstractDataSourceManager
add, checkDataSources, delete, edit, getDefaultDataSourceId, readConfiguration, saveConfiguration, saxDataSource
-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
PARAM_DATABASE_TYPE
public static final String PARAM_DATABASE_TYPE
Name of parameter for database type- See Also:
- Constant Field Values
-
PARAM_DATABASE_URL
public static final String PARAM_DATABASE_URL
Name of parameter for database url- See Also:
- Constant Field Values
-
PARAM_DATABASE_USER
public static final String PARAM_DATABASE_USER
Name of parameter for user's login- See Also:
- Constant Field Values
-
PARAM_DATABASE_PASSWORD
public static final String PARAM_DATABASE_PASSWORD
Name of parameter for user's password- See Also:
- Constant Field Values
-
SQL_DATASOURCE_PREFIX
public static final String SQL_DATASOURCE_PREFIX
The id of the internal DataSource- See Also:
- Constant Field Values
-
AMETYS_INTERNAL_DATASOURCE_ID
public static final String AMETYS_INTERNAL_DATASOURCE_ID
The id of the internal DataSource- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SQLDataSourceManager
public SQLDataSourceManager()
-
-
Method Detail
-
service
public void service(ServiceManager serviceManager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Overrides:
service
in classAbstractDataSourceManager
- Throws:
ServiceException
-
readDataSourceDefinition
public static Map<String,AbstractDataSourceManager.DataSourceDefinition> readDataSourceDefinition(File file)
Read the read source definitions- Parameters:
file
- The configuration file- Returns:
- the data source definitions
-
doReadConfiguration
protected Map<String,AbstractDataSourceManager.DataSourceDefinition> doReadConfiguration(File file)
Description copied from class:AbstractDataSourceManager
Actually read configuration.- Specified by:
doReadConfiguration
in classAbstractDataSourceManager
- Parameters:
file
- the definitions file.- Returns:
- all definitions.
-
setFilename
public static void setFilename(String filename)
Set the config filename. Only use for tests.- Parameters:
filename
- Name with path of the config file
-
getStaticFileConfiguration
public static File getStaticFileConfiguration()
Get the configuration file for SQL data sources- Returns:
- the configuration file
-
getFileConfiguration
public File getFileConfiguration()
Description copied from class:AbstractDataSourceManager
Get the file configuration of data sources- Specified by:
getFileConfiguration
in classAbstractDataSourceManager
- Returns:
- the file
-
initialize
public void initialize(boolean preserveInternalDB) throws Exception
Initializes connections.- Parameters:
preserveInternalDB
- also initialize internal db connection, or not.- Throws:
Exception
- if an error occurs
-
initialize
public void initialize() throws Exception
- Specified by:
initialize
in interfaceInitializable
- Overrides:
initialize
in classAbstractDataSourceManager
- Throws:
Exception
-
getDataSourceDefinition
public AbstractDataSourceManager.DataSourceDefinition getDataSourceDefinition(String id)
Description copied from class:AbstractDataSourceManager
Get the data source definition or null if not found- Overrides:
getDataSourceDefinition
in classAbstractDataSourceManager
- Parameters:
id
- the id of data source- Returns:
- the data source definition or null if not found
-
getDataSourceDefinitions
public Map<String,AbstractDataSourceManager.DataSourceDefinition> getDataSourceDefinitions(boolean includePrivate, boolean includeInternal, boolean includeDefault)
Description copied from class:AbstractDataSourceManager
Get the data source definitions- Overrides:
getDataSourceDefinitions
in classAbstractDataSourceManager
- Parameters:
includePrivate
- true to include private data sourcesincludeInternal
- true to include internal data sources. Not used by default.includeDefault
- true to include an additional data source definition for each default data source- Returns:
- the data source definitions
-
getDataSourcePrefixId
protected String getDataSourcePrefixId()
Description copied from class:AbstractDataSourceManager
Get the prefix for data source identifier- Specified by:
getDataSourcePrefixId
in classAbstractDataSourceManager
- Returns:
- the id prefix
-
getInternalDataSourceDefinition
public static AbstractDataSourceManager.DataSourceDefinition getInternalDataSourceDefinition()
Get the datasource definition for internal database- Returns:
- The datasource definition
-
getInternalSQLDataSourceConnection
public Connection getInternalSQLDataSourceConnection()
Get a connection object the internal data source- Returns:
- the connection object to Ametys' internal SQL data source
-
getSQLDataSources
public Map<String,DataSource> getSQLDataSources()
Get the existing SQL data sources- Returns:
- the SQL data sources
-
getSQLDataSource
public DataSource getSQLDataSource(String id)
Get the SQL data source by its identifier- Parameters:
id
- The id of data source- Returns:
- the SQL data source
-
setDefaultDataSource
public AbstractDataSourceManager.DataSourceDefinition setDefaultDataSource(String id)
Description copied from class:AbstractDataSourceManager
Set the data source with the given id as the default data source- Overrides:
setDefaultDataSource
in classAbstractDataSourceManager
- Parameters:
id
- the id of the data source- Returns:
- the
AbstractDataSourceManager.DataSourceDefinition
of the data source set as default
-
getDefaultDataSourceDefinition
public AbstractDataSourceManager.DataSourceDefinition getDefaultDataSourceDefinition()
Description copied from class:AbstractDataSourceManager
Get the default data source for this type- Overrides:
getDefaultDataSourceDefinition
in classAbstractDataSourceManager
- Returns:
- the definition object of the default data source. Can return null if no datasource is defined.
-
internalSetDefaultDataSource
protected void internalSetDefaultDataSource()
Description copied from class:AbstractDataSourceManager
Set a default data source internally- Specified by:
internalSetDefaultDataSource
in classAbstractDataSourceManager
-
checkParameters
public void checkParameters(Map<String,Object> parameters) throws ItemCheckerTestFailureException
Description copied from class:AbstractDataSourceManager
Checks the parameters of a data source- Specified by:
checkParameters
in classAbstractDataSourceManager
- Parameters:
parameters
- the parameters of the data source- Throws:
ItemCheckerTestFailureException
- if the test failed
-
editDataSource
protected void editDataSource(AbstractDataSourceManager.DataSourceDefinition dataSource)
Description copied from class:AbstractDataSourceManager
Edit a data source from its configuration- Specified by:
editDataSource
in classAbstractDataSourceManager
- Parameters:
dataSource
- the data source configuration
-
createDataSource
protected void createDataSource(AbstractDataSourceManager.DataSourceDefinition dataSourceDef)
Description copied from class:AbstractDataSourceManager
Creates a data source from its configuration- Specified by:
createDataSource
in classAbstractDataSourceManager
- Parameters:
dataSourceDef
- the data source configuration
-
deleteDataSource
protected void deleteDataSource(AbstractDataSourceManager.DataSourceDefinition dataSource)
Description copied from class:AbstractDataSourceManager
Deletes a data source- Specified by:
deleteDataSource
in classAbstractDataSourceManager
- Parameters:
dataSource
- the data source configuration
-
dispose
public void dispose(boolean preserveInternalDB)
Disposes connections.- Parameters:
preserveInternalDB
- also remove internal db connection, or not.
-
dispose
public void dispose()
- Specified by:
dispose
in interfaceDisposable
- Overrides:
dispose
in classAbstractDataSourceManager
-
-