Package org.nuxeo.runtime.datasource
Class ConnectionHelper
java.lang.Object
org.nuxeo.runtime.datasource.ConnectionHelper
Helper to acquire a JDBC
Connection
from a datasource name.- Since:
- 5.7
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Connection
getConnection
(String dataSourceName) Gets a new connection for the given dataSource.static Connection
getConnection
(String dataSourceName, boolean noSharing) Gets a new connection for the given dataSource.static Connection
unwrap
(Connection connection) Tries to unwrap the connection to get the real physical one (returned by the original datasource).
-
Constructor Details
-
ConnectionHelper
public ConnectionHelper()
-
-
Method Details
-
unwrap
Tries to unwrap the connection to get the real physical one (returned by the original datasource).This should only be used by code that needs to cast the connection to a driver-specific class to use driver-specific features.
- Throws:
SQLException
- if no actual physical connection was allocated yet
-
getConnection
Gets a new connection for the given dataSource. The connection MUST be closed in a finally block when code is done using it.- Parameters:
dataSourceName
- the datasource for which the connection is requested- Returns:
- a new connection
- Throws:
SQLException
-
getConnection
public static Connection getConnection(String dataSourceName, boolean noSharing) throws SQLException Gets a new connection for the given dataSource. The connection MUST be closed in a finally block when code is done using it.- Parameters:
dataSourceName
- the datasource for which the connection is requestednoSharing
-true
if this connection must not be shared with others- Returns:
- a new connection
- Throws:
SQLException
-