Variable renames, and additional debug logging.

2.3.0
Brett Wooldridge 10 years ago
parent 0fe27651fb
commit 3f746b7afb

@ -365,7 +365,7 @@ public abstract class BaseHikariPool implements HikariPoolMBean, IBagStateListen
try { try {
connection = (username == null && password == null) ? dataSource.getConnection() : dataSource.getConnection(username, password); connection = (username == null && password == null) ? dataSource.getConnection() : dataSource.getConnection(username, password);
if (isUseJdbc4Validation && !poolUtils.isJdbc40Compliant(connection)) { if (isUseJdbc4Validation && !poolUtils.isJdbc4ValidationSupported(connection)) {
throw new SQLException("JDBC4 Connection.isValid() method not supported, connection test query must be configured"); throw new SQLException("JDBC4 Connection.isValid() method not supported, connection test query must be configured");
} }

@ -19,19 +19,23 @@ import com.zaxxer.hikari.HikariConfig;
public final class PoolUtilities public final class PoolUtilities
{ {
private static final Logger LOGGER = LoggerFactory.getLogger(PoolUtilities.class);
private final ThreadPoolExecutor executorService; private final ThreadPoolExecutor executorService;
private volatile boolean IS_JDBC40; private String poolName;
private volatile boolean IS_JDBC41; private volatile boolean isValidChecked;
private volatile boolean jdbc40checked; private volatile boolean isValidSupported;
private volatile boolean isNetworkTimeoutSupported;
private volatile boolean queryTimeoutSupported; private volatile boolean queryTimeoutSupported;
public PoolUtilities(final HikariConfig configuration) public PoolUtilities(final HikariConfig configuration)
{ {
this.IS_JDBC40 = true; this.poolName = configuration.getPoolName();
this.IS_JDBC41 = true; this.isValidSupported = true;
this.isNetworkTimeoutSupported = true;
this.queryTimeoutSupported = true; this.queryTimeoutSupported = true;
this.executorService = createThreadPoolExecutor(configuration.getMaximumPoolSize(), "HikariCP utility thread (pool " + configuration.getPoolName() + ")", configuration.getThreadFactory(), new ThreadPoolExecutor.DiscardPolicy()); this.executorService = createThreadPoolExecutor(configuration.getMaximumPoolSize(), "HikariCP utility thread (pool " + poolName + ")", configuration.getThreadFactory(), new ThreadPoolExecutor.DiscardPolicy());
} }
/** /**
@ -47,7 +51,7 @@ public final class PoolUtilities
connection.close(); connection.close();
} }
catch (Exception e) { catch (Exception e) {
LoggerFactory.getLogger(getClass()).debug("Exception closing connection {}", connection.toString(), e); LOGGER.debug("{} - Exception closing connection {}", poolName, connection.toString(), e);
} }
} }
} }
@ -130,20 +134,21 @@ public final class PoolUtilities
* @return true if JDBC 4.1 compliance, false otherwise * @return true if JDBC 4.1 compliance, false otherwise
* @throws SQLException re-thrown exception from Connection.getNetworkTimeout() * @throws SQLException re-thrown exception from Connection.getNetworkTimeout()
*/ */
public boolean isJdbc40Compliant(final Connection connection) public boolean isJdbc4ValidationSupported(final Connection connection)
{ {
if (!jdbc40checked) { if (!isValidChecked) {
try { try {
connection.isValid(5); // This will throw various exceptions in the case of a non-JDBC 41 compliant driver connection.isValid(5); // This will throw various exceptions in the case of a non-JDBC 4.0 compliant driver
} }
catch (Throwable e) { catch (Throwable e) {
IS_JDBC40 = false; isValidSupported = false;
LOGGER.debug("{} - JDBC4 Connection.isValid() not supported", poolName);
} }
jdbc40checked = true; isValidChecked = true;
} }
return IS_JDBC40; return isValidSupported;
} }
/** /**
@ -161,6 +166,7 @@ public final class PoolUtilities
} }
catch (Throwable e) { catch (Throwable e) {
queryTimeoutSupported = false; queryTimeoutSupported = false;
LOGGER.debug("{} - Statement.setQueryTimeout() not supported", poolName);
} }
} }
} }
@ -178,14 +184,15 @@ public final class PoolUtilities
*/ */
public int setNetworkTimeout(final Connection connection, final long timeoutMs, final boolean isUseNetworkTimeout) public int setNetworkTimeout(final Connection connection, final long timeoutMs, final boolean isUseNetworkTimeout)
{ {
if (isUseNetworkTimeout && IS_JDBC41) { if (isUseNetworkTimeout && isNetworkTimeoutSupported) {
try { try {
final int networkTimeout = connection.getNetworkTimeout(); final int networkTimeout = connection.getNetworkTimeout();
connection.setNetworkTimeout(executorService, (int) timeoutMs); connection.setNetworkTimeout(executorService, (int) timeoutMs);
return networkTimeout; return networkTimeout;
} }
catch (Throwable e) { catch (Throwable e) {
IS_JDBC41 = false; isNetworkTimeoutSupported = false;
LOGGER.debug("{} - Connection.setNetworkTimeout() not supported", poolName);
} }
} }

Loading…
Cancel
Save