Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Adding correct support to mark at tx for rollback

Cody found this. I went through and debugged his sample application and
found this was the easiest way to solve his problem. Others will
probably have this problem as well. There's no JIRA, though there
probably should have been, :)
  • Loading branch information...
commit 3e2806d96f345d24e4860c267f5cba181a311435 1 parent 11b7816
Jason Porter authored January 03, 2012
53  impl/src/main/java/org/jboss/seam/faces/transaction/UnexpectedExceptionObserver.java
... ...
@@ -0,0 +1,53 @@
  1
+/*
  2
+ * JBoss, Home of Professional Open Source
  3
+ * Copyright 2012, Red Hat, Inc., and individual contributors
  4
+ * by the @authors tag. See the copyright.txt in the distribution for a
  5
+ * full listing of individual contributors.
  6
+ *
  7
+ * Licensed under the Apache License, Version 2.0 (the "License");
  8
+ * you may not use this file except in compliance with the License.
  9
+ * You may obtain a copy of the License at
  10
+ * http://www.apache.org/licenses/LICENSE-2.0
  11
+ * Unless required by applicable law or agreed to in writing, software
  12
+ * distributed under the License is distributed on an "AS IS" BASIS,
  13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14
+ * See the License for the specific language governing permissions and
  15
+ * limitations under the License.
  16
+ */
  17
+
  18
+package org.jboss.seam.faces.transaction;
  19
+
  20
+import javax.enterprise.event.Observes;
  21
+import javax.faces.event.AbortProcessingException;
  22
+import javax.faces.event.ExceptionQueuedEvent;
  23
+import javax.inject.Inject;
  24
+import javax.transaction.SystemException;
  25
+
  26
+import org.jboss.seam.transaction.DefaultTransaction;
  27
+import org.jboss.seam.transaction.SeamTransaction;
  28
+import org.jboss.solder.logging.Logger;
  29
+
  30
+/**
  31
+ * Simple observer to mark the current transaction for rollback when an unexpected exception occurs.
  32
+ * NOTE: Must be using Seam Transaction for this to work properly, otherwise it's skipped.
  33
+ *
  34
+ * @author <a href="http://community.jboss.org/people/LightGuard">Jason Porter</a>
  35
+ */
  36
+public class UnexpectedExceptionObserver {
  37
+
  38
+    @Inject
  39
+    private Logger log;
  40
+
  41
+    @Inject
  42
+    @DefaultTransaction
  43
+    private SeamTransaction tx;
  44
+
  45
+    public void processEvent(@Observes ExceptionQueuedEvent event) throws AbortProcessingException {
  46
+        try {
  47
+            log.debug("Marking transaction for rollback based on unexpected exception", event.getContext().getException());
  48
+            tx.setRollbackOnly();
  49
+        } catch (SystemException e) {
  50
+            log.warn("Could not mark transaction for rollback", e);
  51
+        }
  52
+    }
  53
+}

1 note on commit 3e2806d

Please sign in to comment.
Something went wrong with that request. Please try again.