Fix #78 add ability to set an IConnectionCustomizer instance directly on the HikariConfig/HikariDataSource.

pull/84/head
Brett Wooldridge 11 years ago
parent c7b3095d85
commit cc12165b44

@ -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.
*

@ -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)

Loading…
Cancel
Save