Conditionally reset the transaction isolation level based on whether the user has altered it or not. Turns out it is expensive for some databases.

pull/30/head
Brett Wooldridge 11 years ago
parent 04aa65a6d8
commit c6b8d488a4

@ -388,7 +388,7 @@ public final class HikariPool implements HikariPoolMBean
* @param timeoutMs the timeout before we consider the test a failure
* @return true if the connection is alive, false if it is not alive or we timed out
*/
private boolean isConnectionAlive(final Connection connection, long timeoutMs)
private boolean isConnectionAlive(final IHikariConnectionProxy connection, long timeoutMs)
{
if (timeoutMs < 1000)
{
@ -398,7 +398,10 @@ public final class HikariPool implements HikariPoolMBean
try
{
connection.setAutoCommit(isAutoCommit);
connection.setTransactionIsolation(transactionIsolation);
if (connection.isTransactionIsolationDirty())
{
connection.setTransactionIsolation(transactionIsolation);
}
try
{
@ -418,6 +421,8 @@ public final class HikariPool implements HikariPoolMBean
{
connection.commit();
}
connection.resetTransactionIsolationDirty();
}
return true;

@ -45,6 +45,7 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy
private boolean isClosed;
private boolean forceClose;
private boolean isTransactionIsolationDirty;
private final long creationTime;
private volatile long lastAccess;
@ -113,6 +114,16 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy
scheduler.schedule(leakTask, leakDetectionThreshold);
}
public final boolean isTransactionIsolationDirty()
{
return isTransactionIsolationDirty;
}
public void resetTransactionIsolationDirty()
{
isTransactionIsolationDirty = false;
}
public final boolean isBrokenConnection()
{
return forceClose;
@ -399,6 +410,22 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy
}
}
/** {@inheritDoc} */
public void setTransactionIsolation(int level) throws SQLException
{
checkClosed();
try
{
delegate.setTransactionIsolation(level);
isTransactionIsolationDirty = true;
}
catch (SQLException e)
{
checkException(e);
throw e;
}
}
// **********************************************************************
// Private Methods
// **********************************************************************

@ -36,6 +36,10 @@ public interface IHikariConnectionProxy extends Connection
boolean isBrokenConnection();
boolean isTransactionIsolationDirty();
void resetTransactionIsolationDirty();
long getCreationTime();
long getLastAccess();

Loading…
Cancel
Save