Example usage for org.apache.commons.dbcp2 Utils DISCONNECTION_SQL_CODES

List of usage examples for org.apache.commons.dbcp2 Utils DISCONNECTION_SQL_CODES

Introduction

In this page you can find the example usage for org.apache.commons.dbcp2 Utils DISCONNECTION_SQL_CODES.

Prototype

Set DISCONNECTION_SQL_CODES

To view the source code for org.apache.commons.dbcp2 Utils DISCONNECTION_SQL_CODES.

Click Source Link

Document

SQL codes of fatal connection errors.

Usage

From source file:JDBCPool.dbcp.demo.sourcecode.PoolableConnection.java

/**
 * Checks the SQLState of the input exception and any nested SQLExceptions it wraps.
 * <p>/*from  www .  ja  v a2s  .c o  m*/
 * If {@link #getDisconnectSqlCodes() disconnectSQLCodes} has been set, sql states
 * are compared to those in the configured list of fatal exception codes.  If this
 * property is not set, codes are compared against the default codes in
 * #{@link Utils.DISCONNECTION_SQL_CODES} and in this case anything starting with
 * #{link Utils.DISCONNECTION_SQL_CODE_PREFIX} is considered a disconnection.</p>
 *
 * @param e SQLException to be examined
 * @return true if the exception signals a disconnection
 */
private boolean isDisconnectionSqlException(SQLException e) {
    boolean fatalException = false;
    String sqlState = e.getSQLState();
    if (sqlState != null) {
        fatalException = _disconnectionSqlCodes == null
                ? sqlState.startsWith(Utils.DISCONNECTION_SQL_CODE_PREFIX)
                        || Utils.DISCONNECTION_SQL_CODES.contains(sqlState)
                : _disconnectionSqlCodes.contains(sqlState);
        if (!fatalException) {
            if (e.getNextException() != null) {
                fatalException = isDisconnectionSqlException(e.getNextException());
            }
        }
    }
    return fatalException;
}