Example usage for org.apache.commons.dbcp SQLNestedException getCause

List of usage examples for org.apache.commons.dbcp SQLNestedException getCause

Introduction

In this page you can find the example usage for org.apache.commons.dbcp SQLNestedException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:org.smartfrog.services.persistence.framework.connectionpool.ConnectionPoolImpl.java

public Connection getConnection() throws SQLException {

    /**//www . j a  v a  2  s . c  om
     * If the data source is closed throw exception
     */
    if (dataSource == null) {
        throw new SQLPoolClosedException("Connection pool is closed");
    }

    /**
     * get the connection
     * Cannot create PoolableConnectionFactory 
     */
    try {

        return dataSource.getConnection();

    } catch (SQLNestedException e) {

        // TODO: get all the reasons from dbcp documentation
        Throwable cause = e.getCause();
        if (cause instanceof java.util.NoSuchElementException) {
            throw new SQLPoolTimeoutException("Timeout trying to obtain a connection from the connection pool",
                    e);
        } else {
            throw new SQLPoolAccessException("Failure trying to obtain a connection from the connection pool",
                    e);
        }

    } catch (SQLException e) {

        throw new SQLPoolAccessException("Failure trying to obtain a connection from the connection pool", e);

    }
}