From 39bf64fef7cc5850ea68ba75fcebc1b0572d11fa Mon Sep 17 00:00:00 2001 From: lukaseder Date: Thu, 22 Mar 2018 11:18:08 +0100 Subject: [PATCH] [#7167] Errors should also roll back a transaction --- .../org/jooq/ContextTransactionalCallable.java | 4 ++-- .../org/jooq/ContextTransactionalRunnable.java | 4 ++-- .../main/java/org/jooq/TransactionalCallable.java | 4 ++-- .../main/java/org/jooq/TransactionalRunnable.java | 4 ++-- .../main/java/org/jooq/impl/DefaultDSLContext.java | 14 ++++++-------- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/ContextTransactionalCallable.java b/jOOQ/src/main/java/org/jooq/ContextTransactionalCallable.java index 287677e953..2ae4b132c6 100644 --- a/jOOQ/src/main/java/org/jooq/ContextTransactionalCallable.java +++ b/jOOQ/src/main/java/org/jooq/ContextTransactionalCallable.java @@ -62,8 +62,8 @@ public interface ContextTransactionalCallable { *

* If this method completes normally, and this is not a nested transaction, * then the transaction will be committed. If this method completes with an - * exception, then the transaction is rolled back to the beginning of this - * ContextTransactionalCallable. + * exception (any {@link Throwable}), then the transaction is rolled back to + * the beginning of this ContextTransactionalCallable. * * @return The outcome of the transaction. * @throws Throwable Any exception that will cause a rollback of the code diff --git a/jOOQ/src/main/java/org/jooq/ContextTransactionalRunnable.java b/jOOQ/src/main/java/org/jooq/ContextTransactionalRunnable.java index eefc385dd3..4b7a585eef 100644 --- a/jOOQ/src/main/java/org/jooq/ContextTransactionalRunnable.java +++ b/jOOQ/src/main/java/org/jooq/ContextTransactionalRunnable.java @@ -62,8 +62,8 @@ public interface ContextTransactionalRunnable { *

* If this method completes normally, and this is not a nested transaction, * then the transaction will be committed. If this method completes with an - * exception, then the transaction is rolled back to the beginning of this - * ContextTransactionalRunnable. + * exception (any {@link Throwable}), then the transaction is rolled back to + * the beginning of this ContextTransactionalRunnable. * * @throws Throwable Any exception that will cause a rollback of the code * contained in this transaction. If this is a nested diff --git a/jOOQ/src/main/java/org/jooq/TransactionalCallable.java b/jOOQ/src/main/java/org/jooq/TransactionalCallable.java index 9bfae19e65..b66727f3e8 100644 --- a/jOOQ/src/main/java/org/jooq/TransactionalCallable.java +++ b/jOOQ/src/main/java/org/jooq/TransactionalCallable.java @@ -59,8 +59,8 @@ public interface TransactionalCallable { *

* If this method completes normally, and this is not a nested transaction, * then the transaction will be committed. If this method completes with an - * exception, then the transaction is rolled back to the beginning of this - * TransactionalCallable. + * exception (any {@link Throwable}), then the transaction is rolled back to + * the beginning of this TransactionalCallable. * * @param configuration The Configuration in whose context the * transaction is run. diff --git a/jOOQ/src/main/java/org/jooq/TransactionalRunnable.java b/jOOQ/src/main/java/org/jooq/TransactionalRunnable.java index 3bea403404..0eb34b27fc 100644 --- a/jOOQ/src/main/java/org/jooq/TransactionalRunnable.java +++ b/jOOQ/src/main/java/org/jooq/TransactionalRunnable.java @@ -59,8 +59,8 @@ public interface TransactionalRunnable { *

* If this method completes normally, and this is not a nested transaction, * then the transaction will be committed. If this method completes with an - * exception, then the transaction is rolled back to the beginning of this - * TransactionalRunnable. + * exception (any {@link Throwable}), then the transaction is rolled back to + * the beginning of this TransactionalRunnable. * * @param configuration The Configuration in whose context the * transaction is run. diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java index c70d0442db..c98000a250 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java @@ -528,10 +528,7 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri } } - // [#6608] Propagating errors directly - catch (Error error) { - throw error; - } + // [#6608] [#7167] Errors are no longer handled differently catch (Throwable cause) { if (cause instanceof Exception) ctx.cause((Exception) cause); @@ -551,12 +548,13 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri } listeners.rollbackEnd(ctx); - if (cause instanceof RuntimeException) { + // [#6608] [#7167] Errors are no longer handled differently + if (cause instanceof RuntimeException) throw (RuntimeException) cause; - } - else { + else if (cause instanceof Error) + throw (Error) cause; + else throw new DataAccessException("Rollback caused", cause); - } } return result;