[jboss-cvs] JBossAS SVN: r69779 - in branches/JBPAPP_4_2_0_GA_CP/ejb3/src: test/org/jboss/ejb3/test/epcpropagation and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Feb 11 15:09:09 EST 2008
Author: bdecoste
Date: 2008-02-11 15:09:09 -0500 (Mon, 11 Feb 2008)
New Revision: 69779
Added:
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/CMTEPCStatefulBean.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/CMTStatefulBean.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/EPCStatefulBean.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/InitEPCStatefulBean.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/IntermediateStatefulBean.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/IntermediateStatefulRemote.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/NoTxEPCStatefulBean.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/NoTxStatefulBean.java
Modified:
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/entity/TransactionScopedEntityManager.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/MyEntity.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/StatefulBean.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/StatefulRemote.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/StatelessBean.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/StatelessRemote.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/unit/EPCPropagationTestCase.java
Log:
[JBPAPP-586] fixed EPC propagation
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/entity/TransactionScopedEntityManager.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/entity/TransactionScopedEntityManager.java 2008-02-11 20:07:17 UTC (rev 69778)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/entity/TransactionScopedEntityManager.java 2008-02-11 20:09:09 UTC (rev 69779)
@@ -24,14 +24,19 @@
import org.hibernate.Session;
import org.hibernate.ejb.HibernateEntityManager;
import org.jboss.ejb3.PersistenceUnitRegistry;
+import org.jboss.ejb3.stateful.StatefulBeanContext;
+import org.jboss.logging.Logger;
import javax.persistence.*;
+
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
+import java.util.List;
+
/**
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
* @version $Revision$
@@ -40,7 +45,13 @@
{
private static final long serialVersionUID = 4260828563883650376L;
+ private static final Logger log = Logger.getLogger(TransactionScopedEntityManager.class);
+
private transient ManagedEntityManagerFactory factory;
+
+ public TransactionScopedEntityManager()
+ {
+ }
public Session getSession()
{
@@ -64,10 +75,6 @@
this.factory = factory;
}
- public TransactionScopedEntityManager()
- {
- }
-
public void writeExternal(ObjectOutput out) throws IOException
{
out.writeUTF(factory.getKernelName());
@@ -83,34 +90,34 @@
public Object getDelegate()
{
- return factory.getTransactionScopedEntityManager().getDelegate();
+ return getEntityManager().getDelegate();
}
public void joinTransaction()
{
factory.verifyInTx();
- factory.getTransactionScopedEntityManager().joinTransaction();
+ getEntityManager().joinTransaction();
}
public void clear()
{
- factory.getTransactionScopedEntityManager().clear();
+ getEntityManager().clear();
}
public FlushModeType getFlushMode()
{
- return factory.getTransactionScopedEntityManager().getFlushMode();
+ return getEntityManager().getFlushMode();
}
public void lock(Object entity, LockModeType lockMode)
{
factory.verifyInTx();
- factory.getTransactionScopedEntityManager().lock(entity, lockMode);
+ getEntityManager().lock(entity, lockMode);
}
public <T> T getReference(Class<T> entityClass, Object primaryKey)
{
- EntityManager em = factory.getTransactionScopedEntityManager();
+ EntityManager em = getEntityManager();
if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
try
{
@@ -124,47 +131,48 @@
public void setFlushMode(FlushModeType flushMode)
{
- factory.getTransactionScopedEntityManager().setFlushMode(flushMode);
+ getEntityManager().setFlushMode(flushMode);
}
public Query createQuery(String ejbqlString)
{
- EntityManager em = factory.getTransactionScopedEntityManager();
+ EntityManager em = getEntityManager();
if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
return em.createQuery(ejbqlString);
}
public Query createNamedQuery(String name)
{
- EntityManager em = factory.getTransactionScopedEntityManager();
+ EntityManager em = getEntityManager();
if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
return em.createNamedQuery(name);
}
public Query createNativeQuery(String sqlString)
{
- EntityManager em = factory.getTransactionScopedEntityManager();
+ EntityManager em = getEntityManager();
if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
return em.createNativeQuery(sqlString);
}
public Query createNativeQuery(String sqlString, Class resultClass)
{
- EntityManager em = factory.getTransactionScopedEntityManager();
+ EntityManager em = getEntityManager();
if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
return em.createNativeQuery(sqlString, resultClass);
}
public Query createNativeQuery(String sqlString, String resultSetMapping)
{
- EntityManager em = factory.getTransactionScopedEntityManager();
+ EntityManager em = getEntityManager();
if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
return em.createNativeQuery(sqlString, resultSetMapping);
}
public <A> A find(Class<A> entityClass, Object primaryKey)
{
- EntityManager em = factory.getTransactionScopedEntityManager();
+ EntityManager em = getEntityManager();
+
if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
try
{
@@ -179,36 +187,36 @@
public void persist(Object entity)
{
factory.verifyInTx();
- factory.getTransactionScopedEntityManager().persist(entity);
+ getEntityManager().persist(entity);
}
public <A> A merge(A entity)
{
factory.verifyInTx();
- return (A) factory.getTransactionScopedEntityManager().merge(entity);
+ return (A) getEntityManager().merge(entity);
}
public void remove(Object entity)
{
factory.verifyInTx();
- factory.getTransactionScopedEntityManager().remove(entity);
+ getEntityManager().remove(entity);
}
public void refresh(Object entity)
{
factory.verifyInTx();
- factory.getTransactionScopedEntityManager().refresh(entity);
+ getEntityManager().refresh(entity);
}
public boolean contains(Object entity)
{
- return factory.getTransactionScopedEntityManager().contains(entity);
+ return getEntityManager().contains(entity);
}
public void flush()
{
factory.verifyInTx();
- factory.getTransactionScopedEntityManager().flush();
+ getEntityManager().flush();
}
public void close()
@@ -225,5 +233,24 @@
{
throw new IllegalStateException("Illegal to call this method from injected, managed EntityManager");
}
+
+ protected EntityManager getEntityManager()
+ {
+ StatefulBeanContext beanContext = StatefulBeanContext.currentBean.get();
+
+ EntityManager em;
+ if (beanContext != null)
+ {
+ List<StatefulBeanContext> beanContexts = StatefulBeanContext.currentBean.getList();
+ for( StatefulBeanContext bc : beanContexts)
+ {
+ em = bc.getExtendedPersistenceContext(factory.getKernelName());
+ if (em != null)
+ return em;
+ }
+ }
+
+ return factory.getTransactionScopedEntityManager();
+ }
}
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/CMTEPCStatefulBean.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/CMTEPCStatefulBean.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/CMTEPCStatefulBean.java 2008-02-11 20:09:09 UTC (rev 69779)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.epcpropagation;
+
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.ejb.Local;
+import javax.ejb.Remote;
+import javax.ejb.SessionContext;
+import javax.ejb.Stateful;
+import javax.ejb.TransactionManagement;
+import javax.ejb.TransactionManagementType;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceContextType;
+import javax.transaction.Status;
+import javax.transaction.UserTransaction;
+
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at Stateful
+ at Remote(StatefulRemote.class)
+public class CMTEPCStatefulBean implements StatefulRemote
+{
+ private static final Logger log = Logger.getLogger(CMTEPCStatefulBean.class);
+
+ @PersistenceContext(type=PersistenceContextType.EXTENDED, unitName="mypc")
+ EntityManager em;
+
+ @Resource
+ SessionContext sessionContext;
+
+ @EJB
+ StatelessRemote cmtBean;
+
+ public boolean execute(Integer id, String name) throws Exception
+ {
+ MyEntity eb = em.find(MyEntity.class, id);
+ eb.setName(name.toUpperCase());
+
+ String propagatedName = cmtBean.updateEntity(id, name.toLowerCase());
+
+ return propagatedName.equals(name.toUpperCase());
+ }
+}
\ No newline at end of file
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/CMTStatefulBean.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/CMTStatefulBean.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/CMTStatefulBean.java 2008-02-11 20:09:09 UTC (rev 69779)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.epcpropagation;
+
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.ejb.Local;
+import javax.ejb.Remote;
+import javax.ejb.SessionContext;
+import javax.ejb.Stateful;
+import javax.ejb.TransactionManagement;
+import javax.ejb.TransactionManagementType;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceContextType;
+import javax.transaction.Status;
+import javax.transaction.UserTransaction;
+
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at Stateful
+ at Remote(StatefulRemote.class)
+public class CMTStatefulBean implements StatefulRemote
+{
+ private static final Logger log = Logger.getLogger(CMTStatefulBean.class);
+
+ @PersistenceContext(unitName="mypc")
+ EntityManager em;
+
+ @Resource
+ SessionContext sessionContext;
+
+ @EJB
+ StatelessRemote cmtBean;
+
+ public boolean execute(Integer id, String name) throws Exception
+ {
+ MyEntity eb = em.find(MyEntity.class, id);
+ eb.setName(name.toUpperCase());
+
+ String propagatedName = cmtBean.updateEntity(id, name.toLowerCase());
+
+ return propagatedName.equals(name.toUpperCase());
+ }
+}
\ No newline at end of file
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/EPCStatefulBean.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/EPCStatefulBean.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/EPCStatefulBean.java 2008-02-11 20:09:09 UTC (rev 69779)
@@ -0,0 +1,87 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.epcpropagation;
+
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.ejb.Local;
+import javax.ejb.Remote;
+import javax.ejb.SessionContext;
+import javax.ejb.Stateful;
+import javax.ejb.TransactionManagement;
+import javax.ejb.TransactionManagementType;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceContextType;
+import javax.transaction.Status;
+import javax.transaction.UserTransaction;
+
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at Stateful
+ at TransactionManagement(TransactionManagementType.BEAN)
+ at Remote(StatefulRemote.class)
+public class EPCStatefulBean implements StatefulRemote
+{
+ private static final Logger log = Logger.getLogger(EPCStatefulBean.class);
+
+ @PersistenceContext(type=PersistenceContextType.EXTENDED, unitName="mypc")
+ EntityManager em;
+
+ @Resource
+ SessionContext sessionContext;
+
+ @EJB
+ StatelessRemote cmtBean;
+
+ public boolean execute(Integer id, String name) throws Exception
+ {
+ try
+ {
+ UserTransaction tx1 = sessionContext.getUserTransaction();
+ tx1.begin();
+ em.joinTransaction();
+ MyEntity entity = em.find(MyEntity.class, id);
+ entity.setName(name.toUpperCase());
+
+ String propagatedName = cmtBean.updateEntity(id, name.toLowerCase());
+ tx1.commit();
+
+ return propagatedName.equals(name.toUpperCase());
+ }
+ catch (Exception e)
+ {
+ try
+ {
+ sessionContext.getUserTransaction().rollback();
+ }
+ catch (Exception e1)
+ {
+ log.info("ROLLBACK: "+e1);
+ }
+ throw e;
+ }
+ }
+}
\ No newline at end of file
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/InitEPCStatefulBean.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/InitEPCStatefulBean.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/InitEPCStatefulBean.java 2008-02-11 20:09:09 UTC (rev 69779)
@@ -0,0 +1,87 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.epcpropagation;
+
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.ejb.Local;
+import javax.ejb.Remote;
+import javax.ejb.SessionContext;
+import javax.ejb.Stateful;
+import javax.ejb.TransactionManagement;
+import javax.ejb.TransactionManagementType;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceContextType;
+import javax.transaction.Status;
+import javax.transaction.UserTransaction;
+
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at Stateful
+ at TransactionManagement(TransactionManagementType.BEAN)
+ at Remote(StatefulRemote.class)
+public class InitEPCStatefulBean implements StatefulRemote
+{
+ private static final Logger log = Logger.getLogger(InitEPCStatefulBean.class);
+
+ @PersistenceContext(type=PersistenceContextType.EXTENDED, unitName="mypc")
+ EntityManager em;
+
+ @Resource
+ SessionContext sessionContext;
+
+ @EJB(beanName="IntermediateStatefulBean")
+ StatefulRemote cmtBean;
+
+ public boolean execute(Integer id, String name) throws Exception
+ {
+ try
+ {
+ UserTransaction tx1 = sessionContext.getUserTransaction();
+ tx1.begin();
+ em.joinTransaction();
+ MyEntity entity = em.find(MyEntity.class, id);
+ entity.setName(name.toUpperCase());
+
+ boolean result = cmtBean.execute(id, name.toLowerCase());
+ tx1.commit();
+
+ return result;
+ }
+ catch (Exception e)
+ {
+ try
+ {
+ sessionContext.getUserTransaction().rollback();
+ }
+ catch (Exception e1)
+ {
+ log.info("ROLLBACK: "+e1);
+ }
+ throw e;
+ }
+ }
+}
\ No newline at end of file
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/IntermediateStatefulBean.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/IntermediateStatefulBean.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/IntermediateStatefulBean.java 2008-02-11 20:09:09 UTC (rev 69779)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.epcpropagation;
+
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.ejb.Local;
+import javax.ejb.Remote;
+import javax.ejb.SessionContext;
+import javax.ejb.Stateful;
+import javax.ejb.TransactionManagement;
+import javax.ejb.TransactionManagementType;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceContextType;
+import javax.transaction.Status;
+import javax.transaction.UserTransaction;
+
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at Stateful
+ at Remote(StatefulRemote.class)
+public class IntermediateStatefulBean implements IntermediateStatefulRemote
+{
+ private static final Logger log = Logger.getLogger(IntermediateStatefulBean.class);
+
+ @PersistenceContext(unitName="mypc")
+ EntityManager em;
+
+ @Resource
+ SessionContext sessionContext;
+
+ @EJB
+ StatelessRemote cmtBean;
+
+ public boolean execute(Integer id, String name) throws Exception
+ {
+ MyEntity entity = em.find(MyEntity.class, id);
+
+ String propagatedName = cmtBean.updateEntity(id, name.toLowerCase());
+
+ return propagatedName.equals(name.toUpperCase());
+ }
+}
\ No newline at end of file
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/IntermediateStatefulRemote.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/IntermediateStatefulRemote.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/IntermediateStatefulRemote.java 2008-02-11 20:09:09 UTC (rev 69779)
@@ -0,0 +1,30 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.epcpropagation;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public interface IntermediateStatefulRemote
+{
+ public boolean execute(Integer id, String name) throws Exception;
+}
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/MyEntity.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/MyEntity.java 2008-02-11 20:07:17 UTC (rev 69778)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/MyEntity.java 2008-02-11 20:09:09 UTC (rev 69779)
@@ -67,4 +67,9 @@
{
this.name = name;
}
+
+ public String toString()
+ {
+ return "MyEntity:id=" + id + ",name=" + name;
+ }
}
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/NoTxEPCStatefulBean.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/NoTxEPCStatefulBean.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/NoTxEPCStatefulBean.java 2008-02-11 20:09:09 UTC (rev 69779)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.epcpropagation;
+
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.ejb.Local;
+import javax.ejb.Remote;
+import javax.ejb.SessionContext;
+import javax.ejb.Stateful;
+import javax.ejb.TransactionManagement;
+import javax.ejb.TransactionManagementType;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceContextType;
+import javax.transaction.Status;
+import javax.transaction.UserTransaction;
+
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at Stateful
+ at TransactionManagement(TransactionManagementType.BEAN)
+ at Remote(StatefulRemote.class)
+public class NoTxEPCStatefulBean implements StatefulRemote
+{
+ private static final Logger log = Logger.getLogger(NoTxEPCStatefulBean.class);
+
+ @PersistenceContext(type=PersistenceContextType.EXTENDED, unitName="mypc")
+ EntityManager em;
+
+ @Resource
+ SessionContext sessionContext;
+
+ @EJB
+ StatelessRemote cmtBean;
+
+ public boolean execute(Integer id, String name) throws Exception
+ {
+ MyEntity eb = em.find(MyEntity.class, id);
+ eb.setName(name.toUpperCase());
+
+ String propagatedName = cmtBean.updateEntity(id, name.toLowerCase());
+
+ return propagatedName.equals(name.toUpperCase());
+ }
+}
\ No newline at end of file
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/NoTxStatefulBean.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/NoTxStatefulBean.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/NoTxStatefulBean.java 2008-02-11 20:09:09 UTC (rev 69779)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.epcpropagation;
+
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.ejb.Local;
+import javax.ejb.Remote;
+import javax.ejb.SessionContext;
+import javax.ejb.Stateful;
+import javax.ejb.TransactionManagement;
+import javax.ejb.TransactionManagementType;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceContextType;
+import javax.transaction.Status;
+import javax.transaction.UserTransaction;
+
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at Stateful
+ at TransactionManagement(TransactionManagementType.BEAN)
+ at Remote(StatefulRemote.class)
+public class NoTxStatefulBean implements StatefulRemote
+{
+ private static final Logger log = Logger.getLogger(NoTxStatefulBean.class);
+
+ @PersistenceContext(unitName="mypc")
+ EntityManager em;
+
+ @Resource
+ SessionContext sessionContext;
+
+ @EJB
+ StatelessRemote cmtBean;
+
+ public boolean execute(Integer id, String name) throws Exception
+ {
+ MyEntity eb = em.find(MyEntity.class, id);
+ eb.setName(name.toUpperCase());
+
+ String propagatedName = cmtBean.updateEntity(id, name.toLowerCase());
+
+ return propagatedName.equals(name.toUpperCase());
+ }
+}
\ No newline at end of file
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/StatefulBean.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/StatefulBean.java 2008-02-11 20:07:17 UTC (rev 69778)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/StatefulBean.java 2008-02-11 20:09:09 UTC (rev 69779)
@@ -47,7 +47,7 @@
{
private static final Logger log = Logger.getLogger(StatefulBean.class);
- @PersistenceContext(type=PersistenceContextType.EXTENDED,unitName="mypc")
+ @PersistenceContext(unitName="mypc")
EntityManager em;
@Resource
@@ -56,38 +56,32 @@
@EJB
StatelessRemote cmtBean;
- public boolean execute(Integer pId, String pName)
+ public boolean execute(Integer id, String name) throws Exception
{
-
try
{
UserTransaction tx1 = sessionContext.getUserTransaction();
- log.info("!!!!! execute tx1 " + tx1 + " " + tx1.getStatus());
tx1.begin();
- log.info("!!!!! execute begin " + tx1.getStatus());
em.joinTransaction();
- MyEntity eb = em.find(MyEntity.class, pId);
- eb.setName(pName.toUpperCase());
- cmtBean.updateEntity(pId, pName.toLowerCase());
- UserTransaction tx2 = sessionContext.getUserTransaction();
- log.info("!!!!! execute tx2 " + tx2 + " " + tx2.getStatus());
+ MyEntity entity = em.find(MyEntity.class, id);
+ entity.setName(name.toUpperCase());
+
+ String propagatedName = cmtBean.updateEntity(id, name.toLowerCase());
tx1.commit();
- log.info("!!!! execute state " + tx1.getStatus() + " " + tx2.getStatus() + " " + Status.STATUS_NO_TRANSACTION);
- return true;
+ return propagatedName.equals(name.toUpperCase());
}
catch (Exception e)
{
- e.printStackTrace();
try
{
sessionContext.getUserTransaction().rollback();
}
catch (Exception e1)
{
- System.out.println("ROLLBACK: "+e1);
+ log.info("ROLLBACK: "+e1);
}
- return false;
+ throw e;
}
}
}
\ No newline at end of file
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/StatefulRemote.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/StatefulRemote.java 2008-02-11 20:07:17 UTC (rev 69778)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/StatefulRemote.java 2008-02-11 20:09:09 UTC (rev 69779)
@@ -26,5 +26,5 @@
*/
public interface StatefulRemote
{
- public boolean execute(Integer pId, String pName);
+ public boolean execute(Integer id, String name) throws Exception;
}
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/StatelessBean.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/StatelessBean.java 2008-02-11 20:07:17 UTC (rev 69778)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/StatelessBean.java 2008-02-11 20:09:09 UTC (rev 69779)
@@ -55,33 +55,27 @@
TransactionManager tm;
@TransactionAttribute(TransactionAttributeType.REQUIRED)
- public void createEntity(Integer pId, String pName)
+ public void createEntity(Integer id, String name)
{
- MyEntity eb = em.find(MyEntity.class, pId);
- if (eb == null)
+ MyEntity entity = em.find(MyEntity.class, id);
+ if (entity == null)
{
- eb = new MyEntity();
- eb.setId(pId);
- em.persist(eb);
+ entity = new MyEntity();
+ entity.setId(id);
+ em.persist(entity);
}
- eb.setName(pName);
+ entity.setName(name);
}
@TransactionAttribute(TransactionAttributeType.REQUIRED)
- public void updateEntity(Integer pId, String pName)
+ public String updateEntity(Integer id, String name)
{
- MyEntity eb = em.find(MyEntity.class, pId);
- eb.setName(pName);
+ MyEntity entity = em.find(MyEntity.class, id);
+ String propagatedName = entity.getName();
- try
- {
- Transaction tx = tm.getTransaction();
- log.info("!! updateEntity " + tx + " " + tx.getStatus());
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
+ entity.setName(name);
+
+ return propagatedName;
}
}
\ No newline at end of file
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/StatelessRemote.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/StatelessRemote.java 2008-02-11 20:07:17 UTC (rev 69778)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/StatelessRemote.java 2008-02-11 20:09:09 UTC (rev 69779)
@@ -26,7 +26,7 @@
*/
public interface StatelessRemote
{
- public void createEntity(Integer pId, String pName);
+ public void createEntity(Integer id, String name);
- public void updateEntity(Integer pId, String pName);
+ public String updateEntity(Integer id, String name);
}
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/unit/EPCPropagationTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/unit/EPCPropagationTestCase.java 2008-02-11 20:07:17 UTC (rev 69778)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/epcpropagation/unit/EPCPropagationTestCase.java 2008-02-11 20:09:09 UTC (rev 69779)
@@ -40,16 +40,83 @@
super(name);
}
- public void testPropagation() throws Exception
+ public void testBMTPropagation() throws Exception
{
StatelessRemote stateless = (StatelessRemote) new InitialContext().lookup("StatelessBean/remote");
stateless.createEntity(1, "EntityName");
StatefulRemote stateful = (StatefulRemote) new InitialContext().lookup("StatefulBean/remote");
- stateful.execute(1, "EntityName");
-
+ boolean equal = stateful.execute(1, "EntityName");
+
+ assertTrue("Name changes should propagate", equal);
}
+ public void testBMTEPCPropagation() throws Exception
+ {
+ StatelessRemote stateless = (StatelessRemote) new InitialContext().lookup("StatelessBean/remote");
+ stateless.createEntity(2, "EntityName");
+
+ StatefulRemote stateful = (StatefulRemote) new InitialContext().lookup("EPCStatefulBean/remote");
+ boolean equal = stateful.execute(2, "EntityName");
+
+ assertTrue("Name changes should propagate", equal);
+ }
+
+ public void testCMTPropagation() throws Exception
+ {
+ StatelessRemote stateless = (StatelessRemote) new InitialContext().lookup("StatelessBean/remote");
+ stateless.createEntity(3, "EntityName");
+
+ StatefulRemote stateful = (StatefulRemote) new InitialContext().lookup("CMTStatefulBean/remote");
+ boolean equal = stateful.execute(3, "EntityName");
+
+ assertTrue("Name changes should propagate", equal);
+ }
+
+ public void testCMTEPCPropagation() throws Exception
+ {
+ StatelessRemote stateless = (StatelessRemote) new InitialContext().lookup("StatelessBean/remote");
+ stateless.createEntity(4, "EntityName");
+
+ StatefulRemote stateful = (StatefulRemote) new InitialContext().lookup("CMTEPCStatefulBean/remote");
+ boolean equal = stateful.execute(4, "EntityName");
+
+ assertTrue("Name changes should propagate", equal);
+ }
+
+ public void testNoTxPropagation() throws Exception
+ {
+ StatelessRemote stateless = (StatelessRemote) new InitialContext().lookup("StatelessBean/remote");
+ stateless.createEntity(5, "EntityName");
+
+ StatefulRemote stateful = (StatefulRemote) new InitialContext().lookup("NoTxStatefulBean/remote");
+ boolean equal = stateful.execute(5, "EntityName");
+
+ assertFalse("Name changes should not propagate", equal);
+ }
+
+ public void testNoTxEPCPropagation() throws Exception
+ {
+ StatelessRemote stateless = (StatelessRemote) new InitialContext().lookup("StatelessBean/remote");
+ stateless.createEntity(6, "EntityName");
+
+ StatefulRemote stateful = (StatefulRemote) new InitialContext().lookup("NoTxEPCStatefulBean/remote");
+ boolean equal = stateful.execute(6, "EntityName");
+
+ assertTrue("Name changes should propagate", equal);
+ }
+
+ public void testIntermediateEPCPropagation() throws Exception
+ {
+ StatelessRemote stateless = (StatelessRemote) new InitialContext().lookup("StatelessBean/remote");
+ stateless.createEntity(7, "EntityName");
+
+ StatefulRemote stateful = (StatefulRemote) new InitialContext().lookup("InitEPCStatefulBean/remote");
+ boolean equal = stateful.execute(7, "EntityName");
+
+ assertTrue("Name changes should propagate", equal);
+ }
+
public static Test suite() throws Exception
{
return getDeploySetup(EPCPropagationTestCase.class, "epcpropagation-test.jar");
More information about the jboss-cvs-commits
mailing list