Add catalog to the hikari configuration and into the connection state reset code

pull/41/head
Brett Wooldridge 11 years ago
parent aea65f9ccb
commit 2bc5b57575

@ -60,6 +60,7 @@ public final class HikariConfig implements HikariConfigMBean
private String connectionInitSql;
private String connectionTestQuery;
private String dataSourceClassName;
private String catalog;
private String poolName;
private boolean isAutoCommit;
private boolean isInitializationFailFast;
@ -183,6 +184,16 @@ public final class HikariConfig implements HikariConfigMBean
this.acquireRetryDelay = acquireRetryDelayMs;
}
public String getCatalog()
{
return catalog;
}
public void setCatalog(String catalog)
{
this.catalog = catalog;
}
public String getConnectionCustomizerClassName()
{
return connectionCustomizerClassName;

@ -61,6 +61,7 @@ public final class HikariPool implements HikariPoolMBean
private final boolean isAutoCommit;
private final boolean jdbc4ConnectionTest;
private final boolean isRegisteredMbeans;
private final String catalog;
private int transactionIsolation;
private volatile boolean shutdown;
private boolean debug;
@ -85,6 +86,7 @@ public final class HikariPool implements HikariPoolMBean
this.isAutoCommit = configuration.isAutoCommit();
this.isRegisteredMbeans = configuration.isRegisterMbeans();
this.transactionIsolation = configuration.getTransactionIsolation();
this.catalog = configuration.getCatalog();
this.debug = LOGGER.isDebugEnabled();
if (configuration.getDataSource() == null)
@ -392,7 +394,7 @@ public final class HikariPool implements HikariPoolMBean
connectionCustomizer.customize(connection);
}
IHikariConnectionProxy proxyConnection = (IHikariConnectionProxy) ProxyFactory.getProxyConnection(this, connection, transactionIsolation, isAutoCommit);
IHikariConnectionProxy proxyConnection = ProxyFactory.getProxyConnection(this, connection, transactionIsolation, isAutoCommit, catalog);
String initSql = configuration.getConnectionInitSql();
if (initSql != null && initSql.length() > 0)

@ -46,18 +46,19 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy
protected final Connection delegate;
private final long creationTime;
private final FastStatementList openStatements;
private final HikariPool parentPool;
private final int defaultIsolationLevel;
private final boolean defaultAutoCommit;
private final String defaultCatalog;
private final AtomicInteger state;
private boolean isClosed;
private boolean forceClose;
private boolean isTransactionIsolationDirty;
private boolean isAutoCommitDirty;
private final long creationTime;
private boolean isCatalogDirty;
private volatile long lastAccess;
private StackTraceElement[] leakTrace;
@ -65,6 +66,7 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy
private final int hashCode;
// static initializer
static
{
@ -77,12 +79,13 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy
SQL_ERRORS.add("JZ0C1"); // Sybase disconnect error
}
protected ConnectionProxy(HikariPool pool, Connection connection, int defaultIsolationLevel, boolean defaultAutoCommit)
protected ConnectionProxy(HikariPool pool, Connection connection, int defaultIsolationLevel, boolean defaultAutoCommit, String defaultCatalog)
{
this.parentPool = pool;
this.delegate = connection;
this.defaultIsolationLevel = defaultIsolationLevel;
this.defaultAutoCommit = defaultAutoCommit;
this.defaultCatalog = defaultCatalog;
this.state = new AtomicInteger();
this.creationTime = lastAccess = System.currentTimeMillis();
@ -173,13 +176,41 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy
}
}
private final <T extends Statement> T trackStatement(T statement)
private <T extends Statement> T trackStatement(T statement)
{
openStatements.add(statement);
return statement;
}
private void resetConnectionState() throws SQLException
{
if (!delegate.getAutoCommit())
{
delegate.rollback();
}
if (isAutoCommitDirty)
{
delegate.setAutoCommit(defaultAutoCommit);
isAutoCommitDirty = false;
}
if (isTransactionIsolationDirty)
{
delegate.setTransactionIsolation(defaultIsolationLevel);
isTransactionIsolationDirty = false;
}
if (isCatalogDirty && defaultCatalog != null)
{
delegate.setCatalog(defaultCatalog);
isCatalogDirty = false;
}
delegate.clearWarnings();
}
// **********************************************************************
// IBagManagable Methods
// **********************************************************************
@ -234,24 +265,7 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy
openStatements.clear();
}
if (!delegate.getAutoCommit())
{
delegate.rollback();
}
if (isAutoCommitDirty)
{
delegate.setAutoCommit(defaultAutoCommit);
isAutoCommitDirty = false;
}
if (isTransactionIsolationDirty)
{
delegate.setTransactionIsolation(defaultIsolationLevel);
isTransactionIsolationDirty = false;
}
delegate.clearWarnings();
resetConnectionState();
}
catch (SQLException e)
{
@ -486,6 +500,7 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy
/** {@inheritDoc} */
public final void setAutoCommit(boolean autoCommit) throws SQLException
{
checkClosed();
try
{
delegate.setAutoCommit(autoCommit);
@ -501,6 +516,7 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy
/** {@inheritDoc} */
public final void setTransactionIsolation(int level) throws SQLException
{
checkClosed();
try
{
delegate.setTransactionIsolation(level);
@ -513,6 +529,22 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy
}
}
@Override
public final void setCatalog(String catalog) throws SQLException
{
checkClosed();
try
{
delegate.setCatalog(catalog);
isCatalogDirty = !catalog.equals(defaultCatalog);
}
catch (SQLException e)
{
checkException(e);
throw e;
}
}
/** {@inheritDoc} */
public final boolean isWrapperFor(Class<?> iface) throws SQLException
{

@ -30,7 +30,7 @@ import com.zaxxer.hikari.HikariPool;
*/
public final class ProxyFactory
{
public static Connection getProxyConnection(HikariPool pool, Connection connection, int defaultIsolationLevel, boolean defaultAutoCommit)
public static IHikariConnectionProxy getProxyConnection(HikariPool pool, Connection connection, int defaultIsolationLevel, boolean defaultAutoCommit, String defaultCatalog)
{
// Body is injected by JavassistProxyFactory
return null;

Loading…
Cancel
Save