protected PooledConnection createConnection(long now, PooledConnection con) {\r
//no connections where available we'll create one\r
boolean error = false;\r
+ boolean inbusy = true;\r
try {\r
//connect and validate the connection\r
con = create();\r
con.lock();\r
if (!busy.offer(con)) {\r
+ inbusy = false;\r
log.debug("Connection doesn't fit into busy array, connection will not be traceable.");\r
- }\r
+ } \r
con.connect();\r
if (con.validate(PooledConnection.VALIDATE_INIT)) {\r
//no need to lock a new one, its not contented\r
con.setStackTrace(getThreadDump());\r
}\r
return con;\r
+ } else {\r
+ //validation failed, make sure we disconnect\r
+ //and clean up\r
+ error =true;\r
} //end if\r
} catch (Exception e) {\r
error = true;\r
} finally {\r
if (error ) {\r
release(con);\r
- busy.remove(con);\r
+ if (inbusy) busy.remove(con);\r
}\r
con.unlock();\r
}//catch\r
protected void connect() throws SQLException {\r
if (connection != null) {\r
try {\r
- this.disconnect();\r
+ this.disconnect(false);\r
} catch (Exception x) {\r
log.error("Unable to disconnect previous connection.", x);\r
} //catch\r
}\r
\r
protected void reconnect() throws SQLException {\r
- this.disconnect();\r
+ this.disconnect(false);\r
this.connect();\r
} //reconnect\r
\r
- protected synchronized void disconnect() throws SQLException {\r
+ protected synchronized void disconnect(boolean finalize) throws SQLException {\r
if (isDiscarded()) {\r
return;\r
}\r
connection.close();\r
}\r
connection = null;\r
- parent.finalize(this);\r
+ if (finalize) parent.finalize(this);\r
}\r
\r
\r
\r
public boolean abandon() {\r
try {\r
- disconnect();\r
+ disconnect(true);\r
} catch (SQLException x) {\r
log.error("", x);\r
} //catch\r
}\r
\r
public boolean validate(int validateAction,String sql) {\r
+ if (this.isDiscarded()) {\r
+ return false;\r
+ }\r
+ \r
if (!doValidate(validateAction)) {\r
//no validation required, no init sql and props not set\r
return true;\r
*/\r
public void release() {\r
try {\r
- disconnect();\r
+ disconnect(true);\r
} catch (SQLException x) {\r
- //TODO\r
+ if (log.isDebugEnabled()) {\r
+ log.debug("Unable to close SQL connection",x);\r
+ }\r
+ } catch (Exception x) {\r
+ if (log.isDebugEnabled()) {\r
+ log.debug("Unable to close SQL connection",x);\r
+ }\r
}\r
\r
}\r