Package org.ametys.core.datasource
Class ConnectionHelper
java.lang.Object
org.ametys.core.datasource.ConnectionHelper
- All Implemented Interfaces:
Disposable
,Component
,Serviceable
Helper component used to retrieve java.sql.Connection from pools
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
ID of database extension for Derbystatic final String
ID of database extension for Hsqldbstatic final String
ID of database extension for Mysqlstatic final String
ID of database extension for Oraclestatic final String
ID of database extension for Postgresstatic final String
ID of database extension for Unknownstatic final String
The Avalon role -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
cleanup
(Connection con) Commit and closes a java.sql.Connectionstatic void
Closes a java.sql.ResultSetstatic void
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 typeReturns the SQLAbstractDataSourceManager.DataSourceDefinition
corresponding to the given id.static Connection
Get a connection to the internal sql data sourcevoid
service
(ServiceManager serviceManager)
-
Field Details
-
ROLE
The Avalon role -
DATABASE_UNKNOWN
ID of database extension for Unknown- See Also:
-
DATABASE_MYSQL
ID of database extension for Mysql- See Also:
-
DATABASE_ORACLE
ID of database extension for Oracle- See Also:
-
DATABASE_POSTGRES
ID of database extension for Postgres- See Also:
-
DATABASE_DERBY
ID of database extension for Derby- See Also:
-
DATABASE_HSQLDB
ID of database extension for Hsqldb- See Also:
-
-
Constructor Details
-
ConnectionHelper
public ConnectionHelper()
-
-
Method Details
-
service
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
dispose
- Specified by:
dispose
in interfaceDisposable
-
getInternalSQLDataSourceConnection
Get a connection to the internal sql data source- Returns:
- java.sql.Connection to query the internal SQL database
-
getConnection
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
Commit and closes a java.sql.Connection- Parameters:
con
- the Connection to close
-
cleanup
Closes a java.sql.Statement- Parameters:
stmt
- the Statement to close
-
cleanup
Closes a java.sql.ResultSet- Parameters:
rs
- the ResultSet to close
-
getDatabaseType
Determine the database type- Parameters:
connection
- The jdbc connection to the database- Returns:
- The database type id or empty string if unknown
-
getDatabaseType
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
Returns the SQLAbstractDataSourceManager.DataSourceDefinition
corresponding to the given id.- Parameters:
id
- the id of the data source- Returns:
- the
AbstractDataSourceManager.DataSourceDefinition
.
-