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

@ -24,7 +24,7 @@ package com.zaxxer.hikari;
public interface HikariConfigMXBean public interface HikariConfigMXBean
{ {
/** /**
* Get the maximum number of milliseconds that a client will wait for a connection from the pool. If this * Get the maximum number of milliseconds that a client will wait for a connection from the pool. If this
* time is exceeded without a connection becoming available, a SQLException will be thrown from * time is exceeded without a connection becoming available, a SQLException will be thrown from
* {@link javax.sql.DataSource#getConnection()}. * {@link javax.sql.DataSource#getConnection()}.
* *
@ -58,7 +58,7 @@ public interface HikariConfigMXBean
void setValidationTimeout(long validationTimeoutMs); void setValidationTimeout(long validationTimeoutMs);
/** /**
* This property controls the maximum amount of time (in milliseconds) that a connection is allowed to sit * This property controls the maximum amount of time (in milliseconds) that a connection is allowed to sit
* idle in the pool. Whether a connection is retired as idle or not is subject to a maximum variation of +30 * idle in the pool. Whether a connection is retired as idle or not is subject to a maximum variation of +30
* seconds, and average variation of +15 seconds. A connection will never be retired as idle before this timeout. * seconds, and average variation of +15 seconds. A connection will never be retired as idle before this timeout.
* A value of 0 means that idle connections are never removed from the pool. * A value of 0 means that idle connections are never removed from the pool.
@ -68,7 +68,7 @@ public interface HikariConfigMXBean
long getIdleTimeout(); long getIdleTimeout();
/** /**
* This property controls the maximum amount of time (in milliseconds) that a connection is allowed to sit * This property controls the maximum amount of time (in milliseconds) that a connection is allowed to sit
* idle in the pool. Whether a connection is retired as idle or not is subject to a maximum variation of +30 * idle in the pool. Whether a connection is retired as idle or not is subject to a maximum variation of +30
* seconds, and average variation of +15 seconds. A connection will never be retired as idle before this timeout. * seconds, and average variation of +15 seconds. A connection will never be retired as idle before this timeout.
* A value of 0 means that idle connections are never removed from the pool. * A value of 0 means that idle connections are never removed from the pool.
@ -131,7 +131,7 @@ public interface HikariConfigMXBean
/** /**
* The property controls the maximum number of connections that HikariCP will keep in the pool, * The property controls the maximum number of connections that HikariCP will keep in the pool,
* including both idle and in-use connections. * including both idle and in-use connections.
* *
* @return the maximum number of connections in the pool * @return the maximum number of connections in the pool
*/ */
@ -167,11 +167,27 @@ public interface HikariConfigMXBean
*/ */
void setUsername(String username); void setUsername(String username);
/** /**
* The name of the connection pool. * The name of the connection pool.
* *
* @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