[seam-commits] Seam SVN: r13546 - in modules/persistence/trunk/impl: src/main/java/org/jboss/seam/persistence/transaction and 1 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Tue Aug 3 03:51:12 EDT 2010
Author: swd847
Date: 2010-08-03 03:51:11 -0400 (Tue, 03 Aug 2010)
New Revision: 13546
Added:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/SeamApplicationException.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/util/ExceptionUtil.java
Modified:
modules/persistence/trunk/impl/pom.xml
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Work.java
Log:
add seam version of ApplicationException
Modified: modules/persistence/trunk/impl/pom.xml
===================================================================
--- modules/persistence/trunk/impl/pom.xml 2010-08-03 03:22:56 UTC (rev 13545)
+++ modules/persistence/trunk/impl/pom.xml 2010-08-03 07:51:11 UTC (rev 13546)
@@ -16,12 +16,12 @@
<properties>
<seam.version>3.0.0.b01</seam.version>
- <arquillian.version>1.0.0-SNAPSHOT</arquillian.version>
+ <arquillian.version>1.0.0.Alpha3</arquillian.version>
<junit.version>4.8.1</junit.version>
<jboss.home>${env.JBOSS_HOME}</jboss.home>
<jboss.domain>default</jboss.domain>
<glassfish.version>3.0.1-b19</glassfish.version>
- <jboss-as-client.version>6.0.0-SNAPSHOT</jboss-as-client.version>
+ <jboss-as-client.version>6.0.0.20100721-M4</jboss-as-client.version>
<jboss-server-manager.version>1.0.3.GA</jboss-server-manager.version>
</properties>
@@ -136,7 +136,7 @@
</profile>
<profile>
- <id>jbossas-remote-60</id>
+ <id>jbossas-remote-6</id>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
@@ -144,13 +144,6 @@
<version>${arquillian.version}</version>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.jboss.spec</groupId>
- <artifactId>jboss-javaee-6.0</artifactId>
- <version>${jboss-javaee6-spec.version}</version>
- <type>pom</type>
- <scope>provided</scope>
- </dependency>
<!-- need for org.jnp.interfaces.NamingContextFactory -->
<dependency>
<groupId>org.jboss.jbossas</groupId>
Added: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/SeamApplicationException.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/SeamApplicationException.java (rev 0)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/SeamApplicationException.java 2010-08-03 07:51:11 UTC (rev 13546)
@@ -0,0 +1,32 @@
+package org.jboss.seam.persistence.transaction;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Seam Annotation for identifying an Exception class as an Application
+ * Exception, which does not cause a transaction rollback
+ *
+ */
+ at Target(ElementType.TYPE)
+ at Retention(RetentionPolicy.RUNTIME)
+ at Documented
+ at Inherited
+public @interface SeamApplicationException
+{
+ /**
+ * Indicates whether the application exception designation should apply to
+ * subclasses of the annotated exception class.
+ */
+ boolean inherited() default true;
+
+ /**
+ * Indicates whether the container should cause the transaction to rollback
+ * when the exception is thrown.
+ */
+ boolean rollback() default false;
+}
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Work.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Work.java 2010-08-03 03:22:56 UTC (rev 13545)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Work.java 2010-08-03 07:51:11 UTC (rev 13546)
@@ -21,9 +21,9 @@
*/
package org.jboss.seam.persistence.transaction;
-import javax.ejb.ApplicationException;
import javax.transaction.Status;
+import org.jboss.seam.persistence.util.ExceptionUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -77,7 +77,7 @@
{
if (newTransactionRequired && transaction.getStatus() != Status.STATUS_NO_TRANSACTION)
{
- if (isRollbackRequired(e, true))
+ if (ExceptionUtil.exceptionCausesRollback(e))
{
log.debug("rolling back transaction");
transaction.rollback();
@@ -88,7 +88,7 @@
transaction.commit();
}
}
- else if (transaction.getStatus() != Status.STATUS_NO_TRANSACTION && isRollbackRequired(e, true))
+ else if (transaction.getStatus() != Status.STATUS_NO_TRANSACTION && ExceptionUtil.exceptionCausesRollback(e))
{
transaction.setRollbackOnly();
}
@@ -96,19 +96,4 @@
}
}
- public static boolean isRollbackRequired(Exception e, boolean isJavaBean)
- {
- Class<? extends Exception> clazz = e.getClass();
- return (isSystemException(e, isJavaBean, clazz)) || (clazz.isAnnotationPresent(ApplicationException.class) && clazz.getAnnotation(ApplicationException.class).rollback());
- }
-
- private static boolean isSystemException(Exception e, boolean isJavaBean, Class<? extends Exception> clazz)
- {
- return isJavaBean && (e instanceof RuntimeException) && !clazz.isAnnotationPresent(ApplicationException.class);
- // &&
- // TODO: this is hackish, maybe just turn off RollackInterceptor for
- // @Converter/@Validator components
- // !JSF.VALIDATOR_EXCEPTION.isInstance(e) &&
- // !JSF.CONVERTER_EXCEPTION.isInstance(e);
- }
}
Added: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/util/ExceptionUtil.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/util/ExceptionUtil.java (rev 0)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/util/ExceptionUtil.java 2010-08-03 07:51:11 UTC (rev 13546)
@@ -0,0 +1,70 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.persistence.util;
+
+import java.lang.reflect.Method;
+
+import org.jboss.seam.persistence.transaction.SeamApplicationException;
+
+/**
+ * Utility class for dealing with application exceptions
+ *
+ * @author Stuart Douglas
+ *
+ */
+public class ExceptionUtil
+{
+
+ private ExceptionUtil()
+ {
+
+ }
+
+ public static boolean exceptionCausesRollback(Exception e)
+ {
+ boolean defaultRollback = false;
+ if (e instanceof RuntimeException)
+ {
+ defaultRollback = true;
+ }
+ Class<?> exClass = e.getClass();
+ if (exClass.isAnnotationPresent(SeamApplicationException.class))
+ {
+ SeamApplicationException sae = exClass.getAnnotation(SeamApplicationException.class);
+ return sae.rollback();
+ }
+ else if (exClass.isAnnotationPresent(EjbApi.APPLICATION_EXCEPTION))
+ {
+ Object ae = exClass.getAnnotation(EjbApi.APPLICATION_EXCEPTION);
+ try
+ {
+ Method rollback = EjbApi.APPLICATION_EXCEPTION.getMethod("rollback");
+ return (Boolean) rollback.invoke(ae);
+ }
+ catch (Exception ex)
+ {
+ throw new RuntimeException(ex);
+ }
+ }
+ return defaultRollback;
+ }
+}
More information about the seam-commits
mailing list