[#8413] Rollback should not be called when TransactionListener.commitEnd() throws exception
This commit is contained in:
parent
b0957ac814
commit
ce73802a32
@ -513,6 +513,7 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
|
||||
DefaultTransactionContext ctx = new DefaultTransactionContext(configuration.derive());
|
||||
TransactionProvider provider = ctx.configuration().transactionProvider();
|
||||
TransactionListeners listeners = new TransactionListeners(ctx.configuration());
|
||||
boolean committed = false;
|
||||
|
||||
try {
|
||||
try {
|
||||
@ -528,6 +529,7 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
|
||||
try {
|
||||
listeners.commitStart(ctx);
|
||||
provider.commit(ctx);
|
||||
committed = true;
|
||||
}
|
||||
finally {
|
||||
listeners.commitEnd(ctx);
|
||||
@ -536,31 +538,39 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
|
||||
|
||||
// [#6608] [#7167] Errors are no longer handled differently
|
||||
catch (Throwable cause) {
|
||||
if (cause instanceof Exception)
|
||||
ctx.cause((Exception) cause);
|
||||
else
|
||||
ctx.causeThrowable(cause);
|
||||
|
||||
listeners.rollbackStart(ctx);
|
||||
try {
|
||||
provider.rollback(ctx);
|
||||
// [#8413] Avoid rollback logic if commit was successful (exception in commitEnd())
|
||||
if (!committed) {
|
||||
if (cause instanceof Exception)
|
||||
ctx.cause((Exception) cause);
|
||||
else
|
||||
ctx.causeThrowable(cause);
|
||||
|
||||
listeners.rollbackStart(ctx);
|
||||
try {
|
||||
provider.rollback(ctx);
|
||||
}
|
||||
|
||||
// [#3718] Use reflection to support also JDBC 4.0
|
||||
catch (Exception suppress) {
|
||||
|
||||
cause.addSuppressed(suppress);
|
||||
|
||||
}
|
||||
listeners.rollbackEnd(ctx);
|
||||
}
|
||||
|
||||
// [#3718] Use reflection to support also JDBC 4.0
|
||||
catch (Exception suppress) {
|
||||
|
||||
cause.addSuppressed(suppress);
|
||||
|
||||
}
|
||||
listeners.rollbackEnd(ctx);
|
||||
|
||||
// [#6608] [#7167] Errors are no longer handled differently
|
||||
if (cause instanceof RuntimeException)
|
||||
throw (RuntimeException) cause;
|
||||
else if (cause instanceof Error)
|
||||
throw (Error) cause;
|
||||
else
|
||||
throw new DataAccessException("Rollback caused", cause);
|
||||
throw new DataAccessException(committed
|
||||
? "Exception after commit"
|
||||
: "Rollback caused"
|
||||
, cause
|
||||
);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user