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 private static org.slf4j.Logger
_logger
Logger for tracesprivate static ServiceManager
_manager
private static SQLDataSourceManager
_sqlDataSourceManager
The manager for SQL data sourcestatic String
DATABASE_DERBY
ID of database extension for Derbystatic String
DATABASE_HSQLDB
ID of database extension for Hsqldbstatic String
DATABASE_MYSQL
ID of database extension for Mysqlstatic String
DATABASE_ORACLE
ID of database extension for Oraclestatic String
DATABASE_POSTGRES
ID of database extension for Postgresstatic String
DATABASE_UNKNOWN
ID of database extension for Unknownstatic String
ROLE
The Avalon role
-
Constructor Summary
Constructors Constructor Description ConnectionHelper()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
cleanup(Connection con)
Commit and closes a java.sql.Connectionstatic void
cleanup(ResultSet rs)
Closes a java.sql.ResultSetstatic void
cleanup(Statement stmt)
Closes a java.sql.Statementvoid
dispose()
static Connection
getConnection(String id)
Returns a Connection from the pool.static String
getDatabaseType(String jdbcURL)
Determine the database typestatic String
getDatabaseType(Connection connection)
Determine the database typestatic AbstractDataSourceManager.DataSourceDefinition
getDataSourceDefinition(String id)
Returns the SQLAbstractDataSourceManager.DataSourceDefinition
corresponding to the given id.static Connection
getInternalSQLDataSourceConnection()
Get a connection to the internal sql data sourceprivate static SQLDataSourceManager
getSQLDataSourceManager()
void
service(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
-
_logger
private static org.slf4j.Logger _logger
Logger for traces
-
_sqlDataSourceManager
private static SQLDataSourceManager _sqlDataSourceManager
The manager for SQL data source
-
_manager
private static ServiceManager _manager
-
-
Constructor Detail
-
ConnectionHelper
public ConnectionHelper()
-
-
Method Detail
-
service
public void service(ServiceManager serviceManager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
dispose
public void dispose()
- Specified by:
dispose
in interfaceDisposable
-
getSQLDataSourceManager
private static SQLDataSourceManager getSQLDataSourceManager()
-
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.DataSourceDefinition
corresponding to the given id.- Parameters:
id
- the id of the data source- Returns:
- the
AbstractDataSourceManager.DataSourceDefinition
.
-
-