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 private static I18nizableText__AMETYS_INTERNAL_DATASOURCE_DESCRIPTIONprivate static I18nizableText__AMETYS_INTERNAL_DATASOURCE_NAMEprivate static String__filenameprivate AbstractDataSourceManager.DataSourceDefinition_internalDataSourceprivate ServiceManager_managerprivate Map<String,org.apache.commons.pool2.ObjectPool>_poolsprivate SQLDatabaseTypeExtensionPoint_sqlDatabaseTypeEPprivate Map<String,DataSource>_sqlDataSourcesstatic StringAMETYS_INTERNAL_DATASOURCE_IDThe id of the internal DataSourcestatic StringPARAM_DATABASE_PASSWORDName of parameter for user's passwordstatic StringPARAM_DATABASE_TYPEName of parameter for database typestatic StringPARAM_DATABASE_URLName of parameter for database urlstatic StringPARAM_DATABASE_USERName of parameter for user's loginstatic StringROLEAvalon Rolestatic StringSQL_DATASOURCE_PREFIXThe 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 private void_closePool(String id)private void_disposePool(String id)Dispose of a connection poolvoidcheckParameters(Map<String,Object> parameters)Checks the parameters of a data sourceprotected voidcreateDataSource(AbstractDataSourceManager.DataSourceDefinition dataSourceDef)Creates a data source from its configurationprotected voiddeleteDataSource(AbstractDataSourceManager.DataSourceDefinition dataSource)Deletes a data sourcevoiddispose()voiddispose(boolean preserveInternalDB)Disposes connections.protected Map<String,AbstractDataSourceManager.DataSourceDefinition>doReadConfiguration(File file)Actually read configuration.protected voideditDataSource(AbstractDataSourceManager.DataSourceDefinition dataSource)Edit a data source from its configurationAbstractDataSourceManager.DataSourceDefinitiongetDataSourceDefinition(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 StringgetDataSourcePrefixId()Get the prefix for data source identifierAbstractDataSourceManager.DataSourceDefinitiongetDefaultDataSourceDefinition()Get the default data source for this typeFilegetFileConfiguration()Get the file configuration of data sourcesstatic AbstractDataSourceManager.DataSourceDefinitiongetInternalDataSourceDefinition()Get the datasource definition for internal databaseConnectiongetInternalSQLDataSourceConnection()Get a connection object the internal data sourceprivate SQLDatabaseTypeExtensionPointgetSQLDatabaseTypeEP()DataSourcegetSQLDataSource(String id)Get the SQL data source by its identifierMap<String,DataSource>getSQLDataSources()Get the existing SQL data sourcesstatic FilegetStaticFileConfiguration()Get the configuration file for SQL data sourcesvoidinitialize()voidinitialize(boolean preserveInternalDB)Initializes connections.protected voidinternalSetDefaultDataSource()Set a default data source internallystatic Map<String,AbstractDataSourceManager.DataSourceDefinition>readDataSourceDefinition(File file)Read the read source definitionsvoidservice(ServiceManager serviceManager)AbstractDataSourceManager.DataSourceDefinitionsetDefaultDataSource(String id)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, 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
 
 
- 
__AMETYS_INTERNAL_DATASOURCE_NAME
private static final I18nizableText __AMETYS_INTERNAL_DATASOURCE_NAME
 
- 
__AMETYS_INTERNAL_DATASOURCE_DESCRIPTION
private static final I18nizableText __AMETYS_INTERNAL_DATASOURCE_DESCRIPTION
 
- 
__filename
private static String __filename
 
- 
_sqlDataSources
private Map<String,DataSource> _sqlDataSources
 
- 
_internalDataSource
private AbstractDataSourceManager.DataSourceDefinition _internalDataSource
 
- 
_sqlDatabaseTypeEP
private SQLDatabaseTypeExtensionPoint _sqlDatabaseTypeEP
 
- 
_manager
private ServiceManager _manager
 
 - 
 
- 
Constructor Detail
- 
SQLDataSourceManager
public SQLDataSourceManager()
 
 - 
 
- 
Method Detail
- 
service
public void service(ServiceManager serviceManager) throws ServiceException
- 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
protected Map<String,AbstractDataSourceManager.DataSourceDefinition> doReadConfiguration(File file)
Description copied from class:AbstractDataSourceManagerActually read configuration.- Specified by:
 doReadConfigurationin classAbstractDataSourceManager- Parameters:
 file- the definitions file.- Returns:
 - all definitions.
 
 
- 
getSQLDatabaseTypeEP
private SQLDatabaseTypeExtensionPoint getSQLDatabaseTypeEP()
 
- 
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:AbstractDataSourceManagerGet the file configuration of data sources- Specified by:
 getFileConfigurationin 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:
 initializein interfaceInitializable- Overrides:
 initializein classAbstractDataSourceManager- Throws:
 Exception
 
- 
getDataSourceDefinition
public AbstractDataSourceManager.DataSourceDefinition getDataSourceDefinition(String id)
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
protected String getDataSourcePrefixId()
Description copied from class:AbstractDataSourceManagerGet the prefix for data source identifier- Specified by:
 getDataSourcePrefixIdin 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: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
public AbstractDataSourceManager.DataSourceDefinition 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
protected void internalSetDefaultDataSource()
Description copied from class:AbstractDataSourceManagerSet a default data source internally- Specified by:
 internalSetDefaultDataSourcein classAbstractDataSourceManager
 
- 
checkParameters
public void checkParameters(Map<String,Object> parameters) throws ItemCheckerTestFailureException
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
protected void editDataSource(AbstractDataSourceManager.DataSourceDefinition dataSource)
Description copied from class:AbstractDataSourceManagerEdit a data source from its configuration- Specified by:
 editDataSourcein classAbstractDataSourceManager- Parameters:
 dataSource- the data source configuration
 
- 
createDataSource
protected void createDataSource(AbstractDataSourceManager.DataSourceDefinition dataSourceDef)
Description copied from class:AbstractDataSourceManagerCreates a data source from its configuration- Specified by:
 createDataSourcein classAbstractDataSourceManager- Parameters:
 dataSourceDef- the data source configuration
 
- 
deleteDataSource
protected void deleteDataSource(AbstractDataSourceManager.DataSourceDefinition dataSource)
Description copied from class:AbstractDataSourceManagerDeletes a data source- Specified by:
 deleteDataSourcein 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:
 disposein interfaceDisposable- Overrides:
 disposein classAbstractDataSourceManager
 
- 
_disposePool
private void _disposePool(String id)
Dispose of a connection pool- Parameters:
 id- the id of the connection pool to dispose of
 
- 
_closePool
private void _closePool(String id)
 
 - 
 
 -