Package org.nuxeo.common.utils
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 Summary
Fields Modifier and Type Field Description static int
MAX_TRIES
Maximum number of times we retry a call if the server says it's overloaded.
-
Constructor Summary
Constructors Constructor Description JDBCUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <V> V
callWithRetry(Callable<V> callable)
Tries to do a JDBC call even when the server is overloaded.static Connection
getConnection(String url, String user, String password)
Tries to acquire aConnection
through theDriverManager
even when the server is overloaded.static Connection
getConnection(DataSource dataSource)
Tries to acquire aConnection
through aDataSource
even when the server is overloaded.static XAConnection
getXAConnection(XADataSource xaDataSource)
Tries to acquire aXAConnection
through aXADataSource
even when the server is overloaded.
-
-
-
Field Detail
-
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:
- Constant Field Values
-
-
Method Detail
-
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 aConnection
through theDriverManager
even when the server is overloaded.- Parameters:
url
- a database url of the formjdbc:subprotocol:subname
user
- the database user on whose behalf the connection is being madepassword
- the user's password- Returns:
- a connection to the URL
- Throws:
SQLException
-
getConnection
public static Connection getConnection(DataSource dataSource) throws SQLException
Tries to acquire aConnection
through aDataSource
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 aXAConnection
through aXADataSource
even when the server is overloaded.- Parameters:
xaDataSource
- the XA data source- Returns:
- a XA connection to the XA data source
- Throws:
SQLException
-
-