commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kasper Sørensen (JIRA) <j...@apache.org>
Subject [jira] [Commented] (DBCP-426) DBCP should allow clients to mark connections as invalid
Date Mon, 29 Sep 2014 21:01:34 GMT

    [ https://issues.apache.org/jira/browse/DBCP-426?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14152285#comment-14152285
] 

Kasper Sørensen commented on DBCP-426:
--------------------------------------

Here's my suggested patch (to be added in BasicDataSource):

{code}
    /**
     * Manually invalidates a connection, effectively requesting the pool to try
     * to close it, remove it from the pool and reclaim pool capacity.
     * 
     * @throws IllegalStateException
     *             if invalidating the connection failed.
     */
    public void invalidateConnection(Connection connection) throws IllegalStateException {
        if (connection == null) {
            return;
        }
        if (connectionPool == null) {
            throw new IllegalStateException("Cannot invalidate connection: ConnectionPool
is null.");
        }

        final PoolableConnection poolableConnection;
        try {
            poolableConnection = connection.unwrap(PoolableConnection.class);
            if (poolableConnection == null) {
                throw new IllegalStateException(
                        "Cannot invalidate connection: Connection is not a poolable connection.");
            }
        } catch (SQLException e) {
            throw new IllegalStateException("Cannot invalidate connection: Unwrapping poolable
connection failed.", e);
        }

        // attempt to close the connection for good measure
        try {
            connection.close();
        } catch (Exception e) {
            // ignore any exceptions here
        }

        try {
            connectionPool.invalidateObject(poolableConnection);
        } catch (Exception e) {
            throw new IllegalStateException("Invalidating connection threw unexpected exception",
e);
        }
    }
{code}

> DBCP should allow clients to mark connections as invalid
> --------------------------------------------------------
>
>                 Key: DBCP-426
>                 URL: https://issues.apache.org/jira/browse/DBCP-426
>             Project: Commons Dbcp
>          Issue Type: Bug
>    Affects Versions: 2.0
>            Reporter: Phil Steitz
>
> Currently there is no way for a DBCP client to mark a connection as invalid, effectively
requesting the pool to try to close it, remove it from the pool and reclaim pool capacity.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message