Package org.nuxeo.runtime.datasource
Class ConnectionHelper
- java.lang.Object
-
- org.nuxeo.runtime.datasource.ConnectionHelper
-
public class ConnectionHelper extends Object
Helper to acquire a JDBCConnection
from a datasource name.- Since:
- 5.7
-
-
Constructor Summary
Constructors Constructor Description ConnectionHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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).
-
-
-
Method Detail
-
unwrap
public static Connection unwrap(Connection connection) throws SQLException
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
public static Connection getConnection(String dataSourceName) 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 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
-
-