Package org.ametys.core.datasource
Class ConnectionHelper
- java.lang.Object
-
- org.ametys.core.datasource.ConnectionHelper
-
- All Implemented Interfaces:
Disposable,Component,Serviceable
public final class ConnectionHelper extends Object implements Component, Serviceable, Disposable
Helper component used to retrieve java.sql.Connection from pools
-
-
Field Summary
Fields Modifier and Type Field Description static StringDATABASE_DERBYID of database extension for Derbystatic StringDATABASE_HSQLDBID of database extension for Hsqldbstatic StringDATABASE_MYSQLID of database extension for Mysqlstatic StringDATABASE_ORACLEID of database extension for Oraclestatic StringDATABASE_POSTGRESID of database extension for Postgresstatic StringDATABASE_UNKNOWNID of database extension for Unknownstatic StringROLEThe Avalon role
-
Constructor Summary
Constructors Constructor Description ConnectionHelper()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidcleanup(Connection con)Commit and closes a java.sql.Connectionstatic voidcleanup(ResultSet rs)Closes a java.sql.ResultSetstatic voidcleanup(Statement stmt)Closes a java.sql.Statementvoiddispose()static ConnectiongetConnection(String id)Returns a Connection from the pool.static StringgetDatabaseType(String jdbcURL)Determine the database typestatic StringgetDatabaseType(Connection connection)Determine the database typestatic AbstractDataSourceManager.DataSourceDefinitiongetDataSourceDefinition(String id)Returns the SQLAbstractDataSourceManager.DataSourceDefinitioncorresponding to the given id.static ConnectiongetInternalSQLDataSourceConnection()Get a connection to the internal sql data sourcevoidservice(ServiceManager serviceManager)
-
-
-
Field Detail
-
DATABASE_UNKNOWN
public static final String DATABASE_UNKNOWN
ID of database extension for Unknown- See Also:
- Constant Field Values
-
DATABASE_MYSQL
public static final String DATABASE_MYSQL
ID of database extension for Mysql- See Also:
- Constant Field Values
-
DATABASE_ORACLE
public static final String DATABASE_ORACLE
ID of database extension for Oracle- See Also:
- Constant Field Values
-
DATABASE_POSTGRES
public static final String DATABASE_POSTGRES
ID of database extension for Postgres- See Also:
- Constant Field Values
-
DATABASE_DERBY
public static final String DATABASE_DERBY
ID of database extension for Derby- See Also:
- Constant Field Values
-
DATABASE_HSQLDB
public static final String DATABASE_HSQLDB
ID of database extension for Hsqldb- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ConnectionHelper
public ConnectionHelper()
-
-
Method Detail
-
service
public void service(ServiceManager serviceManager) throws ServiceException
- Specified by:
servicein interfaceServiceable- Throws:
ServiceException
-
dispose
public void dispose()
- Specified by:
disposein interfaceDisposable
-
getInternalSQLDataSourceConnection
public static Connection getInternalSQLDataSourceConnection()
Get a connection to the internal sql data source- Returns:
- java.sql.Connection to query the internal SQL database
-
getConnection
public static Connection getConnection(String id)
Returns a Connection from the pool.- Parameters:
id- the id of the data source- Returns:
- a java.sql.Connection to query a SQL database
-
cleanup
public static void cleanup(Connection con)
Commit and closes a java.sql.Connection- Parameters:
con- the Connection to close
-
cleanup
public static void cleanup(Statement stmt)
Closes a java.sql.Statement- Parameters:
stmt- the Statement to close
-
cleanup
public static void cleanup(ResultSet rs)
Closes a java.sql.ResultSet- Parameters:
rs- the ResultSet to close
-
getDatabaseType
public static String getDatabaseType(Connection connection)
Determine the database type- Parameters:
connection- The jdbc connection to the database- Returns:
- The database type id or empty string if unknown
-
getDatabaseType
public static String getDatabaseType(String jdbcURL)
Determine the database type- Parameters:
jdbcURL- The jdbc url used to connect to the database- Returns:
- The database type id or null if unknown
-
getDataSourceDefinition
public static AbstractDataSourceManager.DataSourceDefinition getDataSourceDefinition(String id)
Returns the SQLAbstractDataSourceManager.DataSourceDefinitioncorresponding to the given id.- Parameters:
id- the id of the data source- Returns:
- the
AbstractDataSourceManager.DataSourceDefinition.
-
-