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
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
Modifier and TypeFieldDescriptionstatic final String
The id of the internal DataSourcestatic final String
Name of parameter for user's passwordstatic final String
Name of parameter for database typestatic final String
Name of parameter for database urlstatic final String
Name of parameter for user's loginstatic final String
Avalon Rolestatic final String
The id of the internal DataSourceFields inherited from class org.ametys.core.datasource.AbstractDataSourceManager
_currentUserProvider, _dataSourcesDef, _observationManager, DEFAULT_DATASOURCE_SUFFIX
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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
Deletes a data sourcevoid
dispose()
void
dispose
(boolean preserveInternalDB) Disposes connections.doReadConfiguration
(File file) Actually read configuration.protected void
Edit a data source from its configurationGet the data source definition or null if not foundgetDataSourceDefinitions
(boolean includePrivate, boolean includeInternal, boolean includeDefault) Get the data source definitionsprotected String
Get the prefix for data source identifierGet the default data source for this typeGet the file configuration of data sourcesGet the datasource definition for internal databaseGet a connection object the internal data sourceGet the SQL data source by its identifierGet the existing SQL data sourcesstatic File
Get the configuration file for SQL data sourcesvoid
void
initialize
(boolean preserveInternalDB) Initializes connections.protected void
Set a default data source internallyreadDataSourceDefinition
(File file) Read the read source definitionsvoid
service
(ServiceManager serviceManager) 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 Details
-
ROLE
Avalon Role -
PARAM_DATABASE_TYPE
Name of parameter for database type- See Also:
-
PARAM_DATABASE_URL
Name of parameter for database url- See Also:
-
PARAM_DATABASE_USER
Name of parameter for user's login- See Also:
-
PARAM_DATABASE_PASSWORD
Name of parameter for user's password- See Also:
-
SQL_DATASOURCE_PREFIX
The id of the internal DataSource- See Also:
-
AMETYS_INTERNAL_DATASOURCE_ID
The id of the internal DataSource- See Also:
-
-
Constructor Details
-
SQLDataSourceManager
public SQLDataSourceManager()
-
-
Method Details
-
service
- 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
Description copied from class:AbstractDataSourceManager
Actually read configuration.- Specified by:
doReadConfiguration
in classAbstractDataSourceManager
- Parameters:
file
- the definitions file.- Returns:
- all definitions.
-
setFilename
Set the config filename. Only use for tests.- Parameters:
filename
- Name with path of the config file
-
getStaticFileConfiguration
Get the configuration file for SQL data sources- Returns:
- the configuration file
-
getFileConfiguration
Description copied from class:AbstractDataSourceManager
Get the file configuration of data sources- Specified by:
getFileConfiguration
in classAbstractDataSourceManager
- Returns:
- the file
-
initialize
Initializes connections.- Parameters:
preserveInternalDB
- also initialize internal db connection, or not.- Throws:
Exception
- if an error occurs
-
initialize
- Specified by:
initialize
in interfaceInitializable
- Overrides:
initialize
in classAbstractDataSourceManager
- Throws:
Exception
-
getDataSourceDefinition
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
Description copied from class:AbstractDataSourceManager
Get the prefix for data source identifier- Specified by:
getDataSourcePrefixId
in classAbstractDataSourceManager
- Returns:
- the id prefix
-
getInternalDataSourceDefinition
Get the datasource definition for internal database- Returns:
- The datasource definition
-
getInternalSQLDataSourceConnection
Get a connection object the internal data source- Returns:
- the connection object to Ametys' internal SQL data source
-
getSQLDataSources
Get the existing SQL data sources- Returns:
- the SQL data sources
-
getSQLDataSource
Get the SQL data source by its identifier- Parameters:
id
- The id of data source- Returns:
- the SQL data source
-
setDefaultDataSource
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
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
Description copied from class:AbstractDataSourceManager
Set a default data source internally- Specified by:
internalSetDefaultDataSource
in classAbstractDataSourceManager
-
checkParameters
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
Description copied from class:AbstractDataSourceManager
Edit a data source from its configuration- Specified by:
editDataSource
in classAbstractDataSourceManager
- Parameters:
dataSource
- the data source configuration
-
createDataSource
Description copied from class:AbstractDataSourceManager
Creates a data source from its configuration- Specified by:
createDataSource
in classAbstractDataSourceManager
- Parameters:
dataSourceDef
- the data source configuration
-
deleteDataSource
Description copied from class:AbstractDataSourceManager
Deletes a data source- Specified by:
deleteDataSource
in classAbstractDataSourceManager
- Parameters:
dataSource
- the data source configuration
-
dispose
Disposes connections.- Parameters:
preserveInternalDB
- also remove internal db connection, or not.
-
dispose
- Specified by:
dispose
in interfaceDisposable
- Overrides:
dispose
in classAbstractDataSourceManager
-