protected PooledConnectionAndInfo
getPooledConnectionAndInfo(String username, String password)
throws SQLException {
final PoolKey key = getPoolKey(username,password);
ObjectPool pool;
PooledConnectionManager manager;
synchronized(this) {
manager = (PooledConnectionManager) managers.get(key);
if (manager == null) {
try {
registerPool(username, password);
manager = (PooledConnectionManager) managers.get(key);
} catch (NamingException e) {
throw new SQLNestedException("RegisterPool failed", e);
}
}
pool = ((CPDSConnectionFactory) manager).getPool();
}
PooledConnectionAndInfo info = null;
try {
info = (PooledConnectionAndInfo) pool.borrowObject();
}
catch (NoSuchElementException ex) {
throw new SQLNestedException(
"Could not retrieve connection info from pool", ex);
}
catch (Exception e) {
// See if failure is due to CPDSConnectionFactory authentication failure
try {
testCPDS(username, password);
} catch (Exception ex) {
throw (SQLException) new SQLException(
"Could not retrieve connection info from pool").initCause(ex);
}
// New password works, so kill the old pool, create a new one, and borrow
manager.closePool(username);
synchronized (this) {
managers.remove(key);
}
try {
registerPool(username, password);
pool = getPool(key);
} catch (NamingException ne) {
throw new SQLNestedException("RegisterPool failed", ne);
}
try {
info = (PooledConnectionAndInfo)pool.borrowObject();
} catch (Exception ex) {
throw (SQLException) new SQLException(
"Could not retrieve connection info from pool").initCause(ex);
}
}