Fixes #512 back port to 2.3.x stream.

2.3.x
Brett Wooldridge 9 years ago
parent d5e496cecd
commit e94d920595

@ -212,7 +212,7 @@ public abstract class BaseHikariPool implements HikariPoolMXBean, IBagStateListe
else {
metricsContext.setConnectionLastOpen(bagEntry, now);
metricsContext.stop();
return ProxyFactory.getProxyConnection((HikariPool) this, bagEntry, leakTask.start(bagEntry));
return ProxyFactory.getProxyConnection((HikariPool) this, bagEntry, leakTask.start(bagEntry), isAutoCommit);
}
}
while (timeout > 0L);

@ -58,6 +58,7 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy
private boolean isCatalogDirty;
private boolean isReadOnlyDirty;
private boolean isTransactionIsolationDirty;
private boolean isAutoCommit;
// static initializer
static {
@ -72,11 +73,12 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy
SQL_ERRORS.add("JZ0C1"); // Sybase disconnect error
}
protected ConnectionProxy(final HikariPool pool, final PoolBagEntry bagEntry, final LeakTask leakTask) {
protected ConnectionProxy(final HikariPool pool, final PoolBagEntry bagEntry, final LeakTask leakTask, final boolean isAutoCommit) {
this.parentPool = pool;
this.bagEntry = bagEntry;
this.delegate = bagEntry.connection;
this.leakTask = leakTask;
this.isAutoCommit = isAutoCommit;
this.lastAccess = bagEntry.lastAccess;
this.openStatements = new FastList<Statement>(Statement.class, 16);
@ -129,9 +131,13 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy
@Override
public final void markCommitStateDirty()
{
isCommitStateDirty = true;
if (isAutoCommit) {
lastAccess = System.currentTimeMillis();
}
else {
isCommitStateDirty = true;
}
}
// ***********************************************************************
// Internal methods
@ -201,13 +207,15 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy
try {
closeOpenStatements();
if (isCommitStateDirty && !delegate.getAutoCommit()) {
if (isCommitStateDirty && isAutoCommit) {
LOGGER.debug("{} Performing rollback on {} due to dirty commit state.", parentPool, delegate);
lastAccess = System.currentTimeMillis();
delegate.rollback();
}
if (isConnectionStateDirty) {
resetConnectionState();
lastAccess = System.currentTimeMillis();
}
delegate.clearWarnings();
@ -323,6 +331,7 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy
{
delegate.commit();
isCommitStateDirty = false;
lastAccess = System.currentTimeMillis();
}
/** {@inheritDoc} */
@ -331,6 +340,7 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy
{
delegate.rollback();
isCommitStateDirty = false;
lastAccess = System.currentTimeMillis();
}
/** {@inheritDoc} */
@ -339,6 +349,7 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy
{
delegate.rollback(savepoint);
isCommitStateDirty = false;
lastAccess = System.currentTimeMillis();
}
/** {@inheritDoc} */
@ -347,6 +358,7 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy
{
delegate.setAutoCommit(autoCommit);
isConnectionStateDirty = true;
isAutoCommit = autoCommit;
isAutoCommitDirty = (autoCommit != parentPool.isAutoCommit);
}

@ -45,9 +45,10 @@ public final class ProxyFactory
* @param pool the {@link HikariPool} that will own this proxy
* @param bagEntry the PoolBagEntry entry for this proxy
* @param leakTask a leak detetection task
* @param isAutoCommit
* @return a proxy that wraps the specified {@link Connection}
*/
public static IHikariConnectionProxy getProxyConnection(final HikariPool pool, final PoolBagEntry bagEntry, final LeakTask leakTask)
public static IHikariConnectionProxy getProxyConnection(final HikariPool pool, final PoolBagEntry bagEntry, final LeakTask leakTask, final boolean isAutoCommit)
{
// Body is replaced (injected) by JavassistProxyFactory
throw new IllegalStateException("You need to run the CLI build and you need target/classes in your classpath to run.");

@ -126,6 +126,7 @@ public class ConnectionStateTest
public void testCommitTracking() throws SQLException
{
HikariDataSource ds = new HikariDataSource();
ds.setAutoCommit(false);
ds.setMinimumIdle(1);
ds.setMaximumPoolSize(1);
ds.setConnectionTestQuery("VALUES 1");

Loading…
Cancel
Save