Class JDBCUtils

java.lang.Object
org.nuxeo.common.utils.JDBCUtils

public class JDBCUtils extends Object
Helper for common JDBC-related operations.
Since:
7.3
  • Field Details

    • MAX_TRIES

      public static final int MAX_TRIES
      Maximum number of times we retry a call if the server says it's overloaded.
      See Also:
  • Constructor Details

    • JDBCUtils

      public JDBCUtils()
  • Method Details

    • callWithRetry

      public static <V> V callWithRetry(Callable<V> callable) throws SQLException
      Tries to do a JDBC call even when the server is overloaded.

      Oracle has problems opening and closing many connections in a short time span (ORA-12516, ORA-12519). It seems to have something to do with how closed sessions are not immediately accounted for by Oracle's PMON (process monitor). When we get these errors, we retry a few times with exponential backoff.

      Parameters:
      callable - the callable
      Returns:
      the returned value
      Throws:
      SQLException
    • getConnection

      public static Connection getConnection(String url, String user, String password) throws SQLException
      Tries to acquire a Connection through the DriverManager even when the server is overloaded.
      Parameters:
      url - a database url of the form jdbc:subprotocol:subname
      user - the database user on whose behalf the connection is being made
      password - the user's password
      Returns:
      a connection to the URL
      Throws:
      SQLException
    • getConnection

      public static Connection getConnection(DataSource dataSource) throws SQLException
      Tries to acquire a Connection through a DataSource even when the server is overloaded.
      Parameters:
      dataSource - the data source
      Returns:
      a connection to the data source
      Throws:
      SQLException
    • getXAConnection

      public static XAConnection getXAConnection(XADataSource xaDataSource) throws SQLException
      Tries to acquire a XAConnection through a XADataSource even when the server is overloaded.
      Parameters:
      xaDataSource - the XA data source
      Returns:
      a XA connection to the XA data source
      Throws:
      SQLException