Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9e29b32

Browse files
author
Dave Cramer
committed
patch to notify listeners on error from Csaba Nagy
1 parentf1792b9 commit9e29b32

File tree

1 file changed

+32
-17
lines changed

1 file changed

+32
-17
lines changed

‎src/interfaces/jdbc/org/postgresql/jdbc2/optional/PooledConnectionImpl.java

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
* @see ConnectionPool
1414
*
1515
* @author Aaron Mulder (ammulder@chariotsolutions.com)
16-
* @version $Revision: 1.6 $
16+
* @author Csaba Nagy (ncsaba@yahoo.com)
17+
* @version $Revision: 1.7 $
1718
*/
1819
publicclassPooledConnectionImplimplementsPooledConnection
1920
{
@@ -95,33 +96,47 @@ public Connection getConnection() throws SQLException
9596
{
9697
if (con ==null)
9798
{
98-
thrownewSQLException("This PooledConnection has already been closed!");
99+
// Before throwing the exception, let's notify the registered listeners about the error
100+
finalSQLExceptionsqlException =newSQLException("This PooledConnection has already been closed!");
101+
fireConnectionFatalError(sqlException);
102+
throwsqlException;
99103
}
100-
// Only one connection can be open at a time from this PooledConnection. See JDBC 2.0 Optional Package spec section 6.2.3
101-
if (last !=null)
104+
// If any error occures while opening a new connection, the listeners
105+
// have to be notified. This gives a chance to connection pools to
106+
// elliminate bad pooled connections.
107+
try
102108
{
103-
last.close();
104-
if (!con.getAutoCommit())
109+
// Only one connection can be open at a time from this PooledConnection. See JDBC 2.0 Optional Package spec section 6.2.3
110+
if (last !=null)
105111
{
106-
try
112+
last.close();
113+
if (!con.getAutoCommit())
107114
{
108-
con.rollback();
115+
try
116+
{
117+
con.rollback();
118+
}
119+
catch (SQLExceptione)
120+
{}
109121
}
110-
catch (SQLExceptione)
111-
{}
122+
con.clearWarnings();
112123
}
113-
con.clearWarnings();
124+
con.setAutoCommit(autoCommit);
125+
}
126+
catch (SQLExceptionsqlException)
127+
{
128+
fireConnectionFatalError(sqlException);
129+
throw (SQLException)sqlException.fillInStackTrace();
114130
}
115-
con.setAutoCommit(autoCommit);
116131
ConnectionHandlerhandler =newConnectionHandler(con);
117132
last =handler;
118133
Connectioncon = (Connection)Proxy.newProxyInstance(getClass().getClassLoader(),newClass[]{Connection.class,PGConnection.class},handler);
119-
last.setProxy(con);
120-
returncon;
134+
last.setProxy(con);
135+
returncon;
121136
}
122137

123138
/**
124-
* Used to fire a connection event to all listeners.
139+
* Used to fire a connectionclosedevent to all listeners.
125140
*/
126141
voidfireConnectionClosed()
127142
{
@@ -140,7 +155,7 @@ void fireConnectionClosed()
140155
}
141156

142157
/**
143-
* Used to fire a connection event to all listeners.
158+
* Used to fire a connectionerrorevent to all listeners.
144159
*/
145160
voidfireConnectionFatalError(SQLExceptione)
146161
{
@@ -363,7 +378,7 @@ else if (method.getName().equals("getConnection"))
363378
}
364379
else
365380
{
366-
try
381+
try
367382
{
368383
returnmethod.invoke(st,args);
369384
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp