Fix isConnectionAlive() check when using Connection.isValid(). Clarify logging.

pull/77/head
Brett Wooldridge 11 years ago
parent d5b91c0c21
commit 3b262816f8

@ -385,9 +385,10 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
{
timeoutMs = Math.max(1000, timeoutMs);
boolean valid;
if (isJdbc4ConnectionTest)
{
connection.isValid((int) TimeUnit.MILLISECONDS.toSeconds(timeoutMs));
valid = connection.isValid((int) TimeUnit.MILLISECONDS.toSeconds(timeoutMs));
}
else
{
@ -399,6 +400,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
statement.setQueryTimeout((int) TimeUnit.MILLISECONDS.toSeconds(timeoutMs));
}
statement.executeQuery(configuration.getConnectionTestQuery());
valid = true;
}
finally
{
@ -411,7 +413,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
connection.rollback();
}
return true;
return valid;
}
catch (SQLException e)
{
@ -450,7 +452,11 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
{
try
{
totalConnections.decrementAndGet();
int tc = totalConnections.decrementAndGet();
if (tc < 0)
{
LOGGER.warn("Internal accounting inconsistency, totalConnections=" + tc, new Exception());
}
connectionProxy.realClose();
}
catch (SQLException e)

@ -141,7 +141,7 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy
forceClose |= sqlState.startsWith("08") | SQL_ERRORS.contains(sqlState);
if (forceClose)
{
LOGGER.warn("Connection {} ({}) marked as broken because of SQLSTATE({}), ErrorCode({}): {}", delegate.toString(), parentPool.toString(), sqle.getErrorCode(), sqle.getNextException());
LOGGER.warn(String.format("Connection %s (%s) marked as broken because of SQLSTATE(%s), ErrorCode(%d).", delegate.toString(), parentPool.toString(), sqlState, sqle.getErrorCode()), sqle);
}
else if (sqle.getNextException() instanceof SQLException)
{

Loading…
Cancel
Save