[jboss-cvs] JBossAS SVN: r64477 - in trunk/ejb3: src/resources/test and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Aug 7 03:46:10 EDT 2007


Author: wolfc
Date: 2007-08-07 03:46:10 -0400 (Tue, 07 Aug 2007)
New Revision: 64477

Added:
   trunk/ejb3/src/resources/test/xpcalt/
   trunk/ejb3/src/resources/test/xpcalt/META-INF/
   trunk/ejb3/src/resources/test/xpcalt/META-INF/persistence.xml
   trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/
   trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/Inspector.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/InspectorBean.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/LowEnd.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/LowEndBean.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/Master.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/MasterBean.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/Thingy.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/XPCAltBean.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/unit/
   trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/unit/XPCAltTestCase.java
Modified:
   trunk/ejb3/build-test.xml
Log:
EJBTHREE-1026: proof of concept

Modified: trunk/ejb3/build-test.xml
===================================================================
--- trunk/ejb3/build-test.xml	2007-08-07 06:51:06 UTC (rev 64476)
+++ trunk/ejb3/build-test.xml	2007-08-07 07:46:10 UTC (rev 64477)
@@ -2505,6 +2505,10 @@
       </copy>
    </target>
 
+   <target name="lifecycle" depends="compile-classes">
+      <build-simple-jar name="lifecycle"/>
+   </target>
+   
    <target name="longlived"
       description="Builds all jar files."
       depends="compile-classes">
@@ -3344,6 +3348,10 @@
       </jar>
    </target>
 
+   <target name="xpcalt" depends="compile-classes">
+      <build-simple-jar name="xpcalt"/>
+   </target>
+   
    <target name="clusteredentity"
       description="Builds all jar files."
       depends="compile-classes">

Added: trunk/ejb3/src/resources/test/xpcalt/META-INF/persistence.xml
===================================================================
--- trunk/ejb3/src/resources/test/xpcalt/META-INF/persistence.xml	                        (rev 0)
+++ trunk/ejb3/src/resources/test/xpcalt/META-INF/persistence.xml	2007-08-07 07:46:10 UTC (rev 64477)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence>
+   <persistence-unit name="tempdb">
+      <jta-data-source>java:/DefaultDS</jta-data-source>
+      <properties>
+          <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
+      </properties>
+   </persistence-unit>
+</persistence>


Property changes on: trunk/ejb3/src/resources/test/xpcalt/META-INF/persistence.xml
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/Inspector.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/Inspector.java	                        (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/Inspector.java	2007-08-07 07:46:10 UTC (rev 64477)
@@ -0,0 +1,36 @@
+/*
+ * 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.test.xpcalt;
+
+import javax.ejb.Remote;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Remote
+public interface Inspector
+{
+   <T> T find(Class<T> cls, Object id);
+}


Property changes on: trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/Inspector.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/InspectorBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/InspectorBean.java	                        (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/InspectorBean.java	2007-08-07 07:46:10 UTC (rev 64477)
@@ -0,0 +1,44 @@
+/*
+ * 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.test.xpcalt;
+
+import javax.ejb.Stateless;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+/**
+ * A stateless bean to check on the persistence unit
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateless
+public class InspectorBean implements Inspector
+{
+   @PersistenceContext
+   private EntityManager em;
+   
+   public <T> T find(Class<T> cls, Object id)
+   {
+      return em.find(cls, id);
+   }
+}


Property changes on: trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/InspectorBean.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/LowEnd.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/LowEnd.java	                        (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/LowEnd.java	2007-08-07 07:46:10 UTC (rev 64477)
@@ -0,0 +1,45 @@
+/*
+ * 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.test.xpcalt;
+
+import javax.ejb.Local;
+import javax.persistence.EntityManager;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Local
+public interface LowEnd
+{
+   void checkThingy(long id);
+   
+   long createThingy(long id);
+   
+   void doSomething();
+   
+   void remove();
+   
+   void setEntityManager(EntityManager em);
+}


Property changes on: trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/LowEnd.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/LowEndBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/LowEndBean.java	                        (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/LowEndBean.java	2007-08-07 07:46:10 UTC (rev 64477)
@@ -0,0 +1,113 @@
+/*
+ * 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.test.xpcalt;
+
+import static javax.ejb.TransactionAttributeType.NEVER;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.ejb.PostActivate;
+import javax.ejb.PrePassivate;
+import javax.ejb.Remove;
+import javax.ejb.Stateful;
+import javax.ejb.TransactionAttribute;
+import javax.persistence.EntityManager;
+
+import org.jboss.annotation.ejb.cache.simple.CacheConfig;
+import org.jboss.logging.Logger;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateful
+ at CacheConfig(idleTimeoutSeconds=5)
+public class LowEndBean implements LowEnd
+{
+   private static Logger log = Logger.getLogger(LowEndBean.class);
+   
+   //@PersistenceContext(type=EXTENDED)
+   // This time it's manual labour
+   private EntityManager em;
+   
+   @TransactionAttribute(NEVER)
+   public void checkThingy(long id)
+   {
+      Thingy thingy = em.find(Thingy.class, id);
+      if(thingy == null || thingy.getId() != id)
+         throw new IllegalStateException("can't find thingy with id " + id);
+   }
+   
+   @TransactionAttribute(NEVER)
+   public long createThingy(long id)
+   {
+      log.info("em = " + em);
+      
+      Thingy thingy = new Thingy(id);
+      em.persist(thingy);
+      return thingy.getId();
+   }
+   
+   public void doSomething()
+   {
+      log.info("doing something");
+   }
+   
+   @PostConstruct
+   protected void postConstruct()
+   {
+      log.info("postConstruct");
+   }
+   
+   @PostActivate
+   protected void postActivate()
+   {
+      log.info("postActivate");   
+   }
+   
+   @PreDestroy
+   protected void preDestroy()
+   {
+      log.info("preDestroy");
+   }
+   
+   @PrePassivate
+   protected void prePassivate()
+   {
+      log.info("prePassivate");
+   }
+   
+   @Remove
+   public void remove()
+   {
+   }
+   
+   /**
+    * Normally we inherit the entity manager, but this is all manual labour.
+    */
+   public void setEntityManager(EntityManager em)
+   {
+      this.em = em;
+   }
+}


Property changes on: trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/LowEndBean.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/Master.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/Master.java	                        (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/Master.java	2007-08-07 07:46:10 UTC (rev 64477)
@@ -0,0 +1,44 @@
+/*
+ * 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.test.xpcalt;
+
+import javax.ejb.Remote;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Remote
+public interface Master
+{
+   void checkThingy(long id);
+   
+   long createThingy(long id);
+   
+   void doSomething();
+   
+   void remove();
+   
+   void save();
+}


Property changes on: trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/Master.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/MasterBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/MasterBean.java	                        (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/MasterBean.java	2007-08-07 07:46:10 UTC (rev 64477)
@@ -0,0 +1,138 @@
+/*
+ * 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.test.xpcalt;
+
+import static javax.ejb.TransactionAttributeType.NEVER;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.ejb.EJB;
+import javax.ejb.PostActivate;
+import javax.ejb.PrePassivate;
+import javax.ejb.Remove;
+import javax.ejb.Stateful;
+import javax.ejb.TransactionAttribute;
+import javax.persistence.EntityManager;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+
+import org.jboss.annotation.JndiInject;
+import org.jboss.annotation.ejb.cache.simple.CacheConfig;
+import org.jboss.logging.Logger;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateful
+ at CacheConfig(idleTimeoutSeconds=5)
+public class MasterBean implements Master
+{
+   private static Logger log = Logger.getLogger(MasterBean.class);
+   
+   @EJB
+   private LowEnd lowEnd;
+   
+   //@PersistenceContext(type=EXTENDED)
+   @EJB(beanName="XPCAltBean")
+   private EntityManager em;
+   
+   @JndiInject(jndiName="java:/TransactionManager")
+   private TransactionManager tm;
+   
+   @TransactionAttribute(NEVER)
+   public long createThingy(long id)
+   {
+      log.info("em = " + em);
+      
+      long realId = lowEnd.createThingy(id);
+      Thingy thingy = em.find(Thingy.class, realId);
+      if(thingy == null || thingy.getId() != realId)
+         throw new IllegalStateException("can't find thingy with id " + realId);
+      return id;
+   }
+   
+   @TransactionAttribute(NEVER)
+   public void checkThingy(long id)
+   {
+      Thingy thingy = em.find(Thingy.class, id);
+      if(thingy == null || thingy.getId() != id)
+         throw new IllegalStateException("can't find thingy with id " + id);
+      
+      lowEnd.checkThingy(id);
+   }
+   
+   public void doSomething()
+   {
+      lowEnd.doSomething();
+   }
+   
+   @PostConstruct
+   protected void postConstruct()
+   {
+      log.info("postConstruct");
+      // manual labour
+      lowEnd.setEntityManager(em);
+   }
+   
+   @PostActivate
+   protected void postActivate()
+   {
+      log.info("postActivate");   
+   }
+   
+   @PreDestroy
+   protected void preDestroy()
+   {
+      log.info("preDestroy");
+   }
+   
+   @PrePassivate
+   protected void prePassivate()
+   {
+      log.info("prePassivate");
+   }
+   
+   @Remove
+   public void remove()
+   {
+      lowEnd.remove();
+      em.close();
+   }
+   
+   public void save()
+   {
+      try
+      {
+         if(tm.getTransaction() == null)
+            throw new RuntimeException("where is my transaction?");
+      }
+      catch (SystemException e)
+      {
+         throw new RuntimeException(e);
+      }
+      
+      em.flush();
+   }
+}


Property changes on: trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/MasterBean.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/Thingy.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/Thingy.java	                        (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/Thingy.java	2007-08-07 07:46:10 UTC (rev 64477)
@@ -0,0 +1,67 @@
+/*
+ * 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.test.xpcalt;
+
+import java.io.Serializable;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+/**
+ * A thingy
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Entity
+public class Thingy implements Serializable
+{
+   private static final long serialVersionUID = 1L;
+   
+   private Long id;
+   
+   public Thingy()
+   {
+      
+   }
+   
+   public Thingy(long id)
+   {
+      this.id = id;
+   }
+   
+   @Id
+   public Long getId()
+   {
+      return id;
+   }
+   
+   public void setId(Long id)
+   {
+      this.id = id;
+   }
+   
+   public String toString()
+   {
+      return super.toString() + "{id=" + id + "}";
+   }
+}


Property changes on: trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/Thingy.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/XPCAltBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/XPCAltBean.java	                        (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/XPCAltBean.java	2007-08-07 07:46:10 UTC (rev 64477)
@@ -0,0 +1,245 @@
+/*
+ * 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.test.xpcalt;
+
+import static javax.ejb.TransactionAttributeType.SUPPORTS;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.ejb.Local;
+import javax.ejb.PostActivate;
+import javax.ejb.PrePassivate;
+import javax.ejb.Remove;
+import javax.ejb.Stateful;
+import javax.ejb.TransactionAttribute;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
+import javax.persistence.FlushModeType;
+import javax.persistence.LockModeType;
+import javax.persistence.PersistenceUnit;
+import javax.persistence.Query;
+import javax.transaction.Status;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+
+import org.jboss.annotation.JndiInject;
+import org.jboss.annotation.ejb.cache.simple.CacheConfig;
+import org.jboss.logging.Logger;
+
+/**
+ * An alternative to extended persistence context.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateful
+ at Local(EntityManager.class)
+ at TransactionAttribute(SUPPORTS)
+ at CacheConfig(idleTimeoutSeconds=5)
+public class XPCAltBean implements EntityManager
+{
+   private static final Logger log = Logger.getLogger(XPCAltBean.class);
+   
+   @PersistenceUnit
+   private EntityManagerFactory emf;
+   
+   private EntityManager actualEntityManager;
+   
+   @JndiInject(jndiName="java:/TransactionManager")
+   private TransactionManager tm;
+   
+   @PostConstruct
+   protected void postConstruct()
+   {
+      this.actualEntityManager = emf.createEntityManager();
+   }
+   
+   @PostActivate
+   protected void postActivate()
+   {
+      log.info("postActivate");   
+   }
+   
+   @PreDestroy
+   protected void preDestroy()
+   {
+      this.actualEntityManager.close();
+   }
+   
+   @PrePassivate
+   protected void prePassivate()
+   {
+      log.info("prePassivate");
+   }
+   
+   public void clear()
+   {
+      actualEntityManager.clear();
+   }
+   
+   @Remove
+   public final void close()
+   {
+      // Normally this is illegal, but since we manage the lifecycle of XPCAlt ourselves this will remove the bean.
+      //throw new IllegalStateException("Closing a container managed entity manager is not allowed (EJB3 persistence 5.9.1)");
+   }
+   
+   public boolean contains(Object entity)
+   {
+      return actualEntityManager.contains(entity);
+   }
+   
+   public Query createNamedQuery(String name)
+   {
+      joinOptionalTransaction();
+      return actualEntityManager.createNamedQuery(name);
+   }
+   
+   public Query createNativeQuery(String sqlString)
+   {
+      joinOptionalTransaction();
+      return actualEntityManager.createNativeQuery(sqlString);
+   }
+   
+   public Query createNativeQuery(String sqlString, Class resultClass)
+   {
+      joinOptionalTransaction();
+      return actualEntityManager.createNativeQuery(sqlString, resultClass);
+   }
+   
+   public Query createNativeQuery(String sqlString, String resultSetMapping)
+   {
+      joinOptionalTransaction();
+      return actualEntityManager.createNativeQuery(sqlString, resultSetMapping);
+   }
+   
+   public Query createQuery(String qlString)
+   {
+      joinOptionalTransaction();
+      return actualEntityManager.createQuery(qlString);
+   }
+   
+   public <T> T find(Class<T> entityClass, Object primaryKey)
+   {
+      joinOptionalTransaction();
+      return actualEntityManager.find(entityClass, primaryKey);
+   }
+   
+   public void flush()
+   {
+      verifyInTx();
+      actualEntityManager.flush();
+   }
+   
+   public Object getDelegate()
+   {
+      return actualEntityManager.getDelegate();
+   }
+   
+   public FlushModeType getFlushMode()
+   {
+      return actualEntityManager.getFlushMode();
+   }
+   
+   public <T> T getReference(Class<T> entityClass, Object primaryKey)
+   {
+      joinOptionalTransaction();
+      return actualEntityManager.getReference(entityClass, primaryKey);
+   }
+   
+   public final EntityTransaction getTransaction()
+   {
+      throw new IllegalStateException("Not allowed on a JTA entity manager (EJB3 Persistence 3.1.1)");
+   }
+   
+   public boolean isOpen()
+   {
+      return actualEntityManager.isOpen();
+   }
+   
+   private void joinOptionalTransaction()
+   {
+      try
+      {
+         if(tm.getStatus() != Status.STATUS_NO_TRANSACTION)
+            actualEntityManager.joinTransaction();
+      }
+      catch (SystemException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+   
+   public void joinTransaction()
+   {
+      actualEntityManager.joinTransaction();
+   }
+   
+   public void lock(Object entity, LockModeType lockMode)
+   {
+      verifyInTx();
+      actualEntityManager.lock(entity, lockMode);
+   }
+   
+   public <T> T merge(T entity)
+   {
+      joinOptionalTransaction();
+      return actualEntityManager.merge(entity);
+   }
+   
+   public void persist(Object entity)
+   {
+      joinOptionalTransaction();
+      actualEntityManager.persist(entity);
+   }
+   
+   public void refresh(Object entity)
+   {
+      joinOptionalTransaction();
+      actualEntityManager.refresh(entity);
+   }
+   
+   public void remove(Object entity)
+   {
+      joinOptionalTransaction();
+      actualEntityManager.remove(entity);
+   }
+   
+   public void setFlushMode(FlushModeType flushMode)
+   {
+      actualEntityManager.setFlushMode(flushMode);
+   }
+   
+   private void verifyInTx()
+   {
+      try
+      {
+         log.info("tx status = " + tm.getStatus());
+      }
+      catch (SystemException e)
+      {
+         throw new RuntimeException(e);
+      }
+      joinTransaction();
+   }
+}


Property changes on: trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/XPCAltBean.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/unit/XPCAltTestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/unit/XPCAltTestCase.java	                        (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/unit/XPCAltTestCase.java	2007-08-07 07:46:10 UTC (rev 64477)
@@ -0,0 +1,105 @@
+/*
+ * 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.xpcalt.unit;
+
+import junit.framework.Test;
+
+import org.jboss.ejb3.test.xpcalt.Inspector;
+import org.jboss.ejb3.test.xpcalt.Master;
+import org.jboss.ejb3.test.xpcalt.Thingy;
+import org.jboss.logging.Logger;
+import org.jboss.test.JBossTestCase;
+
+/**
+ * Test the an alternative to extended persistence context.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class XPCAltTestCase extends JBossTestCase
+{
+   @SuppressWarnings("unused")
+   private static final Logger log = Logger.getLogger(XPCAltTestCase.class);
+
+   public XPCAltTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void test1() throws Exception
+   {
+      Master master = (Master) getInitialContext().lookup("MasterBean/remote");
+      
+      master.doSomething();
+      
+      master.remove();
+   }
+   
+   public void test2() throws Exception
+   {
+      Master master = (Master) getInitialContext().lookup("MasterBean/remote");
+      Inspector inspector = (Inspector) getInitialContext().lookup("InspectorBean/remote");
+      
+      long id = master.createThingy(2);
+      
+      Thingy thingy = inspector.find(Thingy.class, id);
+      assertNull("thingy should not have been committed", thingy);
+      
+      master.save();
+      
+      thingy = inspector.find(Thingy.class, id);
+      assertNotNull("thingy should have been committed", thingy);
+      assertEquals((Long) 2l, thingy.getId());
+      
+      master.remove();
+   }
+   
+   public void test3() throws Exception
+   {
+      Master master = (Master) getInitialContext().lookup("MasterBean/remote");
+      Inspector inspector = (Inspector) getInitialContext().lookup("InspectorBean/remote");
+      
+      long id = master.createThingy(3);
+      
+      Thingy thingy = inspector.find(Thingy.class, id);
+      assertNull("thingy should not have been committed", thingy);
+      
+      // make sure everything is passivated
+      sleep(10000);
+      
+      master.checkThingy(3);
+      
+      master.save();
+      
+      thingy = inspector.find(Thingy.class, id);
+      assertNotNull("thingy should have been committed", thingy);
+      assertEquals((Long) 3l, thingy.getId());
+      
+      master.remove();
+   }
+   
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(XPCAltTestCase.class, "xpcalt.jar");
+   }
+
+}


Property changes on: trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/unit/XPCAltTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native




More information about the jboss-cvs-commits mailing list