You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2014/12/02 00:59:11 UTC

[10/13] isis git commit: ISIS-961: in IsisTransactionManager, call setAbortCause if an exception is caught for any reason (this includes an exception thrown by domain object code).

ISIS-961: in IsisTransactionManager, call setAbortCause if an exception is caught for any reason (this includes an exception thrown by domain object code).

Also:
- minor enhancement/improvement to error page so that a NonRecoverableException's message is displayed rather than a generic message.


Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/d231d201
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/d231d201
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/d231d201

Branch: refs/heads/master
Commit: d231d2019705f6a1642900ada3e4a5e8de85b4b3
Parents: c05621a
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Mon Dec 1 23:15:42 2014 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Mon Dec 1 23:15:42 2014 +0000

----------------------------------------------------------------------
 .../ui/components/actions/ActionPanel.java      |  4 +--
 .../cssmenu/ActionLinkFactoryAbstract.java      |  7 ++--
 .../viewer/wicket/ui/errors/ExceptionModel.java | 11 ++++++-
 .../transaction/IsisTransactionManager.java     | 34 ++++++++++++++------
 4 files changed, 40 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/d231d201/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/actions/ActionPanel.java
----------------------------------------------------------------------
diff --git a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/actions/ActionPanel.java b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/actions/ActionPanel.java
index b2959ff..238840e 100644
--- a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/actions/ActionPanel.java
+++ b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/actions/ActionPanel.java
@@ -351,8 +351,8 @@ public class ActionPanel extends PanelAbstract<ActionModel> implements ActionExe
             if (appEx != null) {
                 getMessageBroker().setApplicationError(appEx.getMessage());
 
-                // there's no need to abort the transaction, it will have already been done
-                // (in IsisTransactionManager#executeWithinTransaction(...)). 
+                // there's no need to set the abort cause on the transaction, it will have already been done
+                // (in IsisTransactionManager#executeWithinTransaction(...)).
                 return null;
             } 
             

http://git-wip-us.apache.org/repos/asf/isis/blob/d231d201/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/cssmenu/ActionLinkFactoryAbstract.java
----------------------------------------------------------------------
diff --git a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/cssmenu/ActionLinkFactoryAbstract.java b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/cssmenu/ActionLinkFactoryAbstract.java
index 5c7f779..d5ab010 100644
--- a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/cssmenu/ActionLinkFactoryAbstract.java
+++ b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/cssmenu/ActionLinkFactoryAbstract.java
@@ -26,18 +26,15 @@ import org.apache.wicket.Component;
 import org.apache.wicket.ajax.AjaxRequestTarget;
 import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
 import org.apache.wicket.ajax.markup.html.AjaxLink;
-import org.apache.wicket.behavior.AttributeAppender;
 import org.apache.wicket.markup.ComponentTag;
 import org.apache.wicket.markup.html.form.FormComponent;
 import org.apache.wicket.markup.html.link.AbstractLink;
-import org.apache.wicket.model.Model;
 import org.apache.wicket.request.IRequestHandler;
 import org.apache.wicket.util.visit.IVisit;
 import org.apache.wicket.util.visit.IVisitor;
 import org.apache.isis.applib.RecoverableException;
 import org.apache.isis.applib.annotation.ActionLayout;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
 import org.apache.isis.core.metamodel.spec.feature.ObjectAction;
 import org.apache.isis.core.runtime.system.context.IsisContext;
 import org.apache.isis.viewer.wicket.model.links.LinkAndLabel;
@@ -223,6 +220,10 @@ public abstract class ActionLinkFactoryAbstract implements ActionLinkFactory {
             final RecoverableException appEx = ActionModel.getApplicationExceptionIfAny(ex);
             if (appEx != null) {
                 IsisContext.getMessageBroker().setApplicationError(appEx.getMessage());
+
+                // there's no need to set the abort cause on the transaction, it will have already been done
+                // (in IsisTransactionManager#executeWithinTransaction(...)).
+
                 return null;
             } 
 

http://git-wip-us.apache.org/repos/asf/isis/blob/d231d201/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/errors/ExceptionModel.java
----------------------------------------------------------------------
diff --git a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/errors/ExceptionModel.java b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/errors/ExceptionModel.java
index fbb4aed..8c87bf2 100644
--- a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/errors/ExceptionModel.java
+++ b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/errors/ExceptionModel.java
@@ -18,9 +18,12 @@
  */
 package org.apache.isis.viewer.wicket.ui.errors;
 
+import java.util.Iterator;
 import java.util.List;
 import com.google.common.base.Throwables;
+import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
+import org.apache.isis.applib.NonRecoverableException;
 import org.apache.isis.core.metamodel.spec.feature.ObjectMember;
 import org.apache.isis.viewer.wicket.model.models.ModelAbstract;
 
@@ -58,7 +61,13 @@ public class ExceptionModel extends ModelAbstract<List<StackTraceDetail>> {
                 this.mainMessage = recognizedMessageIfAny;
             } else {
                 this.recognized =false;
-                this.mainMessage = MAIN_MESSAGE_IF_NOT_RECOGNIZED;
+
+                // see if we can find a NonRecoverableException in the stack trace
+                Iterable<NonRecoverableException> appEx = Iterables.filter(Throwables.getCausalChain(ex), NonRecoverableException.class);
+                Iterator<NonRecoverableException> iterator = appEx.iterator();
+                NonRecoverableException nonRecoverableException = iterator.hasNext() ? iterator.next() : null;
+
+                this.mainMessage = nonRecoverableException != null? nonRecoverableException.getMessage() : MAIN_MESSAGE_IF_NOT_RECOGNIZED;
             }
         }
         stackTraceDetailList = asStackTrace(ex);

http://git-wip-us.apache.org/repos/asf/isis/blob/d231d201/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransactionManager.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransactionManager.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransactionManager.java
index 0fd9308..b36e330 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransactionManager.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransactionManager.java
@@ -46,7 +46,10 @@ import org.apache.isis.core.runtime.system.session.IsisSession;
 
 import static org.apache.isis.core.commons.ensure.Ensure.ensureThatArg;
 import static org.apache.isis.core.commons.ensure.Ensure.ensureThatState;
-import static org.hamcrest.CoreMatchers.*;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.CoreMatchers.nullValue;
 
 public class IsisTransactionManager implements SessionScopedComponent {
 
@@ -139,8 +142,13 @@ public class IsisTransactionManager implements SessionScopedComponent {
      * If a transaction is {@link IsisContext#inTransaction() in progress}, then
      * uses that. Otherwise will {@link #startTransaction() start} a transaction
      * before running the block and {@link #endTransaction() commit} it at the
-     * end. If the closure throws an exception, then will
-     * {@link #abortTransaction() abort} the transaction.
+     * end.
+     *  </p>
+     *
+     * <p>
+     *  If the closure throws an exception, then will {@link #abortTransaction() abort} the transaction if was
+     *  started here, or will ensure that an already-in-progress transaction cannot commit.
+     * </p>
      */
     public void executeWithinTransaction(final TransactionalClosure closure) {
         final boolean initiallyInTransaction = inTransaction();
@@ -157,17 +165,15 @@ public class IsisTransactionManager implements SessionScopedComponent {
         } catch (final RuntimeException ex) {
             closure.onFailure();
             if (!initiallyInTransaction) {
-                // temp TODO fix swallowing of exception
-                // System.out.println(ex.getMessage());
-                // ex.printStackTrace();
                 try {
                     abortTransaction();
                 } catch (final Exception e) {
                     LOG.error("Abort failure after exception", e);
-                    // System.out.println(e.getMessage());
-                    // e.printStackTrace();
                     throw new IsisTransactionManagerException("Abort failure: " + e.getMessage(), ex);
                 }
+            } else {
+                // ensure that this xactn cannot be committed
+                getTransaction().setAbortCause(new IsisException(ex));
             }
             throw ex;
         }
@@ -181,8 +187,13 @@ public class IsisTransactionManager implements SessionScopedComponent {
      * If a transaction is {@link IsisContext#inTransaction() in progress}, then
      * uses that. Otherwise will {@link #startTransaction() start} a transaction
      * before running the block and {@link #endTransaction() commit} it at the
-     * end. If the closure throws an exception, then will
-     * {@link #abortTransaction() abort} the transaction.
+     * end.
+     *  </p>
+     *
+     * <p>
+     *  If the closure throws an exception, then will {@link #abortTransaction() abort} the transaction if was
+     *  started here, or will ensure that an already-in-progress transaction cannot commit.
+     *  </p>
      */
     public <Q> Q executeWithinTransaction(final TransactionalClosureWithReturn<Q> closure) {
         final boolean initiallyInTransaction = inTransaction();
@@ -201,6 +212,9 @@ public class IsisTransactionManager implements SessionScopedComponent {
             closure.onFailure();
             if (!initiallyInTransaction) {
                 abortTransaction();
+            } else {
+                // ensure that this xactn cannot be committed
+                getTransaction().setAbortCause(new IsisException(ex));
             }
             throw ex;
         }