ISIS-1498: introduces new clearAbortCauseAndContinue() internal API for IsisTransaction, and leverage within BackgroundCommandExecution for the case where an action throws an exception (want to capture that, mark on the background Command, and persist).
Project: http://git-wip-us.apache.org/repos/asf/isis/repo Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/06d95ab9 Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/06d95ab9 Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/06d95ab9 Branch: refs/heads/master Commit: 06d95ab91a69e8f8e5513fef40fe086259f69a80 Parents: dc671d0 Author: Dan Haywood <[email protected]> Authored: Tue Sep 27 15:03:19 2016 +0100 Committer: Dan Haywood <[email protected]> Committed: Tue Sep 27 15:04:43 2016 +0100 ---------------------------------------------------------------------- .../background/BackgroundCommandExecution.java | 19 +++++++++++-------- .../system/transaction/IsisTransaction.java | 15 +++++++++++++-- 2 files changed, 24 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/isis/blob/06d95ab9/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/BackgroundCommandExecution.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/BackgroundCommandExecution.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/BackgroundCommandExecution.java index 9343c11..ba6d03d 100644 --- a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/BackgroundCommandExecution.java +++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/BackgroundCommandExecution.java @@ -217,18 +217,21 @@ public abstract class BackgroundCommandExecution extends AbstractIsisSessionTemp } } catch (RuntimeException e) { - // this doesn't really make sense if >1 action - // in any case, the capturing of the action interaction should be the - // responsibility of auditing/profiling + // hmmm, this doesn't really make sense if >1 action + // + // in any case, the capturing of the result of the action invocation should be the + // responsibility of the interaction... backgroundCommand.setException(Throwables.getStackTraceAsString(e)); - // alternatively, could have used ... - Exception unused = backgroundInteraction.getPriorExecution().getThrew(); - - backgroundInteraction.getCurrentExecution().setThrew(e); + // lower down the stack the IsisTransactionManager will have set the transaction to abort + // however, we don't want that to occur (because any changes made to the backgroundCommand itself + // would also be rolled back, and it would keep getting picked up again by a scheduler for + // processing); instead we clear the abort cause and ensure we can continue. + transactionManager.getCurrentTransaction().clearAbortCauseAndContinue(); } - backgroundCommand.setCompletedAt(backgroundInteraction.getPriorExecution().getCompletedAt()); + final Interaction.Execution priorExecution = backgroundInteraction.getPriorExecution(); + backgroundCommand.setCompletedAt(priorExecution.getCompletedAt()); } private ObjectAction findObjectAction( http://git-wip-us.apache.org/repos/asf/isis/blob/06d95ab9/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransaction.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransaction.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransaction.java index ace6b3c..f7eaf60 100644 --- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransaction.java +++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransaction.java @@ -472,8 +472,12 @@ public class IsisTransaction implements TransactionScopedComponent, Transaction * * <p> * If the cause is subsequently rendered by code higher up the stack, then the - * cause can be {@link #clearAbortCause() cleared}. However, it is not possible - * to change the state from {@link State#MUST_ABORT}. + * cause can be {@link #clearAbortCause() cleared}. Note that this keeps the transaction in a state of + * {@link State#MUST_ABORT}. + * + * <p> + * If the cause is to be discarded completely (eg background command execution), then + * {@link #clearAbortCauseAndContinue()} can be used. */ public void setAbortCause(IsisException abortCause) { setState(State.MUST_ABORT); @@ -489,6 +493,13 @@ public class IsisTransaction implements TransactionScopedComponent, Transaction abortCause = null; } + public void clearAbortCauseAndContinue() { + setState(State.IN_PROGRESS); + clearAbortCause(); + } + + + //endregion
