Class ConnectionHelper

java.lang.Object
org.nuxeo.runtime.datasource.ConnectionHelper

public class ConnectionHelper extends Object
Helper to acquire a JDBC Connection from a datasource name.
Since:
5.7
  • Constructor Details

    • ConnectionHelper

      public ConnectionHelper()
  • Method Details

    • 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 requested
      noSharing - true if this connection must not be shared with others
      Returns:
      a new connection
      Throws:
      SQLException