Skip to content

Commit

Permalink
[#6613] Add TransactionContext.causeThrowable() to allow for Throwabl…
Browse files Browse the repository at this point in the history
…e causes for transaction rollbacks
  • Loading branch information
lukaseder committed Sep 28, 2017
1 parent 2470d00 commit bf6382e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
17 changes: 16 additions & 1 deletion jOOQ/src/main/java/org/jooq/TransactionContext.java
Expand Up @@ -60,13 +60,28 @@ public interface TransactionContext extends Scope {
/**
* The exception that has caused the rollback.
*
* @return The exception. May be <code>null</code>.
* @return The exception. May be <code>null</code>, in particular if the
* cause is a {@link Throwable}, in case of which
* {@link #causeThrowable()} should be called.
*/
Exception cause();

/**
* The throwable that has caused the rollback.
*
* @return The throwable. May be <code>null</code>.
*/
Throwable causeThrowable();

/**
* Set the exception that has caused the rollback to the current transaction
* context.
*/
TransactionContext cause(Exception cause);

/**
* Set the throwable that has caused the rollback to the current transaction
* context.
*/
TransactionContext causeThrowable(Throwable cause);
}
15 changes: 13 additions & 2 deletions jOOQ/src/main/java/org/jooq/impl/DefaultTransactionContext.java
Expand Up @@ -44,7 +44,7 @@
class DefaultTransactionContext extends AbstractScope implements TransactionContext {

Transaction transaction;
Exception cause;
Throwable cause;

DefaultTransactionContext(Configuration configuration) {
super(configuration);
Expand All @@ -63,12 +63,23 @@ public final TransactionContext transaction(Transaction t) {

@Override
public final Exception cause() {
return cause;
return cause instanceof Exception ? (Exception) cause : null;
}

@Override
public final TransactionContext cause(Exception c) {
cause = c;
return this;
}

@Override
public final Throwable causeThrowable() {
return cause;
}

@Override
public final TransactionContext causeThrowable(Throwable c) {
cause = c;
return this;
}
}

0 comments on commit bf6382e

Please sign in to comment.