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
FieldsModifier and TypeFieldDescriptionstatic final StringThe id of the internal DataSourcestatic final StringName of parameter for user's passwordstatic final StringName of parameter for database typestatic final StringName of parameter for database urlstatic final StringName of parameter for user's loginstatic final StringAvalon Rolestatic final StringThe id of the internal DataSourceFields inherited from class org.ametys.core.datasource.AbstractDataSourceManager
_currentUserProvider, _dataSourcesDef, _observationManager, DEFAULT_DATASOURCE_SUFFIX -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcheckParameters(Map<String, Object> parameters) Checks the parameters of a data sourceprotected voidcreateDataSource(AbstractDataSourceManager.DataSourceDefinition dataSourceDef) Creates a data source from its configurationprotected voidDeletes a data sourcevoiddispose()voiddispose(boolean preserveInternalDB) Disposes connections.doReadConfiguration(File file) Actually read configuration.protected voidEdit 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 StringGet 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 FileGet the configuration file for SQL data sourcesvoidvoidinitialize(boolean preserveInternalDB) Initializes connections.protected voidSet a default data source internallyreadDataSourceDefinition(File file) Read the read source definitionsvoidservice(ServiceManager serviceManager) Set the data source with the given id as the default data sourcestatic voidsetFilename(String filename) Set the config filename.Methods inherited from class org.ametys.core.datasource.AbstractDataSourceManager
add, checkDataSources, delete, edit, getDefaultDataSourceId, readConfiguration, saveConfiguration, saxDataSourceMethods 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:
servicein interfaceServiceable- Overrides:
servicein 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:AbstractDataSourceManagerActually read configuration.- Specified by:
doReadConfigurationin 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:AbstractDataSourceManagerGet the file configuration of data sources- Specified by:
getFileConfigurationin 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:
initializein interfaceInitializable- Overrides:
initializein classAbstractDataSourceManager- Throws:
Exception
-
getDataSourceDefinition
Description copied from class:AbstractDataSourceManagerGet the data source definition or null if not found- Overrides:
getDataSourceDefinitionin 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:AbstractDataSourceManagerGet the data source definitions- Overrides:
getDataSourceDefinitionsin 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:AbstractDataSourceManagerGet the prefix for data source identifier- Specified by:
getDataSourcePrefixIdin 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:AbstractDataSourceManagerSet the data source with the given id as the default data source- Overrides:
setDefaultDataSourcein classAbstractDataSourceManager- Parameters:
id- the id of the data source- Returns:
- the
AbstractDataSourceManager.DataSourceDefinitionof the data source set as default
-
getDefaultDataSourceDefinition
Description copied from class:AbstractDataSourceManagerGet the default data source for this type- Overrides:
getDefaultDataSourceDefinitionin classAbstractDataSourceManager- Returns:
- the definition object of the default data source. Can return null if no datasource is defined.
-
internalSetDefaultDataSource
Description copied from class:AbstractDataSourceManagerSet a default data source internally- Specified by:
internalSetDefaultDataSourcein classAbstractDataSourceManager
-
checkParameters
Description copied from class:AbstractDataSourceManagerChecks the parameters of a data source- Specified by:
checkParametersin classAbstractDataSourceManager- Parameters:
parameters- the parameters of the data source- Throws:
ItemCheckerTestFailureException- if the test failed
-
editDataSource
Description copied from class:AbstractDataSourceManagerEdit a data source from its configuration- Specified by:
editDataSourcein classAbstractDataSourceManager- Parameters:
dataSource- the data source configuration
-
createDataSource
Description copied from class:AbstractDataSourceManagerCreates a data source from its configuration- Specified by:
createDataSourcein classAbstractDataSourceManager- Parameters:
dataSourceDef- the data source configuration
-
deleteDataSource
Description copied from class:AbstractDataSourceManagerDeletes a data source- Specified by:
deleteDataSourcein classAbstractDataSourceManager- Parameters:
dataSource- the data source configuration
-
dispose
Disposes connections.- Parameters:
preserveInternalDB- also remove internal db connection, or not.
-
dispose
- Specified by:
disposein interfaceDisposable- Overrides:
disposein classAbstractDataSourceManager
-