Make the addConnection() method a little more DRY

2.3.0
Brett Wooldridge 10 years ago
parent 9e16052edf
commit 2260cc2e5f

@ -360,11 +360,7 @@ public abstract class BaseHikariPool implements HikariPoolMBean, IBagStateListen
protected final boolean addConnection()
{
// Speculative increment of totalConnections with expectation of success
if (totalConnections.incrementAndGet() > configuration.getMaximumPoolSize()) {
totalConnections.decrementAndGet();
return true;
}
if (totalConnections.incrementAndGet() <= configuration.getMaximumPoolSize()) {
Connection connection = null;
try {
connection = (username == null && password == null) ? dataSource.getConnection() : dataSource.getConnection(username, password);
@ -389,15 +385,16 @@ public abstract class BaseHikariPool implements HikariPoolMBean, IBagStateListen
return true;
}
catch (Exception e) {
totalConnections.decrementAndGet(); // We failed, so undo speculative increment of totalConnections
lastConnectionFailure.set(e);
poolUtils.quietlyCloseConnection(connection);
LOGGER.debug("Connection attempt to database {} failed: {}", configuration.getPoolName(), e.getMessage(), e);
return false;
}
}
totalConnections.decrementAndGet(); // We failed or pool is max, so undo speculative increment of totalConnections
return false;
}
// ***********************************************************************
// Abstract methods
// ***********************************************************************

Loading…
Cancel
Save