commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sebastiaan van Erk <sebs...@sebster.com>
Subject [dbcp] Issue with DelegatingConnection's passivate method
Date Tue, 03 Dec 2002 12:35:17 GMT
Hi all,

I have run into the following issue when using DBCP. In the class 
DelegatingConnection.java there are the following two methods:

    public void close() throws SQLException
    {
        passivate();
        _conn.close();
    }

    protected void passivate() throws SQLException {
        _closed = true;
        [snip]
*       if(_conn instanceof DelegatingConnection) {
*           ((DelegatingConnection)_conn).passivate();
*       }
    }

If you have a chain of 2 or more DelegatingConnections, the code marked *
will cause the delegates to think they're closed before the close() method
is called. Thus if you inherit from DelegatingConnection and override the
close method, the _closed flag will have been set to true (and also of any
futher delegates) even though the close() method has not yet been called.
This seems like the incorrect semantics to me. For example if you have the
sequence of delegates:

   a : DelegatingConnection
   |
   +_conn : PoolableConnection (extends DelegatingConnection) (b)
    |
    +_conn : DelegatingConnection (c)
     |
     +_conn : java.sql.Connection

where PoolableConnection returns the connection to the pool in its
close() method, then calling a.close() will cause a.passivate() to be
called which will call b.passivate() which will call c.passivate()
which will set c._closed to true. When in you call pool.returnObject(this)
in b, which might try to call b.getAutoCommit() it'll complain that the
connection c is already closed.

Why are the 3 lines marked with the * necessary anyway? The very next thing
called after these lines is the _conn.close() method, which in the case of
a DelegatingConnection calls passivate() immediately anyway!

Greetings,
Sebastiaan van Erk

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message