Commit 9e29b32e authored by Dave Cramer's avatar Dave Cramer

patch to notify listeners on error from Csaba Nagy

parent f1792b93
...@@ -13,7 +13,8 @@ import org.postgresql.PGConnection; ...@@ -13,7 +13,8 @@ import org.postgresql.PGConnection;
* @see ConnectionPool * @see ConnectionPool
* *
* @author Aaron Mulder (ammulder@chariotsolutions.com) * @author Aaron Mulder (ammulder@chariotsolutions.com)
* @version $Revision: 1.6 $ * @author Csaba Nagy (ncsaba@yahoo.com)
* @version $Revision: 1.7 $
*/ */
public class PooledConnectionImpl implements PooledConnection public class PooledConnectionImpl implements PooledConnection
{ {
...@@ -95,8 +96,16 @@ public class PooledConnectionImpl implements PooledConnection ...@@ -95,8 +96,16 @@ public class PooledConnectionImpl implements PooledConnection
{ {
if (con == null) if (con == null)
{ {
throw new SQLException("This PooledConnection has already been closed!"); // Before throwing the exception, let's notify the registered listeners about the error
final SQLException sqlException = new SQLException("This PooledConnection has already been closed!");
fireConnectionFatalError(sqlException);
throw sqlException;
} }
// If any error occures while opening a new connection, the listeners
// have to be notified. This gives a chance to connection pools to
// elliminate bad pooled connections.
try
{
// Only one connection can be open at a time from this PooledConnection. See JDBC 2.0 Optional Package spec section 6.2.3 // Only one connection can be open at a time from this PooledConnection. See JDBC 2.0 Optional Package spec section 6.2.3
if (last != null) if (last != null)
{ {
...@@ -113,6 +122,12 @@ public class PooledConnectionImpl implements PooledConnection ...@@ -113,6 +122,12 @@ public class PooledConnectionImpl implements PooledConnection
con.clearWarnings(); con.clearWarnings();
} }
con.setAutoCommit(autoCommit); con.setAutoCommit(autoCommit);
}
catch (SQLException sqlException)
{
fireConnectionFatalError(sqlException);
throw (SQLException)sqlException.fillInStackTrace();
}
ConnectionHandler handler = new ConnectionHandler(con); ConnectionHandler handler = new ConnectionHandler(con);
last = handler; last = handler;
Connection con = (Connection)Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Connection.class, PGConnection.class}, handler); Connection con = (Connection)Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Connection.class, PGConnection.class}, handler);
...@@ -121,7 +136,7 @@ public class PooledConnectionImpl implements PooledConnection ...@@ -121,7 +136,7 @@ public class PooledConnectionImpl implements PooledConnection
} }
/** /**
* Used to fire a connection event to all listeners. * Used to fire a connection closed event to all listeners.
*/ */
void fireConnectionClosed() void fireConnectionClosed()
{ {
...@@ -140,7 +155,7 @@ public class PooledConnectionImpl implements PooledConnection ...@@ -140,7 +155,7 @@ public class PooledConnectionImpl implements PooledConnection
} }
/** /**
* Used to fire a connection event to all listeners. * Used to fire a connection error event to all listeners.
*/ */
void fireConnectionFatalError(SQLException e) void fireConnectionFatalError(SQLException e)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment