[jboss-cvs] JBossAS SVN: r72368 - in projects/ejb3/trunk: transactions and 24 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Apr 17 11:25:26 EDT 2008
Author: wolfc
Date: 2008-04-17 11:25:26 -0400 (Thu, 17 Apr 2008)
New Revision: 72368
Added:
projects/ejb3/trunk/transactions/
projects/ejb3/trunk/transactions/.classpath
projects/ejb3/trunk/transactions/.project
projects/ejb3/trunk/transactions/.settings/
projects/ejb3/trunk/transactions/.settings/org.eclipse.jdt.core.prefs
projects/ejb3/trunk/transactions/pom.xml
projects/ejb3/trunk/transactions/src/
projects/ejb3/trunk/transactions/src/main/
projects/ejb3/trunk/transactions/src/main/java/
projects/ejb3/trunk/transactions/src/main/java/org/
projects/ejb3/trunk/transactions/src/main/java/org/jboss/
projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/
projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/
projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/AbstractInterceptor.java
projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/BMTInterceptor.java
projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/Ejb3TxPolicy.java
projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/NullInterceptor.java
projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/TxInterceptor.java
projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/TxInterceptorFactory.java
projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/TxUtil.java
projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/UserTransactionImpl.java
projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/container/
projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/container/StatefulBeanContext.java
projects/ejb3/trunk/transactions/src/test/
projects/ejb3/trunk/transactions/src/test/java/
projects/ejb3/trunk/transactions/src/test/java/org/
projects/ejb3/trunk/transactions/src/test/java/org/jboss/
projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/
projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/
projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/
projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/bmt/
projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/bmt/StatefulBMTBean.java
projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/bmt/unit/
projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/bmt/unit/BMTUnitTestCase.java
projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/
projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/AspectDeployment.java
projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/SimpleClassLoaderDeployer.java
projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/SimpleContainer.java
projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/SimpleTransactionService.java
projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/StatefulBeanContext.java
projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/StatefulContainer.java
projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/StatefulContainerMethodInvocation.java
projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/StatefulInstanceInterceptor.java
projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/instance/
projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/instance/InstanceTest.java
projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/instance/InstanceTestBean.java
projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/instance/unit/
projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/instance/unit/InstanceTestCase.java
projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/mc/
projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/mc/UnitTestBootstrap.java
projects/ejb3/trunk/transactions/src/test/resources/
projects/ejb3/trunk/transactions/src/test/resources/instance/
projects/ejb3/trunk/transactions/src/test/resources/instance/beans.xml
projects/ejb3/trunk/transactions/src/test/resources/instance/jboss-aop.xml
projects/ejb3/trunk/transactions/src/test/resources/jndi.properties
projects/ejb3/trunk/transactions/src/test/resources/log4j.xml
Removed:
projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/BMTInterceptor.java
projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/Ejb3TxPolicy.java
projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/NullInterceptor.java
projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/TxInterceptor.java
projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/TxInterceptorFactory.java
projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/TxUtil.java
projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/UserTransactionImpl.java
Log:
EJBTHREE-1299: added transactions component and unit test
Property changes on: projects/ejb3/trunk/transactions
___________________________________________________________________
Name: svn:ignore
+ target
eclipse-target
Added: projects/ejb3/trunk/transactions/.classpath
===================================================================
--- projects/ejb3/trunk/transactions/.classpath (rev 0)
+++ projects/ejb3/trunk/transactions/.classpath 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" output="eclipse-target/tests-classes" path="src/test/java"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry excluding="**/*.java" kind="src" output="eclipse-target/tests-classes" path="src/test/resources"/>
+ <classpathentry kind="output" path="eclipse-target/classes"/>
+</classpath>
Added: projects/ejb3/trunk/transactions/.project
===================================================================
--- projects/ejb3/trunk/transactions/.project (rev 0)
+++ projects/ejb3/trunk/transactions/.project 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>jboss-ejb3-transactions</name>
+ <comment>The JBoss EJB 3 Transactions component implements all functionality
+ specified in Chapter 13 (Support for Transactions) of the EJB 3.0
+ specification.</comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ </natures>
+</projectDescription>
Added: projects/ejb3/trunk/transactions/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- projects/ejb3/trunk/transactions/.settings/org.eclipse.jdt.core.prefs (rev 0)
+++ projects/ejb3/trunk/transactions/.settings/org.eclipse.jdt.core.prefs 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,6 @@
+#Tue Apr 15 15:17:02 CEST 2008
+eclipse.preferences.version=1
+instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.source=1.5
Added: projects/ejb3/trunk/transactions/pom.xml
===================================================================
--- projects/ejb3/trunk/transactions/pom.xml (rev 0)
+++ projects/ejb3/trunk/transactions/pom.xml 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,158 @@
+<!--
+ vi:ts=2:sw=2:expandtab
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-build</artifactId>
+ <version>0.13.1-SNAPSHOT</version>
+ <relativePath>../build/pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>jboss-ejb3-transactions</artifactId>
+ <version>0.13.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <name>JBoss EJB 3.0 Transactions</name>
+ <url>http://www.jboss.org</url>
+ <description>
+ The JBoss EJB 3 Transactions component implements all functionality
+ specified in Chapter 13 (Support for Transactions) of the EJB 3.0
+ specification.
+ </description>
+
+ <dependencies>
+ <!-- Internal -->
+ <dependency>
+ <groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-metadata</artifactId>
+ <version>0.12.1-SNAPSHOT</version>
+ </dependency>
+
+ <!-- External -->
+ <dependency>
+ <groupId>jboss.aop</groupId>
+ <artifactId>jboss-aop-deployer-jdk50</artifactId>
+ <version>2.0.0.CR8</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-spi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-transaction-spi</artifactId>
+ <version>5.0.0.Beta4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jnpserver</artifactId>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-common-core</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.metadata</groupId>
+ <artifactId>jboss-metadata</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.aop</groupId>
+ <artifactId>jboss-aop</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.aspects</groupId>
+ <artifactId>jboss-transaction-aspects</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.deployers</groupId>
+ <artifactId>jboss-deployers-vfs</artifactId>
+ <version>2.0.0.Beta14</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.deployers</groupId>
+ <artifactId>jboss-deployers-vfs-spi</artifactId>
+ <version>2.0.0.Beta14</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-cache</artifactId>
+ <version>0.13.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-ext-api-impl</artifactId>
+ <version>0.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-interceptors</artifactId>
+ <version>0.13.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.javaee</groupId>
+ <artifactId>jboss-ejb-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-kernel</artifactId>
+ <version>2.0.0.Beta13</version>
+ <scope>test</scope>
+ </dependency>
+ <!--
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-managed</artifactId>
+ <version>2.0.0.Beta10</version>
+ <scope>test</scope>
+ </dependency>
+ -->
+ <dependency>
+ <groupId>jboss.jbossts</groupId>
+ <artifactId>jbossjta</artifactId>
+ <version>4.3.0.GA</version>
+ <scope>test</scope>
+ </dependency>
+ <!-- For Eclipse Maven 2 Plugin -->
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-reflect</artifactId>
+ <version>2.0.0.Beta12</version>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- For Arjuna / JBoss Transaction -->
+ <dependency>
+ <groupId>apache-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.1.0.jboss</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>oswego-concurrent</groupId>
+ <artifactId>concurrent</artifactId>
+ <version>1.3.4-jboss-update1</version>
+ </dependency>
+ <dependency>
+ <groupId>jboss.jbossts</groupId>
+ <artifactId>jbossts-common</artifactId>
+ <version>4.3.0.GA</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Copied: projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx (from rev 72157, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/tx)
Added: projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/AbstractInterceptor.java
===================================================================
--- projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/AbstractInterceptor.java (rev 0)
+++ projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/AbstractInterceptor.java 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.tx;
+
+import java.lang.annotation.Annotation;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.ejb3.interceptors.aop.ExtendedAdvisorHelper;
+import org.jboss.ejb3.interceptors.container.AbstractContainer;
+
+/**
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public abstract class AbstractInterceptor implements Interceptor
+{
+ protected <C> C getContainer(Invocation invocation)
+ {
+ return (C) AbstractContainer.getContainer(invocation.getAdvisor());
+ }
+
+ public final String getName()
+ {
+ return getClass().getName();
+ }
+
+ protected static <T extends Annotation> T resolveAnnotation(Invocation invocation, Class<?> cls, Class<T> annotationType)
+ {
+ return ExtendedAdvisorHelper.getExtendedAdvisor(invocation.getAdvisor(), invocation.getTargetObject()).resolveAnnotation(cls, annotationType);
+ }
+}
Deleted: projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/BMTInterceptor.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/tx/BMTInterceptor.java 2008-04-14 10:07:06 UTC (rev 72157)
+++ projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/BMTInterceptor.java 2008-04-17 15:25:26 UTC (rev 72368)
@@ -1,223 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.ejb3.tx;
-
-import javax.ejb.EJBException;
-import javax.transaction.Status;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
-import org.jboss.aop.joinpoint.Invocation;
-import org.jboss.aop.util.PayloadKey;
-import org.jboss.ejb3.Container;
-import org.jboss.ejb3.EJBContainerInvocation;
-import org.jboss.ejb3.aop.AbstractInterceptor;
-import org.jboss.ejb3.stateful.StatefulBeanContext;
-import org.jboss.logging.Logger;
-import org.jboss.tm.TxUtils;
-
-/**
- * Comment
- *
- * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @author <a href="mailto:osh at sparre.dk">Ole Husgaard</a>
- * @version $Revision$
- */
-public class BMTInterceptor extends AbstractInterceptor
-{
- private TransactionManager tm;
- private boolean isStateless;
- protected static Logger log = Logger.getLogger(BMTInterceptor.class);
-
- public BMTInterceptor(TransactionManager tm, boolean stateless)
- {
- this.tm = tm;
- isStateless = stateless;
- }
-
-
- public String getName()
- {
- return BMTInterceptor.class.getName();
- }
-
-
-
- public Object handleStateless(Invocation invocation) throws Throwable
- {
- Container container = getEJBContainer(invocation);
- boolean exceptionThrown = false;
- try
- {
- return invocation.invokeNext();
- }
- catch (Exception ex)
- {
- exceptionThrown = true;
- checkStatelessDone(container, ex);
- throw ex;
- }
- finally
- {
- try
- {
- if (!exceptionThrown) checkStatelessDone(container, null);
- }
- finally
- {
- tm.suspend();
- }
- }
- }
-
- public Object handleStateful(Invocation invocation) throws Throwable
- {
- EJBContainerInvocation ejb = (EJBContainerInvocation)invocation;
- Container container = getEJBContainer(invocation);
-
- StatefulBeanContext ctx = (StatefulBeanContext)ejb.getBeanContext();
- Transaction tx = (Transaction)ctx.getMetaData().getMetaData("TX", "TX");
- if (tx != null)
- {
- ctx.getMetaData().addMetaData("TX", "TX", null, PayloadKey.TRANSIENT);
- tm.resume(tx);
- }
- try
- {
- return invocation.invokeNext();
- }
- finally
- {
- checkBadStateful(container);
- Transaction newTx = tm.getTransaction();
- if (newTx != null)
- {
- ctx.getMetaData().addMetaData("TX", "TX", newTx, PayloadKey.TRANSIENT);
- tm.suspend();
- }
- else
- {
- ctx.getMetaData().addMetaData("TX", "TX", null, PayloadKey.TRANSIENT);
- }
- }
- }
-
- public Object invoke(Invocation invocation) throws Throwable
- {
- Transaction oldTx = tm.getTransaction();
- if (oldTx != null) tm.suspend();
-
- try
- {
- if (isStateless) return handleStateless(invocation);
- else return handleStateful(invocation);
- }
- finally
- {
- if (oldTx != null) tm.resume(oldTx);
- }
-
-
- }
-
- private void checkStatelessDone(Container container, Exception ex)
- {
- int status = Status.STATUS_NO_TRANSACTION;
-
- try
- {
- status = tm.getStatus();
- }
- catch (SystemException sex)
- {
- log.error("Failed to get status", sex);
- }
-
- switch (status)
- {
- case Status.STATUS_ACTIVE :
- case Status.STATUS_COMMITTING :
- case Status.STATUS_MARKED_ROLLBACK :
- case Status.STATUS_PREPARING :
- case Status.STATUS_ROLLING_BACK :
- try
- {
- tm.rollback();
- }
- catch (Exception sex)
- {
- log.error("Failed to rollback", sex);
- }
- // fall through...
- case Status.STATUS_PREPARED :
- String msg = "Application error: BMT stateless bean " + container.getEjbName()
- + " should complete transactions before" + " returning (ejb1.1 spec, 11.6.1)";
- log.error(msg);
-
- // the instance interceptor will discard the instance
- if (ex != null)
- {
- if (ex instanceof EJBException)
- throw (EJBException)ex;
- else
- throw new EJBException(msg, ex);
- }
- else throw new EJBException(msg);
- }
- }
-
- private void checkBadStateful(Container container)
- {
- int status = Status.STATUS_NO_TRANSACTION;
-
- try
- {
- status = tm.getStatus();
- }
- catch (SystemException ex)
- {
- log.error("Failed to get status", ex);
- }
-
- switch (status)
- {
- case Status.STATUS_COMMITTING :
- case Status.STATUS_MARKED_ROLLBACK :
- case Status.STATUS_PREPARING :
- case Status.STATUS_ROLLING_BACK :
- try
- {
- tm.rollback();
- }
- catch (Exception ex)
- {
- log.error("Failed to rollback", ex);
- }
- String msg = "BMT stateful bean '" + container.getEjbName()
- + "' did not complete user transaction properly status=" + TxUtils.getStatusAsString(status);
- log.error(msg);
- }
- }
-
-
-}
Copied: projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/BMTInterceptor.java (from rev 72339, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/tx/BMTInterceptor.java)
===================================================================
--- projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/BMTInterceptor.java (rev 0)
+++ projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/BMTInterceptor.java 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,212 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.tx;
+
+import javax.ejb.EJBException;
+import javax.transaction.Status;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aop.util.PayloadKey;
+import org.jboss.ejb3.interceptors.container.ContainerMethodInvocation;
+import org.jboss.ejb3.tx.container.StatefulBeanContext;
+import org.jboss.logging.Logger;
+import org.jboss.tm.TxUtils;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @author <a href="mailto:osh at sparre.dk">Ole Husgaard</a>
+ * @version $Revision$
+ */
+public class BMTInterceptor extends AbstractInterceptor
+{
+ private TransactionManager tm;
+ private boolean isStateless;
+ protected static Logger log = Logger.getLogger(BMTInterceptor.class);
+
+ public BMTInterceptor(TransactionManager tm, boolean stateless)
+ {
+ this.tm = tm;
+ isStateless = stateless;
+ }
+
+ public Object handleStateless(Invocation invocation) throws Throwable
+ {
+ String ejbName = invocation.getAdvisor().getName();
+ boolean exceptionThrown = false;
+ try
+ {
+ return invocation.invokeNext();
+ }
+ catch (Exception ex)
+ {
+ exceptionThrown = true;
+ checkStatelessDone(ejbName, ex);
+ throw ex;
+ }
+ finally
+ {
+ try
+ {
+ if (!exceptionThrown) checkStatelessDone(ejbName, null);
+ }
+ finally
+ {
+ tm.suspend();
+ }
+ }
+ }
+
+ public Object handleStateful(Invocation invocation) throws Throwable
+ {
+ StatefulBeanContext<?> ctx = (StatefulBeanContext<?>) ContainerMethodInvocation.getContainerMethodInvocation(invocation).getBeanContext();
+ String ejbName = invocation.getAdvisor().getName();
+
+ Transaction tx = (Transaction)ctx.getMetaData().getMetaData("TX", "TX");
+ if (tx != null)
+ {
+ ctx.getMetaData().addMetaData("TX", "TX", null, PayloadKey.TRANSIENT);
+ tm.resume(tx);
+ }
+ try
+ {
+ return invocation.invokeNext();
+ }
+ finally
+ {
+ checkBadStateful(ejbName);
+ Transaction newTx = tm.getTransaction();
+ if (newTx != null)
+ {
+ ctx.getMetaData().addMetaData("TX", "TX", newTx, PayloadKey.TRANSIENT);
+ tm.suspend();
+ }
+ else
+ {
+ ctx.getMetaData().addMetaData("TX", "TX", null, PayloadKey.TRANSIENT);
+ }
+ }
+ }
+
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ Transaction oldTx = tm.getTransaction();
+ if (oldTx != null) tm.suspend();
+
+ try
+ {
+ if (isStateless) return handleStateless(invocation);
+ else return handleStateful(invocation);
+ }
+ finally
+ {
+ if (oldTx != null) tm.resume(oldTx);
+ }
+
+
+ }
+
+ private void checkStatelessDone(String ejbName, Exception ex)
+ {
+ int status = Status.STATUS_NO_TRANSACTION;
+
+ try
+ {
+ status = tm.getStatus();
+ }
+ catch (SystemException sex)
+ {
+ log.error("Failed to get status", sex);
+ }
+
+ switch (status)
+ {
+ case Status.STATUS_ACTIVE :
+ case Status.STATUS_COMMITTING :
+ case Status.STATUS_MARKED_ROLLBACK :
+ case Status.STATUS_PREPARING :
+ case Status.STATUS_ROLLING_BACK :
+ try
+ {
+ tm.rollback();
+ }
+ catch (Exception sex)
+ {
+ log.error("Failed to rollback", sex);
+ }
+ // fall through...
+ case Status.STATUS_PREPARED :
+ String msg = "Application error: BMT stateless bean " + ejbName
+ + " should complete transactions before" + " returning (ejb1.1 spec, 11.6.1)";
+ log.error(msg);
+
+ // the instance interceptor will discard the instance
+ if (ex != null)
+ {
+ if (ex instanceof EJBException)
+ throw (EJBException)ex;
+ else
+ throw new EJBException(msg, ex);
+ }
+ else throw new EJBException(msg);
+ }
+ }
+
+ private void checkBadStateful(String ejbName)
+ {
+ int status = Status.STATUS_NO_TRANSACTION;
+
+ try
+ {
+ status = tm.getStatus();
+ }
+ catch (SystemException ex)
+ {
+ log.error("Failed to get status", ex);
+ }
+
+ switch (status)
+ {
+ case Status.STATUS_COMMITTING :
+ case Status.STATUS_MARKED_ROLLBACK :
+ case Status.STATUS_PREPARING :
+ case Status.STATUS_ROLLING_BACK :
+ try
+ {
+ tm.rollback();
+ }
+ catch (Exception ex)
+ {
+ log.error("Failed to rollback", ex);
+ }
+ String msg = "BMT stateful bean '" + ejbName
+ + "' did not complete user transaction properly status=" + TxUtils.getStatusAsString(status);
+ log.error(msg);
+ }
+ }
+
+
+}
Deleted: projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/Ejb3TxPolicy.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/tx/Ejb3TxPolicy.java 2008-04-14 10:07:06 UTC (rev 72157)
+++ projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/Ejb3TxPolicy.java 2008-04-17 15:25:26 UTC (rev 72368)
@@ -1,124 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.ejb3.tx;
-
-import java.rmi.RemoteException;
-
-import javax.ejb.ApplicationException;
-import javax.ejb.EJBException;
-import javax.ejb.EJBTransactionRequiredException;
-import javax.ejb.EJBTransactionRolledbackException;
-import javax.transaction.Transaction;
-
-import org.jboss.aop.joinpoint.Invocation;
-import org.jboss.aop.joinpoint.MethodInvocation;
-
-/**
- * Comment
- *
- * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision$
- */
-public class Ejb3TxPolicy extends org.jboss.aspects.tx.TxPolicy
-{
- public void throwMandatory(Invocation invocation)
- {
- throw new EJBTransactionRequiredException(((MethodInvocation) invocation).getActualMethod().toString());
- }
-
- public void handleExceptionInOurTx(Invocation invocation, Throwable t, Transaction tx) throws Throwable
- {
- ApplicationException ae = TxUtil.getApplicationException(t.getClass(), invocation);
- if (ae != null)
- {
- if (ae.rollback()) setRollbackOnly(tx);
- throw t;
- }
-
- // if it's neither EJBException nor RemoteException
- if(!(t instanceof EJBException || t instanceof RemoteException))
- {
- // errors and unchecked are wrapped into EJBException
- if(t instanceof Error)
- {
- t = new EJBException(formatException("Unexpected Error", t));
- }
- else if (t instanceof RuntimeException)
- {
- t = new EJBException((Exception)t);
- }
- else
- {
- // an application exception
- throw t;
- }
- }
-
- setRollbackOnly(tx);
- throw t;
- }
-
- public void handleInCallerTx(Invocation invocation, Throwable t, Transaction tx) throws Throwable
- {
- ApplicationException ae = TxUtil.getApplicationException(t.getClass(), invocation);
-
- if (ae != null)
- {
- if (ae.rollback()) setRollbackOnly(tx);
- throw t;
- }
-
- // if it's not EJBTransactionRolledbackException
- if(!(t instanceof EJBTransactionRolledbackException))
- {
- if(t instanceof Error)
- {
- t = new EJBTransactionRolledbackException(formatException("Unexpected Error", t));
- }
- else if(t instanceof RuntimeException || t instanceof RemoteException)
- {
- t = new EJBTransactionRolledbackException(t.getMessage(), (Exception) t);
- }
- else // application exception
- {
- throw t;
- }
- }
-
- setRollbackOnly(tx);
- log.error(t);
- throw t;
- }
-
- private String formatException(String msg, Throwable t)
- {
- java.io.StringWriter sw = new java.io.StringWriter();
- java.io.PrintWriter pw = new java.io.PrintWriter(sw);
- if (msg != null)
- pw.println(msg);
- if (t != null)
- {
- t.printStackTrace(pw);
- } // end of if ()
- return sw.toString();
- }
-}
Copied: projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/Ejb3TxPolicy.java (from rev 72339, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/tx/Ejb3TxPolicy.java)
===================================================================
--- projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/Ejb3TxPolicy.java (rev 0)
+++ projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/Ejb3TxPolicy.java 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,124 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.tx;
+
+import java.rmi.RemoteException;
+
+import javax.ejb.ApplicationException;
+import javax.ejb.EJBException;
+import javax.ejb.EJBTransactionRequiredException;
+import javax.ejb.EJBTransactionRolledbackException;
+import javax.transaction.Transaction;
+
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aop.joinpoint.MethodInvocation;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public class Ejb3TxPolicy extends org.jboss.aspects.tx.TxPolicy
+{
+ public void throwMandatory(Invocation invocation)
+ {
+ throw new EJBTransactionRequiredException(((MethodInvocation) invocation).getActualMethod().toString());
+ }
+
+ public void handleExceptionInOurTx(Invocation invocation, Throwable t, Transaction tx) throws Throwable
+ {
+ ApplicationException ae = TxUtil.getApplicationException(t.getClass(), invocation);
+ if (ae != null)
+ {
+ if (ae.rollback()) setRollbackOnly(tx);
+ throw t;
+ }
+
+ // if it's neither EJBException nor RemoteException
+ if(!(t instanceof EJBException || t instanceof RemoteException))
+ {
+ // errors and unchecked are wrapped into EJBException
+ if(t instanceof Error)
+ {
+ t = new EJBException(formatException("Unexpected Error", t));
+ }
+ else if (t instanceof RuntimeException)
+ {
+ t = new EJBException((Exception)t);
+ }
+ else
+ {
+ // an application exception
+ throw t;
+ }
+ }
+
+ setRollbackOnly(tx);
+ throw t;
+ }
+
+ public void handleInCallerTx(Invocation invocation, Throwable t, Transaction tx) throws Throwable
+ {
+ ApplicationException ae = TxUtil.getApplicationException(t.getClass(), invocation);
+
+ if (ae != null)
+ {
+ if (ae.rollback()) setRollbackOnly(tx);
+ throw t;
+ }
+
+ // if it's not EJBTransactionRolledbackException
+ if(!(t instanceof EJBTransactionRolledbackException))
+ {
+ if(t instanceof Error)
+ {
+ t = new EJBTransactionRolledbackException(formatException("Unexpected Error", t));
+ }
+ else if(t instanceof RuntimeException || t instanceof RemoteException)
+ {
+ t = new EJBTransactionRolledbackException(t.getMessage(), (Exception) t);
+ }
+ else // application exception
+ {
+ throw t;
+ }
+ }
+
+ setRollbackOnly(tx);
+ log.error(t);
+ throw t;
+ }
+
+ private String formatException(String msg, Throwable t)
+ {
+ java.io.StringWriter sw = new java.io.StringWriter();
+ java.io.PrintWriter pw = new java.io.PrintWriter(sw);
+ if (msg != null)
+ pw.println(msg);
+ if (t != null)
+ {
+ t.printStackTrace(pw);
+ } // end of if ()
+ return sw.toString();
+ }
+}
Deleted: projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/NullInterceptor.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/tx/NullInterceptor.java 2008-04-14 10:07:06 UTC (rev 72157)
+++ projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/NullInterceptor.java 2008-04-17 15:25:26 UTC (rev 72368)
@@ -1,44 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.ejb3.tx;
-
-import org.jboss.aop.advice.Interceptor;
-import org.jboss.aop.joinpoint.Invocation;
-
-/**
- * Comment
- *
- * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision$
- */
-public class NullInterceptor implements Interceptor
-{
- public String getName()
- {
- return NullInterceptor.class.getName();
- }
-
- public Object invoke(Invocation invocation) throws Throwable
- {
- return invocation.invokeNext();
- }
-}
Copied: projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/NullInterceptor.java (from rev 72339, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/tx/NullInterceptor.java)
===================================================================
--- projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/NullInterceptor.java (rev 0)
+++ projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/NullInterceptor.java 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.tx;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public class NullInterceptor implements Interceptor
+{
+ public String getName()
+ {
+ return NullInterceptor.class.getName();
+ }
+
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ return invocation.invokeNext();
+ }
+}
Deleted: projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/TxInterceptor.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/tx/TxInterceptor.java 2008-04-14 10:07:06 UTC (rev 72157)
+++ projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/TxInterceptor.java 2008-04-17 15:25:26 UTC (rev 72368)
@@ -1,147 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2007, Red Hat Middleware LLC, and individual contributors as indicated
- * 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.ejb3.tx;
-
-import javax.ejb.ApplicationException;
-import javax.ejb.EJBException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
-import org.jboss.aop.joinpoint.MethodInvocation;
-import org.jboss.aop.joinpoint.Invocation;
-import org.jboss.aspects.tx.TxPolicy;
-import org.jboss.logging.Logger;
-
-/**
- * Ensure the correct exceptions are thrown based on both caller
- * transactional context and supported Transaction Attribute Type
- *
- * EJB3 13.6.2.6
- * EJB3 Core Specification 14.3.1 Table 14
- *
- * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
- * @author <a href="mailto:andrew.rubinger at redhat.com">ALR</a>
- * @version $Revision: $
- */
-public class TxInterceptor extends org.jboss.aspects.tx.TxInterceptor
-{
- private static final Logger log = Logger.getLogger(TxInterceptor.class);
-
- public static class Never extends org.jboss.aspects.tx.TxInterceptor.Never
- {
- public Never(TransactionManager tm, TxPolicy policy)
- {
- super(tm, policy);
- }
-
- @Override
- public Object invoke(Invocation invocation) throws Throwable
- {
- if (tm.getTransaction() != null)
- {
- throw new EJBException("Transaction present on server in Never call (EJB3 13.6.2.6)");
- }
- return policy.invokeInNoTx(invocation);
- }
- }
-
- public static class NotSupported extends org.jboss.aspects.tx.TxInterceptor.NotSupported
- {
- public NotSupported(TransactionManager tm, TxPolicy policy)
- {
- super(tm, policy);
- }
-
- public NotSupported(TransactionManager tm, TxPolicy policy, int timeout)
- {
- super(tm, policy, timeout);
- }
-
- /**
- * EJBTHREE-1082
- * EJB3 Core Specification 14.3.1 Table 14
- */
- @Override
- public Object invoke(Invocation invocation) throws Throwable
- {
- Transaction tx = tm.getTransaction();
- if (tx != null)
- {
- tm.suspend();
- try
- {
- return policy.invokeInNoTx(invocation);
- }
- catch (Exception e)
- {
- // If application exception was thrown, rethrow
- if (e.getClass().getAnnotation(ApplicationException.class) != null)
- {
- throw e;
- }
- // Otherwise wrap in EJBException
- else
- {
- throw new EJBException(e);
- }
- }
- finally
- {
- tm.resume(tx);
- }
- }
- else
- {
- return policy.invokeInNoTx(invocation);
- }
- }
- }
-
- public static class Mandatory extends org.jboss.aspects.tx.TxInterceptor.Mandatory
- {
- public Mandatory(TransactionManager tm, TxPolicy policy)
- {
- this(tm, policy, -1);
- }
-
- public Mandatory(TransactionManager tm, TxPolicy policy, int timeout)
- {
- super(tm, policy, timeout);
- }
-
- public String getName()
- {
- return this.getClass().getName();
- }
-
- public Object invoke(Invocation invocation) throws Throwable
- {
- Transaction tx = tm.getTransaction();
- if (tx == null)
- {
- policy.throwMandatory(invocation);
- }
- return policy.invokeInCallerTx(invocation, tx);
- }
-
- }
-}
Copied: projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/TxInterceptor.java (from rev 72339, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/tx/TxInterceptor.java)
===================================================================
--- projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/TxInterceptor.java (rev 0)
+++ projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/TxInterceptor.java 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,147 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors as indicated
+ * 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.ejb3.tx;
+
+import javax.ejb.ApplicationException;
+import javax.ejb.EJBException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+import org.jboss.aop.joinpoint.MethodInvocation;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aspects.tx.TxPolicy;
+import org.jboss.logging.Logger;
+
+/**
+ * Ensure the correct exceptions are thrown based on both caller
+ * transactional context and supported Transaction Attribute Type
+ *
+ * EJB3 13.6.2.6
+ * EJB3 Core Specification 14.3.1 Table 14
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @author <a href="mailto:andrew.rubinger at redhat.com">ALR</a>
+ * @version $Revision: $
+ */
+public class TxInterceptor extends org.jboss.aspects.tx.TxInterceptor
+{
+ private static final Logger log = Logger.getLogger(TxInterceptor.class);
+
+ public static class Never extends org.jboss.aspects.tx.TxInterceptor.Never
+ {
+ public Never(TransactionManager tm, TxPolicy policy)
+ {
+ super(tm, policy);
+ }
+
+ @Override
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ if (tm.getTransaction() != null)
+ {
+ throw new EJBException("Transaction present on server in Never call (EJB3 13.6.2.6)");
+ }
+ return policy.invokeInNoTx(invocation);
+ }
+ }
+
+ public static class NotSupported extends org.jboss.aspects.tx.TxInterceptor.NotSupported
+ {
+ public NotSupported(TransactionManager tm, TxPolicy policy)
+ {
+ super(tm, policy);
+ }
+
+ public NotSupported(TransactionManager tm, TxPolicy policy, int timeout)
+ {
+ super(tm, policy, timeout);
+ }
+
+ /**
+ * EJBTHREE-1082
+ * EJB3 Core Specification 14.3.1 Table 14
+ */
+ @Override
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ Transaction tx = tm.getTransaction();
+ if (tx != null)
+ {
+ tm.suspend();
+ try
+ {
+ return policy.invokeInNoTx(invocation);
+ }
+ catch (Exception e)
+ {
+ // If application exception was thrown, rethrow
+ if (e.getClass().getAnnotation(ApplicationException.class) != null)
+ {
+ throw e;
+ }
+ // Otherwise wrap in EJBException
+ else
+ {
+ throw new EJBException(e);
+ }
+ }
+ finally
+ {
+ tm.resume(tx);
+ }
+ }
+ else
+ {
+ return policy.invokeInNoTx(invocation);
+ }
+ }
+ }
+
+ public static class Mandatory extends org.jboss.aspects.tx.TxInterceptor.Mandatory
+ {
+ public Mandatory(TransactionManager tm, TxPolicy policy)
+ {
+ this(tm, policy, -1);
+ }
+
+ public Mandatory(TransactionManager tm, TxPolicy policy, int timeout)
+ {
+ super(tm, policy, timeout);
+ }
+
+ public String getName()
+ {
+ return this.getClass().getName();
+ }
+
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ Transaction tx = tm.getTransaction();
+ if (tx == null)
+ {
+ policy.throwMandatory(invocation);
+ }
+ return policy.invokeInCallerTx(invocation, tx);
+ }
+
+ }
+}
Deleted: projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/TxInterceptorFactory.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/tx/TxInterceptorFactory.java 2008-04-14 10:07:06 UTC (rev 72157)
+++ projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/TxInterceptorFactory.java 2008-04-17 15:25:26 UTC (rev 72368)
@@ -1,141 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.ejb3.tx;
-
-import java.lang.reflect.Method;
-
-import javax.ejb.TransactionAttribute;
-import javax.ejb.TransactionAttributeType;
-import javax.ejb.TransactionManagementType;
-
-import org.jboss.aop.Advisor;
-import org.jboss.aop.joinpoint.Joinpoint;
-import org.jboss.aop.joinpoint.MethodJoinpoint;
-import org.jboss.ejb3.EJBContainer;
-import org.jboss.ejb3.annotation.TransactionTimeout;
-import org.jboss.ejb3.stateful.StatefulContainer;
-import org.jboss.logging.Logger;
-
-/**
- * This interceptor handles transactions for AOP
- *
- * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision$
- */
-public class TxInterceptorFactory extends org.jboss.aspects.tx.TxInterceptorFactory
-{
- @SuppressWarnings("unused")
- private static final Logger log = Logger.getLogger(TxInterceptorFactory.class);
-
- protected TransactionAttributeType getTxType(Advisor advisor, Joinpoint jp)
- {
- Method method = ((MethodJoinpoint) jp).getMethod();
- TransactionAttribute tx = (TransactionAttribute) advisor.resolveAnnotation(method, TransactionAttribute.class);
-
- if (tx == null)
- tx = (TransactionAttribute) advisor.resolveAnnotation(TransactionAttribute.class);
-
- TransactionAttributeType value = TransactionAttributeType.REQUIRED;
- if (tx != null && tx.value() != null)
- {
- value = tx.value();
- }
-
- return value;
- }
-
- protected int resolveTransactionTimeout(Advisor advisor, Method method)
- {
- TransactionTimeout annotation = (TransactionTimeout)advisor.resolveAnnotation(method, TransactionTimeout.class);
-
- if (annotation == null)
- annotation = (TransactionTimeout)advisor.resolveAnnotation(TransactionTimeout.class);
-
- if (annotation != null)
- {
- return annotation.value();
- }
-
- return -1;
- }
-
- protected void initializePolicy()
- {
- policy = new Ejb3TxPolicy();
- }
-
- public Object createPerJoinpoint(Advisor advisor, Joinpoint jp)
- {
- // We have to do this until AOP supports matching based on annotation attributes
- TransactionManagementType type = TxUtil.getTransactionManagementType(advisor);
- if (type == TransactionManagementType.BEAN)
- {
- // Must be a separate line (EJBContainer cannot be dereferenced)
- EJBContainer container = EJBContainer.getEJBContainer(advisor);
- return new BMTInterceptor(TxUtil.getTransactionManager(), !(container instanceof StatefulContainer));
- }
-
- Method method = ((MethodJoinpoint) jp).getMethod();
- int timeout = resolveTransactionTimeout(advisor, method);
-
- if (policy == null);
- super.initialize();
-
- TransactionAttributeType txType = getTxType(advisor, jp);
-
- if (txType.equals(TransactionAttributeType.NEVER))
- {
- // make sure we use the EJB3 interceptor, not the AOP one.
- return new TxInterceptor.Never(TxUtil.getTransactionManager(), policy);
- }
- else if (txType.equals(TransactionAttributeType.REQUIRED))
- {
- return new TxInterceptor.Required(TxUtil.getTransactionManager(), policy, timeout);
- }
- else if (txType.equals(TransactionAttributeType.REQUIRES_NEW))
- {
- return new TxInterceptor.RequiresNew(TxUtil.getTransactionManager(), policy, timeout);
- }
- else if(txType.equals(TransactionAttributeType.NOT_SUPPORTED))
- {
- return new TxInterceptor.NotSupported(TxUtil.getTransactionManager(), policy, timeout);
- }
- else if(txType.equals(TransactionAttributeType.MANDATORY))
- {
- return new TxInterceptor.Mandatory(TxUtil.getTransactionManager(), policy, timeout);
- }
- else if(txType.equals(TransactionAttributeType.SUPPORTS))
- {
- return new TxInterceptor.Supports(TxUtil.getTransactionManager(), policy, timeout);
- }
- else
- {
- Object interceptor = super.createPerJoinpoint(advisor, jp);
- return interceptor;
- }
- }
-
- public String getName()
- {
- return getClass().getName();
- }
-}
Copied: projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/TxInterceptorFactory.java (from rev 72339, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/tx/TxInterceptorFactory.java)
===================================================================
--- projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/TxInterceptorFactory.java (rev 0)
+++ projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/TxInterceptorFactory.java 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,141 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.tx;
+
+import java.lang.reflect.Method;
+
+import javax.ejb.Stateful;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+import javax.ejb.TransactionManagementType;
+
+import org.jboss.aop.Advisor;
+import org.jboss.aop.joinpoint.Joinpoint;
+import org.jboss.aop.joinpoint.MethodJoinpoint;
+import org.jboss.ejb3.annotation.TransactionTimeout;
+import org.jboss.logging.Logger;
+
+/**
+ * This interceptor handles transactions for AOP
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public class TxInterceptorFactory extends org.jboss.aspects.tx.TxInterceptorFactory
+{
+ @SuppressWarnings("unused")
+ private static final Logger log = Logger.getLogger(TxInterceptorFactory.class);
+
+ protected TransactionAttributeType getTxType(Advisor advisor, Joinpoint jp)
+ {
+ Method method = ((MethodJoinpoint) jp).getMethod();
+ TransactionAttribute tx = (TransactionAttribute) advisor.resolveAnnotation(method, TransactionAttribute.class);
+
+ if (tx == null)
+ tx = (TransactionAttribute) advisor.resolveAnnotation(TransactionAttribute.class);
+
+ TransactionAttributeType value = TransactionAttributeType.REQUIRED;
+ if (tx != null && tx.value() != null)
+ {
+ value = tx.value();
+ }
+
+ return value;
+ }
+
+ protected int resolveTransactionTimeout(Advisor advisor, Method method)
+ {
+ TransactionTimeout annotation = (TransactionTimeout)advisor.resolveAnnotation(method, TransactionTimeout.class);
+
+ if (annotation == null)
+ annotation = (TransactionTimeout)advisor.resolveAnnotation(TransactionTimeout.class);
+
+ if (annotation != null)
+ {
+ return annotation.value();
+ }
+
+ return -1;
+ }
+
+ protected void initializePolicy()
+ {
+ policy = new Ejb3TxPolicy();
+ }
+
+ public Object createPerJoinpoint(Advisor advisor, Joinpoint jp)
+ {
+ // We have to do this until AOP supports matching based on annotation attributes
+ TransactionManagementType type = TxUtil.getTransactionManagementType(advisor);
+ if (type == TransactionManagementType.BEAN)
+ {
+ // Must be a separate line (EJBContainer cannot be dereferenced)
+ boolean stateful = advisor.resolveAnnotation(Stateful.class) != null;
+ // Both MessageDriven and Stateless are stateless
+ return new BMTInterceptor(TxUtil.getTransactionManager(), !stateful);
+ }
+
+ Method method = ((MethodJoinpoint) jp).getMethod();
+ int timeout = resolveTransactionTimeout(advisor, method);
+
+ if (policy == null);
+ super.initialize();
+
+ TransactionAttributeType txType = getTxType(advisor, jp);
+
+ if (txType.equals(TransactionAttributeType.NEVER))
+ {
+ // make sure we use the EJB3 interceptor, not the AOP one.
+ return new TxInterceptor.Never(TxUtil.getTransactionManager(), policy);
+ }
+ else if (txType.equals(TransactionAttributeType.REQUIRED))
+ {
+ return new TxInterceptor.Required(TxUtil.getTransactionManager(), policy, timeout);
+ }
+ else if (txType.equals(TransactionAttributeType.REQUIRES_NEW))
+ {
+ return new TxInterceptor.RequiresNew(TxUtil.getTransactionManager(), policy, timeout);
+ }
+ else if(txType.equals(TransactionAttributeType.NOT_SUPPORTED))
+ {
+ return new TxInterceptor.NotSupported(TxUtil.getTransactionManager(), policy, timeout);
+ }
+ else if(txType.equals(TransactionAttributeType.MANDATORY))
+ {
+ return new TxInterceptor.Mandatory(TxUtil.getTransactionManager(), policy, timeout);
+ }
+ else if(txType.equals(TransactionAttributeType.SUPPORTS))
+ {
+ return new TxInterceptor.Supports(TxUtil.getTransactionManager(), policy, timeout);
+ }
+ else
+ {
+ Object interceptor = super.createPerJoinpoint(advisor, jp);
+ return interceptor;
+ }
+ }
+
+ public String getName()
+ {
+ return getClass().getName();
+ }
+}
Deleted: projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/TxUtil.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/tx/TxUtil.java 2008-04-14 10:07:06 UTC (rev 72157)
+++ projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/TxUtil.java 2008-04-17 15:25:26 UTC (rev 72368)
@@ -1,99 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.ejb3.tx;
-
-import javax.ejb.ApplicationException;
-import javax.ejb.TransactionManagement;
-import javax.ejb.TransactionManagementType;
-import javax.transaction.TransactionManager;
-
-import org.jboss.aop.Advisor;
-import org.jboss.aop.joinpoint.Invocation;
-import org.jboss.aop.joinpoint.MethodInvocation;
-import org.jboss.ejb3.Container;
-import org.jboss.ejb3.EJBContainer;
-import org.jboss.ejb3.annotation.impl.ApplicationExceptionImpl;
-import org.jboss.ejb3.aop.AbstractInterceptor;
-import org.jboss.metadata.ejb.jboss.JBossAssemblyDescriptorMetaData;
-import org.jboss.metadata.ejb.spec.ApplicationExceptionMetaData;
-import org.jboss.metadata.ejb.spec.ApplicationExceptionsMetaData;
-import org.jboss.tm.TransactionManagerLocator;
-
-/**
- * Comment
- *
- * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision$
- */
-public class TxUtil
-{
- public static TransactionManager getTransactionManager()
- {
- return TransactionManagerLocator.getInstance().locate();
- }
-
- public static TransactionManagementType getTransactionManagementType(Advisor advisor)
- {
- return getTransactionManagementType(EJBContainer.getEJBContainer(advisor));
- }
-
- @Deprecated
- public static TransactionManagementType getTransactionManagementType(Container container)
- {
- return getTransactionManagementType((EJBContainer) container);
- }
-
- public static TransactionManagementType getTransactionManagementType(EJBContainer container)
- {
- TransactionManagement transactionManagement = (TransactionManagement) container.getAnnotation(TransactionManagement.class);
- if (transactionManagement == null) return TransactionManagementType.CONTAINER;
- return transactionManagement.value();
- }
-
- public static ApplicationException getApplicationException(Class<?> exceptionClass, Invocation invocation)
- {
- MethodInvocation ejb = (MethodInvocation) invocation;
- EJBContainer container = AbstractInterceptor.getEJBContainer(invocation);
-
- // TODO: Wolf: refactor onto a unified metadata view
-
- if (exceptionClass.isAnnotationPresent(ApplicationException.class))
- return (ApplicationException)exceptionClass.getAnnotation(ApplicationException.class);
-
- JBossAssemblyDescriptorMetaData assembly = container.getAssemblyDescriptor();
-
- if (assembly != null)
- {
- ApplicationExceptionsMetaData exceptions = assembly.getApplicationExceptions();
- if (exceptions != null)
- {
- for(ApplicationExceptionMetaData exception : exceptions)
- {
- if (exception.getExceptionClass().equals(exceptionClass.getName()))
- return new ApplicationExceptionImpl(exception.isRollback());
- }
- }
-
- }
- return null;
- }
-}
Copied: projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/TxUtil.java (from rev 72339, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/tx/TxUtil.java)
===================================================================
--- projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/TxUtil.java (rev 0)
+++ projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/TxUtil.java 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.tx;
+
+import javax.ejb.ApplicationException;
+import javax.ejb.TransactionManagement;
+import javax.ejb.TransactionManagementType;
+import javax.transaction.TransactionManager;
+
+import org.jboss.aop.Advisor;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.tm.TransactionManagerLocator;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public class TxUtil
+{
+ public static TransactionManager getTransactionManager()
+ {
+ return TransactionManagerLocator.getInstance().locate();
+ }
+
+ public static TransactionManagementType getTransactionManagementType(Advisor advisor)
+ {
+ TransactionManagement transactionManagement = (TransactionManagement) advisor.resolveAnnotation(TransactionManagement.class);
+ if (transactionManagement == null) return TransactionManagementType.CONTAINER;
+ return transactionManagement.value();
+ }
+
+ public static ApplicationException getApplicationException(Class<?> exceptionClass, Invocation invocation)
+ {
+ return AbstractInterceptor.resolveAnnotation(invocation, exceptionClass, ApplicationException.class);
+ /*
+ MethodInvocation ejb = (MethodInvocation) invocation;
+ EJBContainer container = AbstractInterceptor.getEJBContainer(invocation);
+
+ // TODO: Wolf: refactor onto a unified metadata view
+
+ if (exceptionClass.isAnnotationPresent(ApplicationException.class))
+ return (ApplicationException)exceptionClass.getAnnotation(ApplicationException.class);
+
+ JBossAssemblyDescriptorMetaData assembly = container.getAssemblyDescriptor();
+
+ if (assembly != null)
+ {
+ ApplicationExceptionsMetaData exceptions = assembly.getApplicationExceptions();
+ if (exceptions != null)
+ {
+ for(ApplicationExceptionMetaData exception : exceptions)
+ {
+ if (exception.getExceptionClass().equals(exceptionClass.getName()))
+ return new ApplicationExceptionImpl(exception.isRollback());
+ }
+ }
+
+ }
+ return null;
+ */
+
+ }
+}
Deleted: projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/UserTransactionImpl.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/tx/UserTransactionImpl.java 2008-04-14 10:07:06 UTC (rev 72157)
+++ projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/UserTransactionImpl.java 2008-04-17 15:25:26 UTC (rev 72368)
@@ -1,130 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.ejb3.tx;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import javax.transaction.HeuristicMixedException;
-import javax.transaction.HeuristicRollbackException;
-import javax.transaction.NotSupportedException;
-import javax.transaction.RollbackException;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-import javax.transaction.UserTransaction;
-import org.jboss.logging.Logger;
-
-/**
- * Comment
- *
- * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision$
- */
-public final class UserTransactionImpl implements UserTransaction, java.io.Externalizable
-{
- private static final long serialVersionUID = 2403204397187452430L;
-
- protected static Logger log = Logger.getLogger(UserTransactionImpl.class);
-
- /**
- * Timeout value in seconds for new transactions started
- * by this bean instance.
- */
- private TransactionManager tm;
-
- public UserTransactionImpl()
- {
- if (log.isDebugEnabled())
- log.debug("new UserTx: " + this);
- this.tm = TxUtil.getTransactionManager();
- }
-
- public void begin()
- throws NotSupportedException, SystemException
- {
- // Start the transaction
- tm.begin();
-
- Transaction tx = tm.getTransaction();
- if (log.isDebugEnabled())
- log.debug("UserTx begin: " + tx);
-
- }
-
- public void commit()
- throws RollbackException, HeuristicMixedException, HeuristicRollbackException,
- SecurityException, IllegalStateException, SystemException
- {
- Transaction tx = tm.getTransaction();
- if (log.isDebugEnabled())
- log.debug("UserTx commit: " + tx);
-
- tm.commit();
- }
-
- public void rollback()
- throws IllegalStateException, SecurityException, SystemException
- {
- Transaction tx = tm.getTransaction();
- if (log.isDebugEnabled())
- log.debug("UserTx rollback: " + tx);
- tm.rollback();
- }
-
- public void setRollbackOnly()
- throws IllegalStateException, SystemException
- {
- Transaction tx = tm.getTransaction();
- if (log.isDebugEnabled())
- log.debug("UserTx setRollbackOnly: " + tx);
-
- tm.setRollbackOnly();
- }
-
- public int getStatus()
- throws SystemException
- {
- return tm.getStatus();
- }
-
- /**
- * Set the transaction timeout value for new transactions
- * started by this instance.
- */
- public void setTransactionTimeout(int seconds)
- throws SystemException
- {
- tm.setTransactionTimeout(seconds);
- }
-
- public void writeExternal(ObjectOutput out) throws IOException
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- {
- this.tm = TxUtil.getTransactionManager();
- }
-
-}
Copied: projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/UserTransactionImpl.java (from rev 72339, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/tx/UserTransactionImpl.java)
===================================================================
--- projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/UserTransactionImpl.java (rev 0)
+++ projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/UserTransactionImpl.java 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,130 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.tx;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import javax.transaction.UserTransaction;
+import org.jboss.logging.Logger;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public final class UserTransactionImpl implements UserTransaction, java.io.Externalizable
+{
+ private static final long serialVersionUID = 2403204397187452430L;
+
+ protected static Logger log = Logger.getLogger(UserTransactionImpl.class);
+
+ /**
+ * Timeout value in seconds for new transactions started
+ * by this bean instance.
+ */
+ private TransactionManager tm;
+
+ public UserTransactionImpl()
+ {
+ if (log.isDebugEnabled())
+ log.debug("new UserTx: " + this);
+ this.tm = TxUtil.getTransactionManager();
+ }
+
+ public void begin()
+ throws NotSupportedException, SystemException
+ {
+ // Start the transaction
+ tm.begin();
+
+ Transaction tx = tm.getTransaction();
+ if (log.isDebugEnabled())
+ log.debug("UserTx begin: " + tx);
+
+ }
+
+ public void commit()
+ throws RollbackException, HeuristicMixedException, HeuristicRollbackException,
+ SecurityException, IllegalStateException, SystemException
+ {
+ Transaction tx = tm.getTransaction();
+ if (log.isDebugEnabled())
+ log.debug("UserTx commit: " + tx);
+
+ tm.commit();
+ }
+
+ public void rollback()
+ throws IllegalStateException, SecurityException, SystemException
+ {
+ Transaction tx = tm.getTransaction();
+ if (log.isDebugEnabled())
+ log.debug("UserTx rollback: " + tx);
+ tm.rollback();
+ }
+
+ public void setRollbackOnly()
+ throws IllegalStateException, SystemException
+ {
+ Transaction tx = tm.getTransaction();
+ if (log.isDebugEnabled())
+ log.debug("UserTx setRollbackOnly: " + tx);
+
+ tm.setRollbackOnly();
+ }
+
+ public int getStatus()
+ throws SystemException
+ {
+ return tm.getStatus();
+ }
+
+ /**
+ * Set the transaction timeout value for new transactions
+ * started by this instance.
+ */
+ public void setTransactionTimeout(int seconds)
+ throws SystemException
+ {
+ tm.setTransactionTimeout(seconds);
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ this.tm = TxUtil.getTransactionManager();
+ }
+
+}
Added: projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/container/StatefulBeanContext.java
===================================================================
--- projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/container/StatefulBeanContext.java (rev 0)
+++ projects/ejb3/trunk/transactions/src/main/java/org/jboss/ejb3/tx/container/StatefulBeanContext.java 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.tx.container;
+
+import org.jboss.aop.metadata.SimpleMetaData;
+import org.jboss.ejb3.interceptors.container.BeanContext;
+
+/**
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface StatefulBeanContext<T> extends BeanContext<T>
+{
+ SimpleMetaData getMetaData();
+}
Added: projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/bmt/StatefulBMTBean.java
===================================================================
--- projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/bmt/StatefulBMTBean.java (rev 0)
+++ projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/bmt/StatefulBMTBean.java 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.test.tx.bmt;
+
+import javax.ejb.Stateful;
+import javax.ejb.TransactionManagement;
+import javax.ejb.TransactionManagementType;
+import javax.transaction.UserTransaction;
+
+import org.jboss.ejb3.tx.UserTransactionImpl;
+
+/**
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateful
+ at TransactionManagement(TransactionManagementType.BEAN)
+public class StatefulBMTBean
+{
+ private UserTransaction getUserTransaction()
+ {
+ // TODO: use the API
+ return new UserTransactionImpl();
+ }
+
+ public void normal() throws Exception
+ {
+ UserTransaction tx = getUserTransaction();
+
+ tx.begin();
+ try
+ {
+
+ }
+ finally
+ {
+ tx.rollback();
+ }
+ }
+}
Added: projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/bmt/unit/BMTUnitTestCase.java
===================================================================
--- projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/bmt/unit/BMTUnitTestCase.java (rev 0)
+++ projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/bmt/unit/BMTUnitTestCase.java 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.test.tx.bmt.unit;
+
+
+import java.net.URL;
+
+import org.jboss.ejb3.test.tx.bmt.StatefulBMTBean;
+import org.jboss.ejb3.test.tx.common.StatefulContainer;
+import org.jboss.ejb3.test.tx.mc.UnitTestBootstrap;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class BMTUnitTestCase
+{
+ private static UnitTestBootstrap bootstrap;
+
+ private static URL getResource(String name)
+ {
+ return Thread.currentThread().getContextClassLoader().getResource(name);
+ }
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Throwable
+ {
+ bootstrap = new UnitTestBootstrap();
+ bootstrap.deploy(getResource("instance/beans.xml"));
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception
+ {
+ if(bootstrap != null)
+ bootstrap.shutdown();
+ }
+
+ @Before
+ public void setUp() throws Exception
+ {
+ }
+
+ @After
+ public void tearDown() throws Exception
+ {
+ }
+
+ @Test
+ public void testNormal() throws Throwable
+ {
+ StatefulContainer<StatefulBMTBean> container = new StatefulContainer<StatefulBMTBean>("StatefulBMTBean", "Stateful Container", StatefulBMTBean.class);
+
+ Object id = container.construct();
+
+ container.invoke(id, "normal");
+ }
+}
Added: projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/AspectDeployment.java
===================================================================
--- projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/AspectDeployment.java (rev 0)
+++ projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/AspectDeployment.java 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.test.tx.common;
+
+import java.net.URL;
+
+import org.jboss.deployers.client.spi.main.MainDeployer;
+import org.jboss.deployers.vfs.spi.client.VFSDeployment;
+import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
+import org.jboss.logging.Logger;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * Deploy a resource.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class AspectDeployment
+{
+ private static final Logger log = Logger.getLogger(AspectDeployment.class);
+
+ private MainDeployer mainDeployer;
+ private String resource;
+
+ private VFSDeployment deployment;
+
+ private static URL getResource(String name)
+ {
+ return Thread.currentThread().getContextClassLoader().getResource(name);
+ }
+
+ public void setMainDeployer(MainDeployer mainDeployer)
+ {
+ this.mainDeployer = mainDeployer;
+ }
+
+ public void setResource(String resource)
+ {
+ this.resource = resource;
+ }
+
+ public void start() throws Exception
+ {
+ if(mainDeployer == null)
+ throw new IllegalStateException("mainDeployer is not set");
+ if(resource == null)
+ throw new IllegalStateException("resource is null");
+
+ VirtualFile root = VFS.getRoot(getResource(resource));
+ this.deployment = VFSDeploymentFactory.getInstance().createVFSDeployment(root);
+ log.info("Deploying " + deployment);
+ mainDeployer.deploy(deployment);
+ }
+
+ public void stop() throws Exception
+ {
+ mainDeployer.undeploy(deployment);
+ }
+}
Added: projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/SimpleClassLoaderDeployer.java
===================================================================
--- projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/SimpleClassLoaderDeployer.java (rev 0)
+++ projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/SimpleClassLoaderDeployer.java 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.test.tx.common;
+
+import org.jboss.deployers.spi.deployer.helpers.AbstractTopLevelClassLoaderDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class SimpleClassLoaderDeployer extends AbstractTopLevelClassLoaderDeployer
+{
+ @Override
+ protected ClassLoader createTopLevelClassLoader(DeploymentUnit unit) throws Exception
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+}
Added: projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/SimpleContainer.java
===================================================================
--- projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/SimpleContainer.java (rev 0)
+++ projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/SimpleContainer.java 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.test.tx.common;
+
+
+
+/**
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class SimpleContainer
+{
+ private String name;
+ private String domainName;
+ private Class<Object> beanClass;
+
+ private StatefulContainer<Object> beanContainer;
+
+ /**
+ * @param name
+ * @param domainName
+ * @param beanClass
+ */
+ public SimpleContainer(String name, String domainName, Class<Object> beanClass)
+ {
+ this.name = name;
+ this.domainName = domainName;
+ this.beanClass = beanClass;
+ }
+
+ public <I> I constructProxy(Class<I> intf) throws Throwable
+ {
+ return beanContainer.constructProxy(intf);
+ }
+
+ public void start()
+ {
+ this.beanContainer = new StatefulContainer<Object>(name, domainName, beanClass);
+ }
+
+ public void stop()
+ {
+ this.beanContainer = null;
+ }
+}
Added: projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/SimpleTransactionService.java
===================================================================
--- projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/SimpleTransactionService.java (rev 0)
+++ projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/SimpleTransactionService.java 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.test.tx.common;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import com.arjuna.ats.jta.utils.JNDIManager;
+
+/**
+ * Bind a JTA TransactionManager into JNDI.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class SimpleTransactionService
+{
+ public void start() throws Exception
+ {
+ JNDIManager.bindJTAImplementation();
+ }
+
+ public void stop() throws NamingException
+ {
+ InitialContext ctx = new InitialContext();
+ ctx.unbind("java:/TransactionManager");
+ }
+}
Added: projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/StatefulBeanContext.java
===================================================================
--- projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/StatefulBeanContext.java (rev 0)
+++ projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/StatefulBeanContext.java 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.test.tx.common;
+
+import java.util.List;
+import java.util.UUID;
+
+import org.jboss.aop.metadata.SimpleMetaData;
+import org.jboss.ejb3.cache.Identifiable;
+import org.jboss.ejb3.interceptors.container.DummyBeanContext;
+
+/**
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class StatefulBeanContext<T> extends DummyBeanContext<T>
+ implements Identifiable, org.jboss.ejb3.tx.container.StatefulBeanContext<T>
+{
+ private Object id = UUID.randomUUID();
+ private SimpleMetaData metaData = new SimpleMetaData();
+
+ /**
+ * @param instance
+ * @param interceptors
+ */
+ public StatefulBeanContext(T instance, List<Object> interceptors)
+ {
+ super(instance, interceptors);
+ }
+
+ public Object getId()
+ {
+ return id;
+ }
+
+ public SimpleMetaData getMetaData()
+ {
+ return metaData;
+ }
+}
Added: projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/StatefulContainer.java
===================================================================
--- projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/StatefulContainer.java (rev 0)
+++ projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/StatefulContainer.java 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,284 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.test.tx.common;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+
+import org.jboss.aop.Advisor;
+import org.jboss.aop.ClassAdvisor;
+import org.jboss.aop.MethodInfo;
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.ConstructionInvocation;
+import org.jboss.aop.util.MethodHashing;
+import org.jboss.ejb3.cache.Cache;
+import org.jboss.ejb3.cache.StatefulObjectFactory;
+import org.jboss.ejb3.cache.impl.SimpleCache;
+import org.jboss.ejb3.interceptors.InterceptorFactory;
+import org.jboss.ejb3.interceptors.InterceptorFactoryRef;
+import org.jboss.ejb3.interceptors.aop.LifecycleCallbacks;
+import org.jboss.ejb3.interceptors.container.AbstractContainer;
+import org.jboss.ejb3.interceptors.container.BeanContext;
+import org.jboss.ejb3.interceptors.container.BeanContextFactory;
+import org.jboss.ejb3.interceptors.container.ContainerMethodInvocation;
+import org.jboss.ejb3.interceptors.container.DestructionInvocation;
+import org.jboss.ejb3.interceptors.lang.ClassHelper;
+
+/**
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class StatefulContainer<T> extends AbstractContainer<T, StatefulContainer<T>>
+{
+ private BeanContextFactory<T, StatefulContainer<T>> beanContextFactory = new BeanContextFactory<T, StatefulContainer<T>>()
+ {
+
+ public BeanContext<T> createBean() throws Exception
+ {
+ try
+ {
+ ClassAdvisor advisor = getAdvisor();
+ InterceptorFactoryRef interceptorFactoryRef = (InterceptorFactoryRef) advisor.resolveAnnotation(InterceptorFactoryRef.class);
+ if(interceptorFactoryRef == null)
+ throw new IllegalStateException("No InterceptorFactory specified on " + advisor.getName());
+ //log.debug("interceptor factory class = " + interceptorFactoryRef.value());
+ InterceptorFactory interceptorFactory = interceptorFactoryRef.value().newInstance();
+
+ List<Object> ejb3Interceptors = new ArrayList<Object>();
+ for(Class<?> interceptorClass : getInterceptorRegistry().getInterceptorClasses())
+ {
+ Object interceptor = interceptorFactory.create(advisor, interceptorClass);
+ ejb3Interceptors.add(interceptor);
+ }
+
+ Constructor<T> constructor = advisor.getClazz().getConstructor();
+ int idx = advisor.getConstructorIndex(constructor);
+ Object initargs[] = null;
+ T targetObject = getBeanClass().cast(advisor.invokeNew(initargs, idx));
+
+ BeanContext<T> component = new StatefulBeanContext<T>(targetObject, ejb3Interceptors);
+
+ // Do lifecycle callbacks
+ Interceptor interceptors[] = createLifecycleInterceptors(component, PostConstruct.class);
+
+ ConstructionInvocation invocation = new ConstructionInvocation(interceptors, constructor, initargs);
+ invocation.setAdvisor(advisor);
+ invocation.setTargetObject(targetObject);
+ invocation.invokeNext();
+
+ return component;
+ }
+ catch(Error e)
+ {
+ throw e;
+ }
+ catch(Throwable t)
+ {
+ // TODO: decompose
+ throw new RuntimeException(t);
+ }
+ }
+
+ private Interceptor[] createLifecycleInterceptors(BeanContext<T> component, Class<? extends Annotation> lifecycleAnnotationType) throws Exception
+ {
+ List<Class<?>> lifecycleInterceptorClasses = getInterceptorRegistry().getLifecycleInterceptorClasses();
+ Advisor advisor = getAdvisor();
+ return LifecycleCallbacks.createLifecycleCallbackInterceptors(advisor, lifecycleInterceptorClasses, component, lifecycleAnnotationType);
+ }
+
+ public void destroyBean(BeanContext<T> component)
+ {
+ try
+ {
+ Advisor advisor = getAdvisor();
+ Interceptor interceptors[] = createLifecycleInterceptors(component, PreDestroy.class);
+
+ DestructionInvocation invocation = new DestructionInvocation(interceptors);
+ invocation.setAdvisor(advisor);
+ invocation.setTargetObject(component.getInstance());
+ invocation.invokeNext();
+ }
+ catch(Throwable t)
+ {
+ // TODO: disect
+ if(t instanceof RuntimeException)
+ throw (RuntimeException) t;
+ throw new RuntimeException(t);
+ }
+ }
+
+ public void setContainer(StatefulContainer<T> container)
+ {
+ // Dummy
+ }
+ };
+
+ private StatefulObjectFactory<StatefulBeanContext<T>> factory = new StatefulObjectFactory<StatefulBeanContext<T>>()
+ {
+ public StatefulBeanContext<T> create(Class<?>[] initTypes, Object[] initValues)
+ {
+ try
+ {
+ Constructor<? extends T> constructor = getBeanClass().getConstructor();
+ return (StatefulBeanContext<T>) StatefulContainer.this.construct(constructor);
+ }
+ catch(NoSuchMethodException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void destroy(StatefulBeanContext<T> obj)
+ {
+ StatefulContainer.this.destroy(obj);
+ }
+ };
+
+ private Cache<StatefulBeanContext<T>> cache = new SimpleCache<StatefulBeanContext<T>>(factory);
+
+ private class ProxyInvocationHandler implements InvocationHandler
+ {
+ private Object id;
+
+ public ProxyInvocationHandler(Object id)
+ {
+ assert id != null : "id is null";
+
+ this.id = id;
+ }
+
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+ {
+ return StatefulContainer.this.invoke(id, method, args);
+ }
+ }
+
+ public StatefulContainer(String name, String domainName, Class<T> beanClass)
+ {
+ super(name, domainName, beanClass);
+ setBeanContextFactory(beanContextFactory);
+ }
+
+ /**
+ * For direct access.
+ * @return
+ * @throws Throwable
+ */
+ public Object construct() throws Throwable
+ {
+ StatefulBeanContext<T> ctx = cache.create(null, null);
+ Object id = ctx.getId();
+ cache.release(ctx);
+ return id;
+ }
+
+ /**
+ * For proxied access.
+ * @param <I>
+ * @param intf
+ * @return
+ * @throws Throwable
+ */
+ public <I> I constructProxy(Class<I> intf) throws Throwable
+ {
+ Object id = construct();
+
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ Class<?> interfaces[] = { intf };
+ Object proxy = Proxy.newProxyInstance(loader, interfaces, new ProxyInvocationHandler(id));
+ return intf.cast(proxy);
+ }
+
+ public void destroy(Object id)
+ {
+ cache.remove(id);
+ }
+
+ protected Cache<StatefulBeanContext<T>> getCache()
+ {
+ return cache;
+ }
+
+ /**
+ * A convenient, but unchecked and slow method to call a method upon a target.
+ *
+ * (Slow method)
+ *
+ * @param <R> the return type
+ * @param target the target to invoke upon
+ * @param methodName the method name to invoke
+ * @param args the arguments to the method
+ * @return the return value
+ * @throws Throwable if anything goes wrong
+ */
+ @SuppressWarnings("unchecked")
+ public <R> R invoke(Object id, String methodName, Object ... args) throws Throwable
+ {
+ Method method = ClassHelper.getMethod(getBeanClass(), methodName);
+ return (R) invoke(id, method, args);
+ }
+
+ public Object invoke(Object id, Method method, Object[] arguments) throws Throwable
+ {
+ long methodHash = MethodHashing.calculateHash(method);
+ MethodInfo info = getAdvisor().getMethodInfo(methodHash);
+ if(info == null)
+ throw new IllegalArgumentException("method " + method + " is not under advisement by " + this);
+ ContainerMethodInvocation invocation = new StatefulContainerMethodInvocation(info, id, arguments);
+ return invocation.invokeNext();
+ }
+
+ protected void setBeanContextFactory(BeanContextFactory<T, StatefulContainer<T>> factory)
+ {
+ try
+ {
+ Field field = AbstractContainer.class.getDeclaredField("beanContextFactory");
+ field.setAccessible(true);
+ field.set(this, factory);
+ }
+ catch (SecurityException e)
+ {
+ throw new RuntimeException(e);
+ }
+ catch (NoSuchFieldException e)
+ {
+ throw new RuntimeException(e);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new RuntimeException(e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+}
Added: projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/StatefulContainerMethodInvocation.java
===================================================================
--- projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/StatefulContainerMethodInvocation.java (rev 0)
+++ projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/StatefulContainerMethodInvocation.java 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.test.tx.common;
+
+import org.jboss.aop.MethodInfo;
+import org.jboss.ejb3.interceptors.container.ContainerMethodInvocation;
+
+/**
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class StatefulContainerMethodInvocation extends ContainerMethodInvocation
+{
+ private Object id;
+
+ StatefulContainerMethodInvocation(MethodInfo info, Object id, Object arguments[])
+ {
+ super(info);
+
+ assert id != null : "id is null";
+
+ this.id = id;
+
+ setArguments(arguments);
+ }
+
+ public Object getId()
+ {
+ return id;
+ }
+}
Added: projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/StatefulInstanceInterceptor.java
===================================================================
--- projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/StatefulInstanceInterceptor.java (rev 0)
+++ projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/common/StatefulInstanceInterceptor.java 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,95 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.test.tx.common;
+
+import java.rmi.RemoteException;
+
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.ejb3.cache.Cache;
+import org.jboss.ejb3.tx.AbstractInterceptor;
+import org.jboss.logging.Logger;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 72219 $
+ */
+public class StatefulInstanceInterceptor extends AbstractInterceptor
+{
+ private static final Logger log = Logger.getLogger(StatefulInstanceInterceptor.class);
+
+ public StatefulInstanceInterceptor()
+ {
+ }
+
+ private <T> Object doInvoke(Invocation invocation) throws Throwable
+ {
+ StatefulContainerMethodInvocation ejb = (StatefulContainerMethodInvocation) invocation;
+ Object id = ejb.getId();
+ assert id != null : "id is null";
+ StatefulContainer<T> container = getContainer(invocation);
+ Cache<StatefulBeanContext<T>> cache = container.getCache();
+ StatefulBeanContext<T> target = container.getCache().get(id);
+
+ ejb.setBeanContext(target);
+// StatefulBeanContext.currentBean.push(target);
+// container.pushContext(target);
+ try
+ {
+// if (target.isDiscarded()) throw new EJBException("SFSB was discarded by another thread");
+ return ejb.invokeNext();
+ }
+ catch (Exception ex)
+ {
+// if (StatefulRemoveInterceptor.isApplicationException(ex, (MethodInvocation)invocation)) throw ex;
+ if (ex instanceof RuntimeException
+ || ex instanceof RemoteException)
+ {
+ if(log.isTraceEnabled())
+ log.trace("Removing bean " + id + " because of exception", ex);
+ // TODO: should be discard
+ container.getCache().remove(id);
+ }
+ throw ex;
+ }
+ finally
+ {
+// container.popContext();
+// StatefulBeanContext.currentBean.pop();
+ // the bean context is disassociated, but then the StatefulRemoveInterceptor will fail
+ ejb.setBeanContext(null);
+ synchronized (target)
+ {
+// target.setInInvocation(false);
+// if (!target.isTxSynchronized() && !target.isDiscarded()) container.getCache().release(target);
+// if (block) target.getLock().unlock();
+ cache.release(target);
+ }
+ }
+ }
+
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ return doInvoke(invocation);
+ }
+}
Added: projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/instance/InstanceTest.java
===================================================================
--- projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/instance/InstanceTest.java (rev 0)
+++ projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/instance/InstanceTest.java 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.test.tx.instance;
+
+
+/**
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface InstanceTest
+{
+ void mandatory();
+
+ void never();
+
+ void notSupported();
+
+ void required();
+
+ void requiresNew();
+
+ void supports();
+}
Added: projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/instance/InstanceTestBean.java
===================================================================
--- projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/instance/InstanceTestBean.java (rev 0)
+++ projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/instance/InstanceTestBean.java 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.test.tx.instance;
+
+import static javax.ejb.TransactionAttributeType.MANDATORY;
+import static javax.ejb.TransactionAttributeType.NEVER;
+import static javax.ejb.TransactionAttributeType.REQUIRED;
+
+import javax.ejb.Stateful;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+
+/**
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateful
+public class InstanceTestBean implements InstanceTest
+{
+ @TransactionAttribute(MANDATORY)
+ public void mandatory()
+ {
+
+ }
+
+ @TransactionAttribute(NEVER)
+ public void never()
+ {
+
+ }
+
+ @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
+ public void notSupported()
+ {
+
+ }
+
+ @TransactionAttribute(REQUIRED)
+ public void required()
+ {
+
+ }
+
+ @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
+ public void requiresNew()
+ {
+
+ }
+
+ @TransactionAttribute(TransactionAttributeType.SUPPORTS)
+ public void supports()
+ {
+
+ }
+}
Added: projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/instance/unit/InstanceTestCase.java
===================================================================
--- projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/instance/unit/InstanceTestCase.java (rev 0)
+++ projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/instance/unit/InstanceTestCase.java 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,146 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.test.tx.instance.unit;
+
+import static org.junit.Assert.fail;
+
+import java.net.URL;
+
+import javax.ejb.EJBException;
+import javax.ejb.EJBTransactionRequiredException;
+import javax.naming.InitialContext;
+import javax.transaction.TransactionManager;
+
+import org.jboss.ejb3.test.tx.common.SimpleContainer;
+import org.jboss.ejb3.test.tx.instance.InstanceTest;
+import org.jboss.ejb3.test.tx.mc.UnitTestBootstrap;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class InstanceTestCase
+{
+ private static UnitTestBootstrap bootstrap;
+
+ private static URL getResource(String name)
+ {
+ return Thread.currentThread().getContextClassLoader().getResource(name);
+ }
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Throwable
+ {
+ bootstrap = new UnitTestBootstrap();
+ bootstrap.deploy(getResource("instance/beans.xml"));
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception
+ {
+ if(bootstrap != null)
+ bootstrap.shutdown();
+ }
+
+ @Before
+ public void setUp() throws Exception
+ {
+ }
+
+ @After
+ public void tearDown() throws Exception
+ {
+ }
+
+ /**
+ * Test whether the stateful bean is still alive after a transaction
+ * guard failure.
+ */
+ @Test
+ public void testInstance() throws Throwable
+ {
+ SimpleContainer container = bootstrap.lookup("TestContainer", SimpleContainer.class);
+
+ InstanceTest bean = container.constructProxy(InstanceTest.class);
+
+ InitialContext ctx = new InitialContext();
+ TransactionManager tm = (TransactionManager) ctx.lookup("java:/TransactionManager");
+ tm.begin();
+ try
+ {
+ bean.never();
+ fail("never should not allow a transaction");
+ }
+ catch(EJBException e)
+ {
+ // Good
+ }
+ finally
+ {
+ tm.rollback();
+ }
+
+ bean.required();
+ }
+
+ @Test
+ public void testTransactionMandatory() throws Throwable
+ {
+ SimpleContainer container = bootstrap.lookup("TestContainer", SimpleContainer.class);
+
+ InstanceTest bean = container.constructProxy(InstanceTest.class);
+
+ InitialContext ctx = new InitialContext();
+ TransactionManager tm = (TransactionManager) ctx.lookup("java:/TransactionManager");
+ tm.begin();
+ try
+ {
+ bean.mandatory();
+ }
+ finally
+ {
+ tm.rollback();
+ }
+ }
+
+ @Test
+ public void testTransactionMandatoryIllegal() throws Throwable
+ {
+ SimpleContainer container = bootstrap.lookup("TestContainer", SimpleContainer.class);
+
+ InstanceTest bean = container.constructProxy(InstanceTest.class);
+ try
+ {
+ bean.mandatory();
+ fail("transaction is required");
+ }
+ catch(EJBTransactionRequiredException e)
+ {
+ // Good
+ }
+ }
+}
Added: projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/mc/UnitTestBootstrap.java
===================================================================
--- projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/mc/UnitTestBootstrap.java (rev 0)
+++ projects/ejb3/trunk/transactions/src/test/java/org/jboss/ejb3/test/tx/mc/UnitTestBootstrap.java 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,140 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.test.tx.mc;
+
+import java.net.URL;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
+import org.jboss.kernel.plugins.deployment.xml.BasicXMLDeployer;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.kernel.spi.deployment.KernelDeployment;
+
+/**
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class UnitTestBootstrap extends BasicBootstrap
+{
+ /** The deployer */
+ protected BasicXMLDeployer deployer;
+
+ /**
+ * Create a new bootstrap
+ *
+ * @throws Throwable
+ */
+ public UnitTestBootstrap() throws Throwable
+ {
+ super();
+ bootstrap();
+ }
+
+ protected void bootstrap() throws Throwable
+ {
+ super.bootstrap();
+
+ deployer = new BasicXMLDeployer(getKernel());
+
+ /*
+ Runtime.getRuntime().addShutdownHook(new Shutdown());
+
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ for (Enumeration<URL> e = cl.getResources(StandaloneKernelConstants.DEPLOYMENT_XML_NAME); e.hasMoreElements(); )
+ {
+ URL url = e.nextElement();
+ deploy(url);
+ }
+ for (Enumeration<URL> e = cl.getResources("META-INF/" + StandaloneKernelConstants.DEPLOYMENT_XML_NAME); e.hasMoreElements(); )
+ {
+ URL url = e.nextElement();
+ deploy(url);
+ }
+
+ // Validate that everything is ok
+ deployer.validate();
+ */
+ }
+
+ /**
+ * Deploy a url
+ *
+ * @param url the deployment url
+ * @throws Throwable for any error
+ */
+ public void deploy(URL url) throws Throwable
+ {
+ KernelDeployment deployment = deployer.deploy(url);
+ deployer.validate(deployment);
+ }
+
+ private KernelController getController()
+ {
+ return getKernel().getController();
+ }
+
+ /**
+ * @param name
+ */
+ public <T> T lookup(String name, Class<T> expectedType) throws Throwable
+ {
+ KernelController controller = getController();
+ ControllerContext context = controller.getContext(name, null);
+ controller.change(context, ControllerState.INSTALLED);
+ if(context.getError() != null)
+ throw context.getError();
+
+ if(context.getState() != ControllerState.INSTALLED) {
+ System.err.println(context.getDependencyInfo().getUnresolvedDependencies(null));
+ }
+ // TODO: it can be stalled because of dependencies
+ assert context.getState() == ControllerState.INSTALLED;
+
+ return expectedType.cast(context.getTarget());
+ }
+
+ /**
+ * Shutdown the UnitBootStrap.
+ */
+ public void shutdown()
+ {
+ deployer.shutdown();
+ }
+
+ /**
+ * Undeploy a url
+ *
+ * @param url the deployment url
+ */
+ public void undeploy(URL url)
+ {
+ try
+ {
+ deployer.undeploy(url);
+ }
+ catch (Throwable t)
+ {
+ log.warn("Error during undeployment: " + url, t);
+ }
+ }
+}
Added: projects/ejb3/trunk/transactions/src/test/resources/instance/beans.xml
===================================================================
--- projects/ejb3/trunk/transactions/src/test/resources/instance/beans.xml (rev 0)
+++ projects/ejb3/trunk/transactions/src/test/resources/instance/beans.xml 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+ <bean name="SimpleClassLoaderDeployer" class="org.jboss.ejb3.test.tx.common.SimpleClassLoaderDeployer"/>
+
+ <bean name="AspectManager" class="org.jboss.aop.AspectManager">
+ <constructor factoryClass="org.jboss.aop.AspectManager" factoryMethod="instance"/>
+ </bean>
+
+ <bean name="AspectAppParsingDeployer" class="org.jboss.aop.deployers.AspectAppParsingDeployer"/>
+ <bean name="AspectDeployer" class="org.jboss.aop.deployers.AspectDeployer">
+ <property name="type">aop</property>
+ <property name="aspectManager"><inject bean="AspectManager"/></property>
+ </bean>
+
+ <!-- The MainDeployer -->
+ <bean name="MainDeployer" class="org.jboss.deployers.plugins.main.MainDeployerImpl">
+ <property name="structuralDeployers"><inject bean="StructuralDeployers"/></property>
+ <property name="deployers"><inject bean="Deployers"/></property>
+ <!--property name="mgtDeploymentCreator"><inject bean="ManagedDeploymentCreator"/></property-->
+ </bean>
+
+ <!-- The holder for deployers that determine structure -->
+ <bean name="StructuralDeployers" class="org.jboss.deployers.vfs.plugins.structure.VFSStructuralDeployersImpl">
+ <property name="structureBuilder">
+ <!-- The consolidator of the structure information -->
+ <bean name="StructureBuilder" class="org.jboss.deployers.vfs.plugins.structure.VFSStructureBuilder"/>
+ </property>
+ <!-- Accept any implementor of structure deployer -->
+ <incallback method="addDeployer"/>
+ <uncallback method="removeDeployer"/>
+ </bean>
+
+ <!-- The holder for deployers that do real deployment -->
+ <bean name="Deployers" class="org.jboss.deployers.plugins.deployers.DeployersImpl">
+ <constructor><parameter><inject bean="jboss.kernel:service=KernelController"/></parameter></constructor>
+ <!-- Accept any implementor of deployer -->
+ <incallback method="addDeployer"/>
+ <uncallback method="removeDeployer"/>
+ </bean>
+
+ <!-- File Structure -->
+ <bean name="FileStructure" class="org.jboss.deployers.vfs.plugins.structure.file.FileStructure"/>
+
+ <!-- JNDI -->
+ <bean name="NameServer" class="org.jnp.server.SingletonNamingServer"/>
+
+ <bean name="TransactionManager" class="org.jboss.ejb3.test.tx.common.SimpleTransactionService">
+ <depends>NameServer</depends>
+ </bean>
+
+ <bean name="AspectDeployment" class="org.jboss.ejb3.test.tx.common.AspectDeployment">
+ <property name="mainDeployer"><inject bean="MainDeployer"/></property>
+ <property name="resource">instance/jboss-aop.xml</property>
+ <depends>TransactionManager</depends>
+ </bean>
+
+ <bean name="TestContainer" class="org.jboss.ejb3.test.tx.common.SimpleContainer">
+ <constructor>
+ <parameter>TestContainer</parameter>
+ <parameter>Stateful Container</parameter>
+ <parameter>org.jboss.ejb3.test.tx.instance.InstanceTestBean</parameter>
+ </constructor>
+ <depends>AspectDeployment</depends>
+ <depends>TransactionManager</depends>
+ </bean>
+</deployment>
\ No newline at end of file
Added: projects/ejb3/trunk/transactions/src/test/resources/instance/jboss-aop.xml
===================================================================
--- projects/ejb3/trunk/transactions/src/test/resources/instance/jboss-aop.xml (rev 0)
+++ projects/ejb3/trunk/transactions/src/test/resources/instance/jboss-aop.xml 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<aop>
+ <interceptor class="org.jboss.ejb3.test.tx.common.StatefulInstanceInterceptor" scope="PER_VM"/>
+ <interceptor factory="org.jboss.ejb3.tx.TxInterceptorFactory" scope="PER_CLASS_JOINPOINT"/>
+
+ <domain name="Stateful Container">
+ <bind pointcut="execution(public * *->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.test.tx.common.StatefulInstanceInterceptor"/>
+ <!--interceptor-ref name="org.jboss.aspects.tx.TxPropagationInterceptor"/-->
+ <interceptor-ref name="org.jboss.ejb3.tx.TxInterceptorFactory"/>
+ </bind>
+ <!--
+ <bind pointcut="execution(public * $instanceof{javax.ejb.SessionSynchronization}->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.stateful.SessionSynchronizationInterceptor"/>
+ </bind>
+ -->
+ </domain>
+</aop>
\ No newline at end of file
Added: projects/ejb3/trunk/transactions/src/test/resources/jndi.properties
===================================================================
--- projects/ejb3/trunk/transactions/src/test/resources/jndi.properties (rev 0)
+++ projects/ejb3/trunk/transactions/src/test/resources/jndi.properties 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,2 @@
+java.naming.factory.initial=org.jnp.interfaces.LocalOnlyContextFactory
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
\ No newline at end of file
Added: projects/ejb3/trunk/transactions/src/test/resources/log4j.xml
===================================================================
--- projects/ejb3/trunk/transactions/src/test/resources/log4j.xml (rev 0)
+++ projects/ejb3/trunk/transactions/src/test/resources/log4j.xml 2008-04-17 15:25:26 UTC (rev 72368)
@@ -0,0 +1,123 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<!-- ===================================================================== -->
+<!-- -->
+<!-- Log4j Configuration -->
+<!-- -->
+<!-- ===================================================================== -->
+
+<!-- $Id: log4j.xml 69357 2008-01-25 23:13:47Z wolfc $ -->
+
+<!--
+ | For more configuration infromation and examples see the Jakarta Log4j
+ | owebsite: http://jakarta.apache.org/log4j
+ -->
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+
+ <!-- ================================= -->
+ <!-- Preserve messages in a local file -->
+ <!-- ================================= -->
+
+ <!-- A time/date based rolling appender -->
+ <appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
+ <param name="File" value="target/test.log"/>
+ <param name="Threshold" value="INFO"/>
+ <param name="Append" value="false"/>
+
+ <!-- Rollover at midnight each day -->
+ <param name="DatePattern" value="'.'yyyy-MM-dd"/>
+
+ <!-- Rollover at the top of each hour
+ <param name="DatePattern" value="'.'yyyy-MM-dd-HH"/>
+ -->
+
+ <layout class="org.apache.log4j.PatternLayout">
+ <!-- The default pattern: Date Priority [Category] Message\n -->
+ <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
+
+ <!-- The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
+ <param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
+ -->
+ </layout>
+ </appender>
+
+ <!-- A size based file rolling appender
+ <appender name="FILE" class="org.jboss.logging.appender.RollingFileAppender">
+ <param name="File" value="${jboss.server.home.dir}/log/server.log"/>
+ <param name="Append" value="false"/>
+ <param name="MaxFileSize" value="500KB"/>
+ <param name="MaxBackupIndex" value="1"/>
+
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
+ </layout>
+ </appender>
+ -->
+
+ <!-- ============================== -->
+ <!-- Append messages to the console -->
+ <!-- ============================== -->
+
+ <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+ <param name="Threshold" value="TRACE"/>
+ <param name="Target" value="System.out"/>
+
+ <layout class="org.apache.log4j.PatternLayout">
+ <!-- The default pattern: Date Priority [Category] Message\n -->
+ <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
+ </layout>
+ </appender>
+
+
+ <!-- ================ -->
+ <!-- Limit categories -->
+ <!-- ================ -->
+
+ <!-- Limit JBoss categories to INFO
+ <category name="org.jboss">
+ <priority value="INFO" class="org.jboss.logging.XLevel"/>
+ </category>
+ -->
+
+ <!-- Increase the priority threshold for the DefaultDS category
+ <category name="DefaultDS">
+ <priority value="FATAL"/>
+ </category>
+ -->
+
+ <!-- Decrease the priority threshold for the org.jboss.varia category
+ <category name="org.jboss.varia">
+ <priority value="DEBUG"/>
+ </category>
+ -->
+
+ <!--
+ | An example of enabling the custom TRACE level priority that is used
+ | by the JBoss internals to diagnose low level details. This example
+ | turns on TRACE level msgs for the org.jboss.ejb.plugins package and its
+ | subpackages. This will produce A LOT of logging output.
+ <category name="org.jboss.system">
+ <priority value="TRACE" class="org.jboss.logging.XLevel"/>
+ </category>
+ -->
+
+ <category name="org.jboss">
+ <priority value="INFO"/>
+ </category>
+
+ <category name="org.jboss.ejb3.test.sandbox">
+ <priority value="ALL"/>
+ </category>
+
+ <!-- ======================= -->
+ <!-- Setup the Root category -->
+ <!-- ======================= -->
+
+ <root>
+ <appender-ref ref="CONSOLE"/>
+ <appender-ref ref="FILE"/>
+ </root>
+
+</log4j:configuration>
More information about the jboss-cvs-commits
mailing list