Permit changing the catalog via the HikariConfigMXBean

pull/1135/head
Brett Wooldridge 7 years ago
parent 4e6bd83fb6
commit b5c340eee3

@ -61,6 +61,7 @@ public class HikariConfig implements HikariConfigMXBean
// Properties changeable at runtime through the HikariConfigMXBean // Properties changeable at runtime through the HikariConfigMXBean
// //
private volatile String catalog;
private volatile long connectionTimeout; private volatile long connectionTimeout;
private volatile long validationTimeout; private volatile long validationTimeout;
private volatile long idleTimeout; private volatile long idleTimeout;
@ -74,7 +75,6 @@ public class HikariConfig implements HikariConfigMXBean
// Properties NOT changeable at runtime // Properties NOT changeable at runtime
// //
private long initializationFailTimeout; private long initializationFailTimeout;
private String catalog;
private String connectionInitSql; private String connectionInitSql;
private String connectionTestQuery; private String connectionTestQuery;
private String dataSourceClassName; private String dataSourceClassName;
@ -152,6 +152,21 @@ public class HikariConfig implements HikariConfigMXBean
// HikariConfigMXBean methods // HikariConfigMXBean methods
// *********************************************************************** // ***********************************************************************
/** {@inheritDoc} */
@Override
public String getCatalog()
{
return catalog;
}
/** {@inheritDoc} */
@Override
public void setCatalog(String catalog)
{
this.catalog = catalog;
}
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public long getConnectionTimeout() public long getConnectionTimeout()
@ -315,28 +330,6 @@ public class HikariConfig implements HikariConfigMXBean
// All other configuration methods // All other configuration methods
// *********************************************************************** // ***********************************************************************
/**
* Get the default catalog name to be set on connections.
*
* @return the default catalog name
*/
public String getCatalog()
{
return catalog;
}
/**
* Set the default catalog name to be set on connections.
*
* @param catalog the catalog name, or null
*/
public void setCatalog(String catalog)
{
if (sealed) throw new IllegalStateException("The configuration of the pool is sealed once started. Use HikariConfigMXBean for runtime changes.");
this.catalog = catalog;
}
/** /**
* Get the SQL query to be executed to test the validity of connections. * Get the SQL query to be executed to test the validity of connections.
* *

@ -174,4 +174,20 @@ public interface HikariConfigMXBean
* @return the name of the connection pool * @return the name of the connection pool
*/ */
String getPoolName(); String getPoolName();
/**
* Get the default catalog name to be set on connections.
*
* @return the default catalog name
*/
String getCatalog();
/**
* Set the default catalog name to be set on connections.
* <p>
* WARNING: THIS VALUE SHOULD ONLY BE CHANGED WHILE THE POOL IS SUSPENDED, AFTER CONNECTIONS HAVE BEEN EVICTED.
*
* @param catalog the catalog name, or null
*/
void setCatalog(String catalog);
} }

@ -744,10 +744,11 @@ public final class HikariPool extends PoolBase implements HikariPoolMXBean, IBag
public void run() public void run()
{ {
try { try {
// refresh timeouts in case they changed via MBean // refresh values in case they changed via MBean
connectionTimeout = config.getConnectionTimeout(); connectionTimeout = config.getConnectionTimeout();
validationTimeout = config.getValidationTimeout(); validationTimeout = config.getValidationTimeout();
leakTaskFactory.updateLeakDetectionThreshold(config.getLeakDetectionThreshold()); leakTaskFactory.updateLeakDetectionThreshold(config.getLeakDetectionThreshold());
catalog = (config.getCatalog() != null && !config.getCatalog().equals(catalog)) ? config.getCatalog() : catalog;
final long idleTimeout = config.getIdleTimeout(); final long idleTimeout = config.getIdleTimeout();
final long now = currentTime(); final long now = currentTime();

@ -55,7 +55,10 @@ abstract class PoolBase
public final HikariConfig config; public final HikariConfig config;
public IMetricsTrackerDelegate metricsTracker; public IMetricsTrackerDelegate metricsTracker;
protected volatile String catalog;
protected final String poolName; protected final String poolName;
long connectionTimeout; long connectionTimeout;
long validationTimeout; long validationTimeout;
@ -72,7 +75,6 @@ abstract class PoolBase
private Executor netTimeoutExecutor; private Executor netTimeoutExecutor;
private DataSource dataSource; private DataSource dataSource;
private final String catalog;
private final String schema; private final String schema;
private final boolean isReadOnly; private final boolean isReadOnly;
private final boolean isAutoCommit; private final boolean isAutoCommit;

Loading…
Cancel
Save