From 7027f23ead0df7e69c704f663b21b3a98c80db07 Mon Sep 17 00:00:00 2001 From: Nitin Date: Wed, 18 Nov 2015 17:31:49 +0530 Subject: [PATCH] clear/simplified validation in sync with initializeDataSource() and DriverDataSource() --- .../java/com/zaxxer/hikari/HikariConfig.java | 28 ++++++++----------- .../zaxxer/hikari/util/DriverDataSource.java | 6 ++-- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/zaxxer/hikari/HikariConfig.java b/src/main/java/com/zaxxer/hikari/HikariConfig.java index 9d19e503..b6fa46bc 100644 --- a/src/main/java/com/zaxxer/hikari/HikariConfig.java +++ b/src/main/java/com/zaxxer/hikari/HikariConfig.java @@ -229,7 +229,7 @@ public class HikariConfig implements HikariConfigMXBean this.connectionTimeout = connectionTimeoutMs; } - if (validationTimeout > connectionTimeoutMs && connectionTimeoutMs > 0) { + if (validationTimeout > connectionTimeoutMs) { this.validationTimeout = connectionTimeoutMs; } } @@ -766,26 +766,18 @@ public class HikariConfig implements HikariConfigMXBean throw new IllegalArgumentException("poolName cannot contain ':' when used with JMX"); } - if (driverClassName != null && jdbcUrl == null) { - LOGGER.error("jdbcUrl is required with driverClassName"); - throw new IllegalArgumentException("jdbcUrl is required with driverClassName"); + if (dataSource != null) { + LOGGER.debug("{} - using dataSource={}", poolName, dataSource); } - else if (driverClassName != null && dataSourceClassName != null) { - LOGGER.error("cannot use driverClassName and dataSourceClassName together"); - throw new IllegalArgumentException("cannot use driverClassName and dataSourceClassName together"); - } - else if (jdbcUrl != null && dataSourceClassName != null) { - LOGGER.warn("using dataSourceClassName and ignoring jdbcUrl"); + else if (dataSourceClassName != null) { + LOGGER.debug("{} - using dataSourceClassName={}", poolName, dataSourceClassName); } else if (jdbcUrl != null) { - // OK - } - else if (dataSource == null && dataSourceClassName == null) { - LOGGER.error("either dataSource or dataSourceClassName is required"); - throw new IllegalArgumentException("either dataSource or dataSourceClassName is required"); + LOGGER.debug("{} - using url={}, driverClassName={}", poolName, jdbcUrl, driverClassName); } - else if (dataSource != null && dataSourceClassName != null) { - LOGGER.warn("using dataSource and ignoring dataSourceClassName"); + else { + LOGGER.error("{} - dataSource or dataSourceClassName or jdbcUrl is required.", poolName); + throw new IllegalArgumentException("dataSource or dataSourceClassName or jdbcUrl is required."); } if (LOGGER.isDebugEnabled() || unitTest) { @@ -819,11 +811,13 @@ public class HikariConfig implements HikariConfigMXBean LOGGER.warn("idleTimeout is less than 10000ms, setting to default {}ms.", IDLE_TIMEOUT); idleTimeout = IDLE_TIMEOUT; } + if (idleTimeout + TimeUnit.SECONDS.toMillis(1) > maxLifetime && maxLifetime > 0) { LOGGER.warn("idleTimeout is close to or greater than maxLifetime, disabling it."); maxLifetime = idleTimeout; idleTimeout = 0; } + if (maxLifetime == 0 && idleTimeout == 0) { LOGGER.warn("setting idleTimeout to {}ms.", IDLE_TIMEOUT); idleTimeout = IDLE_TIMEOUT; diff --git a/src/main/java/com/zaxxer/hikari/util/DriverDataSource.java b/src/main/java/com/zaxxer/hikari/util/DriverDataSource.java index 962913c2..9aa9b6bf 100644 --- a/src/main/java/com/zaxxer/hikari/util/DriverDataSource.java +++ b/src/main/java/com/zaxxer/hikari/util/DriverDataSource.java @@ -71,7 +71,7 @@ public final class DriverDataSource implements DataSource driver = (Driver) driverClass.newInstance(); } catch (Exception e) { - LOGGER.warn("Could not instantiate instance of driver class {}, trying JDBC URL resolution", driverClassName, e); + LOGGER.warn("Failed to create instance of driver class {}, trying jdbcUrl resolution", driverClassName, e); } } } @@ -81,11 +81,11 @@ public final class DriverDataSource implements DataSource driver = DriverManager.getDriver(jdbcUrl); } else if (!driver.acceptsURL(jdbcUrl)) { - throw new RuntimeException("Driver " + driverClassName + " claims to not accept JDBC URL " + jdbcUrl); + throw new RuntimeException("Driver " + driverClassName + " claims to not accept jdbcUrl, " + jdbcUrl); } } catch (SQLException e) { - throw new RuntimeException("Unable to get driver instance for jdbcUrl=" + jdbcUrl, e); + throw new RuntimeException("Failed to get driver instance for jdbcUrl=" + jdbcUrl, e); } }