| 46 |
* |
* |
| 47 |
* @author Rodney Waldhoff |
* @author Rodney Waldhoff |
| 48 |
* @author Dirk Verbeeck |
* @author Dirk Verbeeck |
| 49 |
* @version $Revision: 1.12 $ $Date: 2004/05/17 18:39:44 $ |
* @version $Revision: 1.12 $ $Date$ |
| 50 |
*/ |
*/ |
| 51 |
public class PoolingDriver implements Driver { |
public class PoolingDriver implements Driver { |
| 52 |
/** Register an myself with the {@link DriverManager}. */ |
/** Register an myself with the {@link DriverManager}. */ |
| 174 |
try { |
try { |
| 175 |
Connection conn = (Connection)(pool.borrowObject()); |
Connection conn = (Connection)(pool.borrowObject()); |
| 176 |
if (conn != null) { |
if (conn != null) { |
| 177 |
conn = new PoolGuardConnectionWrapper(conn); |
conn = new PoolGuardConnectionWrapper(pool, conn); |
| 178 |
} |
} |
| 179 |
return conn; |
return conn; |
| 180 |
} catch(SQLException e) { |
} catch(SQLException e) { |
| 192 |
} |
} |
| 193 |
} |
} |
| 194 |
|
|
| 195 |
|
public void invalidateConnection(Connection conn) throws SQLException { |
| 196 |
|
if (conn instanceof PoolGuardConnectionWrapper) { // normal case |
| 197 |
|
PoolGuardConnectionWrapper pgconn = (PoolGuardConnectionWrapper) conn; |
| 198 |
|
ObjectPool pool = pgconn.pool; |
| 199 |
|
Connection delegate = pgconn.delegate; |
| 200 |
|
try { |
| 201 |
|
pool.invalidateObject(delegate); |
| 202 |
|
} |
| 203 |
|
catch (Exception e) { |
| 204 |
|
} |
| 205 |
|
pgconn.delegate = null; |
| 206 |
|
} |
| 207 |
|
else { |
| 208 |
|
throw new SQLException("Invalid connection class"); |
| 209 |
|
} |
| 210 |
|
} |
| 211 |
|
|
| 212 |
public int getMajorVersion() { |
public int getMajorVersion() { |
| 213 |
return MAJOR_VERSION; |
return MAJOR_VERSION; |
| 214 |
} |
} |
| 239 |
*/ |
*/ |
| 240 |
private class PoolGuardConnectionWrapper extends DelegatingConnection { |
private class PoolGuardConnectionWrapper extends DelegatingConnection { |
| 241 |
|
|
| 242 |
|
private ObjectPool pool; |
| 243 |
private Connection delegate; |
private Connection delegate; |
| 244 |
|
|
| 245 |
PoolGuardConnectionWrapper(Connection delegate) { |
PoolGuardConnectionWrapper(ObjectPool pool, Connection delegate) { |
| 246 |
super(delegate); |
super(delegate); |
| 247 |
|
this.pool = pool; |
| 248 |
this.delegate = delegate; |
this.delegate = delegate; |
| 249 |
} |
} |
| 250 |
|
|