[#6613] Add TransactionContext.causeThrowable() to allow for Throwable causes for transaction rollbacks
This commit is contained in:
parent
2470d00b29
commit
bf6382edb5
@ -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);
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ import org.jooq.TransactionContext;
|
||||
class DefaultTransactionContext extends AbstractScope implements TransactionContext {
|
||||
|
||||
Transaction transaction;
|
||||
Exception cause;
|
||||
Throwable cause;
|
||||
|
||||
DefaultTransactionContext(Configuration configuration) {
|
||||
super(configuration);
|
||||
@ -63,7 +63,7 @@ class DefaultTransactionContext extends AbstractScope implements TransactionCont
|
||||
|
||||
@Override
|
||||
public final Exception cause() {
|
||||
return cause;
|
||||
return cause instanceof Exception ? (Exception) cause : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -71,4 +71,15 @@ class DefaultTransactionContext extends AbstractScope implements TransactionCont
|
||||
cause = c;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Throwable causeThrowable() {
|
||||
return cause;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final TransactionContext causeThrowable(Throwable c) {
|
||||
cause = c;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user