diff --git a/src/main/java/com/zaxxer/hikari/HikariConfig.java b/src/main/java/com/zaxxer/hikari/HikariConfig.java index d2cf524a..74930aad 100644 --- a/src/main/java/com/zaxxer/hikari/HikariConfig.java +++ b/src/main/java/com/zaxxer/hikari/HikariConfig.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.sql.Connection; +import java.sql.SQLException; import java.util.Properties; import java.util.Set; import java.util.TreeSet; @@ -77,6 +78,7 @@ public class HikariConfig implements HikariConfigMBean private boolean isRegisterMbeans; private DataSource dataSource; private Properties dataSourceProperties; + private IConnectionCustomizer customizer; private int transactionIsolation; static @@ -100,6 +102,12 @@ public class HikariConfig implements HikariConfigMBean maxLifetime = MAX_LIFETIME; isRecordMetrics = false; transactionIsolation = -1; + customizer = new IConnectionCustomizer() { + @Override + public void customize(Connection connection) throws SQLException + { + } + }; } /** @@ -184,6 +192,26 @@ public class HikariConfig implements HikariConfigMBean this.connectionCustomizerClassName = connectionCustomizerClassName; } + /** + * Get the customizer instance specified by the user. + * + * @return an instance of IConnectionCustomizer + */ + public IConnectionCustomizer getConnectionCustomizer() + { + return customizer; + } + + /** + * Set the connection customizer to be used by the pool. + * + * @param customizer an instance of IConnectionCustomizer + */ + public void setConnectionCustomizer(IConnectionCustomizer customizer) + { + this.customizer = customizer; + } + /** * Get the SQL query to be executed to test the validity of connections. * diff --git a/src/main/java/com/zaxxer/hikari/pool/HikariPool.java b/src/main/java/com/zaxxer/hikari/pool/HikariPool.java index 6b9fc60a..260ca960 100644 --- a/src/main/java/com/zaxxer/hikari/pool/HikariPool.java +++ b/src/main/java/com/zaxxer/hikari/pool/HikariPool.java @@ -562,12 +562,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener } } - return new IConnectionCustomizer() { - @Override - public void customize(Connection connection) throws SQLException - { - } - }; + return configuration.getConnectionCustomizer(); } private void logPoolState(String... prefix)