1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-27 07:42:10 +03:00

Closing a Connection or Statement object twice should be a no-op

instead of throwing an Exception.

Per report from Victor Sergienko.
This commit is contained in:
Kris Jurka
2004-02-24 13:11:45 +00:00
parent 27ae96c2b6
commit 935e6e502d
5 changed files with 60 additions and 23 deletions

View File

@@ -14,7 +14,7 @@ import org.postgresql.PGConnection;
*
* @author Aaron Mulder (ammulder@chariotsolutions.com)
* @author Csaba Nagy (ncsaba@yahoo.com)
* @version $Revision: 1.7.4.2 $
* @version $Revision: 1.7.4.3 $
*/
public class PooledConnectionImpl implements PooledConnection
{
@@ -234,12 +234,17 @@ public class PooledConnectionImpl implements PooledConnection
{
return con == null ? Boolean.TRUE : Boolean.FALSE;
}
if (con == null)
if (con == null && !method.getName().equals("close"))
{
throw new SQLException(automatic ? "Connection has been closed automatically because a new connection was opened for the same PooledConnection or the PooledConnection has been closed" : "Connection has been closed");
}
if (method.getName().equals("close"))
{
// we are already closed and a double close
// is not an error.
if (con == null)
return null;
SQLException ex = null;
if (!con.getAutoCommit())
{
@@ -358,12 +363,12 @@ public class PooledConnectionImpl implements PooledConnection
return method.invoke(st, args);
}
// All the rest is from the Statement interface
if (st == null || con.isClosed())
{
throw new SQLException("Statement has been closed");
}
if (method.getName().equals("close"))
{
// closing an already closed object is a no-op
if (st == null || con.isClosed())
return null;
try {
st.close();
} finally {
@@ -372,6 +377,10 @@ public class PooledConnectionImpl implements PooledConnection
}
return null;
}
if (st == null || con.isClosed())
{
throw new SQLException("Statement has been closed");
}
else if (method.getName().equals("getConnection"))
{
return con.getProxy(); // the proxied connection, not a physical connection