Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions api/src/org/labkey/api/data/DbScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.jetbrains.annotations.Nullable;
import org.junit.Assert;
import org.junit.Test;
import org.labkey.api.action.ApiUsageException;
import org.labkey.api.audit.TransactionAuditProvider;
import org.labkey.api.cache.Cache;
import org.labkey.api.data.ConnectionWrapper.Closer;
Expand Down Expand Up @@ -2166,8 +2167,7 @@ public static void closeAllConnectionsForCurrentThread()
}
try
{
LOG.warn("Forcing close of still-pending transaction object. Current stack is ", new Throwable());
LOG.warn("Forcing close of still-pending transaction object started at ", t._creation);
LOG.warn("Forcing close of still-pending transaction object started at {}. Current stack is ", t._creation, new Throwable());
t.close();
}
catch (ConnectionAlreadyReleasedException ignored)
Expand Down Expand Up @@ -2715,16 +2715,17 @@ public void commit()
conn.commit();
conn.setAutoCommit(true);
LOG.debug("setAutoCommit(true)");
if (null != _closeOnClose)
try { _closeOnClose.close(); } catch (Exception ignore) {}
}
finally
{
if (null != _closeOnClose)
try { _closeOnClose.close(); } catch (Exception ignore) {}
if (null != conn)
conn.internalClose();
}

popCurrentTransaction();
// Make sure to pop whether we successfully committed or not
popCurrentTransaction();
}

CommitTaskOption.POSTCOMMIT.run(this);
}
Expand Down Expand Up @@ -3164,6 +3165,24 @@ public void testAutoCommitFailure()
closeAllConnectionsForCurrentThread();
}

@Test
public void tesCommitTaskFailure()
{
String message = "Expected failure";
try (Transaction t = getLabKeyScope().ensureTransaction())
{
t.addCommitTask(() -> { throw new ApiUsageException("Expected failure"); }, CommitTaskOption.PRECOMMIT);
t.commit();
fail("Shouldn't have gotten here, expected ApiUsageException");
}
catch (ApiUsageException e)
{
assertEquals("Bad message", message, e.getMessage());
}
assertFalse(getLabKeyScope().isTransactionActive());
closeAllConnectionsForCurrentThread();
}

@Test
public void testLockReleasedException()
{
Expand Down
Loading