Merge pull request #2815 from ebean-orm/feature/2814-nestedUseSavepoint

#2814 - Change setNestedUseSavepoint() to use 'ScopeTrans' rather than the underlying Transaction
This commit is contained in:
Rob Bygrave authored and GitHub committed 2022-09-02 08:20:53 +12:00
commit c1320e4184
4 files changed
+55 -11

No files matched your search

@@ -45,15 +45,14 @@ public final class ScopeTrans {
* Flag set when nested commit has occurred.
*/
private boolean nestedCommit;
private boolean nestedUseSavepoint;
public ScopeTrans(boolean rollbackOnChecked, boolean created, SpiTransaction transaction, TxScope txScope) {
this.rollbackOnChecked = rollbackOnChecked;
this.created = created;
this.transaction = transaction;
this.noRollbackFor = txScope.getNoRollbackFor();
this.rollbackFor = txScope.getRollbackFor();
if (transaction != null) {
if (!created && txScope.isBatchSet() || txScope.isBatchOnCascadeSet() || txScope.isBatchSizeSet()) {
restoreBatch = transaction.isBatchMode();
@@ -90,6 +89,14 @@ public final class ScopeTrans {
return "ScopeTrans " + transaction;
}
void setNestedUseSavepoint() {
nestedUseSavepoint = true;
}
boolean isNestedUseSavepoint() {
return nestedUseSavepoint;
}
/**
* Return the current/active transaction.
*/
@@ -101,7 +108,6 @@ public final class ScopeTrans {
* Complete the transaction from enhanced transactional. Try to commit.
*/
void complete(Object returnOrThrowable, int opCode) {
if (opCode == OPCODE_ATHROW) {
// exited with a Throwable
caughtThrowable((Throwable) returnOrThrowable);
@@ -168,7 +174,6 @@ public final class ScopeTrans {
* Returns the exception and this should be thrown by the calling code.
*/
public <T extends Throwable> T caughtThrowable(T e) {
if (isRollbackThrowable(e)) {
rollback(e);
}
@@ -188,21 +193,17 @@ public final class ScopeTrans {
* Return true if this throwable should cause a rollback to occur.
*/
private boolean isRollbackThrowable(Throwable e) {
if (e instanceof Error) {
return true;
}
if (noRollbackFor != null) {
for (Class<? extends Throwable> aNoRollbackFor : noRollbackFor) {
if (aNoRollbackFor.equals(e.getClass())) {
// explicit no rollback for this one
return false;
}
}
}
if (rollbackFor != null) {
for (Class<? extends Throwable> aRollbackFor : rollbackFor) {
if (aRollbackFor.equals(e.getClass())) {
@@ -211,7 +212,6 @@ public final class ScopeTrans {
}
}
}
// checked exceptions...
// EJB defaults this to false which is not intuitive IMO
// Ebean makes this configurable (default to true)
@@ -33,13 +33,26 @@ public final class ScopedTransaction extends SpiTransactionProxy {
return "ScopedTransaction " + current;
}
@Override
public void setNestedUseSavepoint() {
current.setNestedUseSavepoint();
}
@Override
public boolean isNestedUseSavepoint() {
return current.isNestedUseSavepoint();
}
/**
* Push the scope transaction.
*/
public void push(ScopeTrans scopeTrans) {
if (current != null) {
stack.push(current);
if (current.isNestedUseSavepoint()) {
// child scope 'inherits' nestedUseSavepoint
scopeTrans.setNestedUseSavepoint();
}
}
current = scopeTrans;
transaction = scopeTrans.getTransaction();
@@ -573,7 +573,7 @@ public class TransactionManager implements SpiTransactionManager {
} else {
setToScope = false;
transaction = txnContainer.current();
nestedSavepoint = transaction.isNestedUseSavepoint();
nestedSavepoint = txnContainer.isNestedUseSavepoint();
}
TxType type = txScope.getType();