#791 - ENH: Add transaction.setRollbackOnly() ... (and Ebean.setRollbackOnly())

This commit is contained in:
Robin Bygrave committed 2016-07-31 21:24:31 +12:00
1 parent d82148248c
commit b4a1d52067
6 files changed
+93

No files matched your search

@@ -181,6 +181,15 @@ public class ScopeTrans implements Thread.UncaughtExceptionHandler {
return e;
}
/**
* Mark the underlying transaction as rollback only.
*/
public void setRollbackOnly() {
if (transaction != null) {
transaction.setRollbackOnly();
}
}
/**
* An Exception was caught and may or may not cause a rollback to occur.
* Returns the exception and this should be thrown by the calling code.
@@ -49,6 +49,11 @@ public class ScopedTransaction implements SpiTransaction {
scopeTrans.rollback(e);
}
@Override
public void setRollbackOnly() {
scopeTrans.setRollbackOnly();
}
@Override
public void end() throws PersistenceException {
try {
@@ -66,6 +66,8 @@ public class JdbcTransaction implements SpiTransaction {
*/
protected boolean active;
protected boolean rollbackOnly;
/**
* The underlying Connection.
*/
@@ -903,6 +905,10 @@ public class JdbcTransaction implements SpiTransaction {
*/
@Override
public void commit() throws RollbackException {
if (rollbackOnly) {
rollback();
return;
}
if (!isActive()) {
throw new IllegalStateException(illegalStateMessage);
}
@@ -945,6 +951,14 @@ public class JdbcTransaction implements SpiTransaction {
}
}
/**
* Mark the transaction as rollback only.
*/
@Override
public void setRollbackOnly() {
this.rollbackOnly = true;
}
/**
* Rollback the transaction.
*/