geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r437177 - in /geronimo/sandbox/jee5-jta/transaction/src: java/org/apache/geronimo/transaction/jpa/ test/org/apache/geronimo/transaction/jpa/ test/org/apache/geronimo/transaction/mockjpa/
Date Sat, 26 Aug 2006 16:18:52 GMT
Author: djencks
Date: Sat Aug 26 09:18:51 2006
New Revision: 437177

URL: http://svn.apache.org/viewvc?rev=437177&view=rev
Log:
Add extended EntityManager support

Added:
    geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/CMPEntityManagerExtended.java   (with props)
    geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/CMPEntityManagerTxScoped.java   (contents, props changed)
      - copied, changed from r434167, geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/CMPEntityManager.java
    geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/EntityManagerExtendedRegistry.java   (with props)
    geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/EntityManagerWrapper.java   (with props)
    geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/InternalCMPEntityManagerExtended.java   (with props)
    geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/TransactionListener.java   (with props)
Removed:
    geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/CMPEntityManager.java
Modified:
    geronimo/sandbox/jee5-jta/transaction/src/test/org/apache/geronimo/transaction/jpa/CMPEntityManagerTest.java
    geronimo/sandbox/jee5-jta/transaction/src/test/org/apache/geronimo/transaction/mockjpa/MockEntityManager.java

Added: geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/CMPEntityManagerExtended.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/CMPEntityManagerExtended.java?rev=437177&view=auto
==============================================================================
--- geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/CMPEntityManagerExtended.java (added)
+++ geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/CMPEntityManagerExtended.java Sat Aug 26 09:18:51 2006
@@ -0,0 +1,163 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.transaction.jpa;
+
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
+import javax.persistence.FlushModeType;
+import javax.persistence.LockModeType;
+import javax.persistence.Query;
+
+import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CMPEntityManagerExtended implements EntityManager {
+
+    private final TransactionManagerImpl transactionManager;
+    private final String persistenceUnit;
+    private final EntityManagerFactory entityManagerFactory;
+    private final Map entityManagerProperties;
+    private final InternalCMPEntityManagerExtended entityManager;
+
+    public CMPEntityManagerExtended(TransactionManagerImpl transactionManager, String persistenceUnit, EntityManagerFactory entityManagerFactory, Map entityManagerProperties) {
+        this.transactionManager = transactionManager;
+        this.persistenceUnit = persistenceUnit;
+        this.entityManagerFactory = entityManagerFactory;
+        this.entityManagerProperties = entityManagerProperties;
+        entityManager = getEntityManager();
+    }
+
+    private InternalCMPEntityManagerExtended getEntityManager() {
+        InternalCMPEntityManagerExtended entityManager = EntityManagerExtendedRegistry.getEntityManager(persistenceUnit);
+        if (entityManager == null) {
+            entityManager = createEntityManager();
+            EntityManagerExtendedRegistry.putEntityManager(persistenceUnit, entityManager);
+        }
+        entityManager.registerBean();
+        return entityManager;
+    }
+
+    private InternalCMPEntityManagerExtended createEntityManager() {
+        EntityManager entityManager;
+        if (entityManagerProperties == null) {
+            entityManager = entityManagerFactory.createEntityManager();
+        } else {
+            entityManager = entityManagerFactory.createEntityManager(entityManagerProperties);
+        }
+        return new InternalCMPEntityManagerExtended(entityManager, persistenceUnit, transactionManager);
+    }
+
+    public void beanRemoved() {
+        entityManager.beanRemoved();
+    }
+
+
+    public void persist(Object o) {
+        entityManager.persist(o);
+    }
+
+    public <T>T merge(T t) {
+        return entityManager.merge(t);
+    }
+
+    public void remove(Object o) {
+        entityManager.remove(o);
+    }
+
+    public <T>T find(Class<T> aClass, Object o) {
+        return entityManager.find(aClass, o);
+    }
+
+    public <T>T getReference(Class<T> aClass, Object o) {
+        return entityManager.getReference(aClass, o);
+    }
+
+    public void flush() {
+        entityManager.flush();
+    }
+
+    public void setFlushMode(FlushModeType flushModeType) {
+        entityManager.setFlushMode(flushModeType);
+    }
+
+    public FlushModeType getFlushMode() {
+        return entityManager.getFlushMode();
+    }
+
+    public void lock(Object o, LockModeType lockModeType) {
+        entityManager.lock(o, lockModeType);
+    }
+
+    public void refresh(Object o) {
+        entityManager.refresh(o);
+    }
+
+    public void clear() {
+        entityManager.clear();
+    }
+
+    public boolean contains(Object o) {
+        return entityManager.contains(o);
+    }
+
+    public Query createQuery(String s) {
+        return entityManager.createQuery(s);
+    }
+
+    public Query createNamedQuery(String s) {
+        return entityManager.createNamedQuery(s);
+    }
+
+    public Query createNativeQuery(String s) {
+        return entityManager.createNativeQuery(s);
+    }
+
+    public Query createNativeQuery(String s, Class aClass) {
+        return entityManager.createNativeQuery(s, aClass);
+    }
+
+    public Query createNativeQuery(String s, String s1) {
+        return entityManager.createNativeQuery(s, s1);
+    }
+
+    public void close() {
+        throw new IllegalStateException("You cannot call close on a Container Managed Entity Manager");
+    }
+
+    public boolean isOpen() {
+        return true;
+    }
+
+    public EntityTransaction getTransaction() {
+        throw new IllegalStateException("You cannot call getTransaction on a container managed EntityManager");
+    }
+
+    public void joinTransaction() {
+        throw new IllegalStateException("You cannot call joinTransaction on a container managed EntityManager");
+    }
+
+    public Object getDelegate() {
+        return entityManager.getDelegate();
+    }
+
+}

Propchange: geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/CMPEntityManagerExtended.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/CMPEntityManagerExtended.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/CMPEntityManagerExtended.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/CMPEntityManagerTxScoped.java (from r434167, geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/CMPEntityManager.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/CMPEntityManagerTxScoped.java?p2=geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/CMPEntityManagerTxScoped.java&p1=geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/CMPEntityManager.java&r1=434167&r2=437177&rev=437177&view=diff
==============================================================================
--- geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/CMPEntityManager.java (original)
+++ geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/CMPEntityManagerTxScoped.java Sat Aug 26 09:18:51 2006
@@ -30,113 +30,288 @@
 
 import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
 import org.apache.geronimo.transaction.manager.TransactionImpl;
-import org.apache.geronimo.transaction.manager.Closeable;
 
 /**
- * @version $Rev:$ $Date:$
+ * @version $Rev$ $Date$
  */
-public class CMPEntityManager implements EntityManager {
+public class CMPEntityManagerTxScoped implements EntityManager {
 
     private final TransactionManagerImpl transactionManager;
     private final String persistenceUnit;
     private final EntityManagerFactory entityManagerFactory;
     private final Map entityManagerProperties;
-    private final boolean transactionScoped;
 
-    public CMPEntityManager(TransactionManagerImpl transactionManager, String persistenceUnit, EntityManagerFactory entityManagerFactory, Map entityManagerProperties, boolean transactionScoped) {
+    public CMPEntityManagerTxScoped(TransactionManagerImpl transactionManager, String persistenceUnit, EntityManagerFactory entityManagerFactory, Map entityManagerProperties) {
         this.transactionManager = transactionManager;
         this.persistenceUnit = persistenceUnit;
         this.entityManagerFactory = entityManagerFactory;
         this.entityManagerProperties = entityManagerProperties;
-        this.transactionScoped = transactionScoped;
     }
 
     private EntityManager getEntityManager(boolean activeRequired) {
         TransactionImpl transaction = (TransactionImpl) transactionManager.getTransaction();
-        if (transaction == null || (activeRequired && transaction.getStatus() != Status.STATUS_ACTIVE)) {
+        if (activeRequired && (transaction == null || transaction.getStatus() != Status.STATUS_ACTIVE)) {
             throw new TransactionRequiredException("No active transaction");
         }
+        if (transaction == null) {
+            return null;
+        }
         EntityManagerWrapper entityManagerWrapper = (EntityManagerWrapper) transaction.getEntityManager(persistenceUnit);
         if (entityManagerWrapper == null) {
-            EntityManager entityManager;
-            if (entityManagerProperties == null) {
-                entityManager = entityManagerFactory.createEntityManager();
-            } else {
-                entityManager = entityManagerFactory.createEntityManager(entityManagerProperties);
-            }
-            entityManagerWrapper =new EntityManagerWrapper(entityManager, transactionScoped);
+            EntityManager entityManager = createEntityManager();
+            entityManagerWrapper = new EntityManagerWrapperTxScoped(entityManager);
             transaction.setEntityManager(persistenceUnit, entityManagerWrapper);
         }
         return entityManagerWrapper.getEntityManager();
     }
 
+    private EntityManager createEntityManager() {
+        EntityManager entityManager;
+        if (entityManagerProperties == null) {
+            entityManager = entityManagerFactory.createEntityManager();
+        } else {
+            entityManager = entityManagerFactory.createEntityManager(entityManagerProperties);
+        }
+        return entityManager;
+    }
+
 
     public void persist(Object o) {
-        getEntityManager(transactionScoped).persist(o);
+        EntityManager entityManager = getEntityManager(true);
+        if (entityManager != null) {
+            entityManager.persist(o);
+        } else {
+            entityManager = createEntityManager();
+            try {
+                entityManager.persist(o);
+            } finally {
+                entityManager.close();
+            }
+        }
     }
 
     public <T>T merge(T t) {
-        return getEntityManager(transactionScoped).merge(t);
+        EntityManager entityManager = getEntityManager(true);
+        if (entityManager != null) {
+            return entityManager.merge(t);
+        } else {
+            entityManager = createEntityManager();
+            try {
+                return entityManager.merge(t);
+            } finally {
+                entityManager.close();
+            }
+        }
     }
 
     public void remove(Object o) {
-        getEntityManager(transactionScoped).remove(o);
+        EntityManager entityManager = getEntityManager(true);
+        if (entityManager != null) {
+            entityManager.remove(o);
+        } else {
+            entityManager = createEntityManager();
+            try {
+                entityManager.remove(o);
+            } finally {
+                entityManager.close();
+            }
+        }
     }
 
     public <T>T find(Class<T> aClass, Object o) {
-        return getEntityManager(false).find(aClass, o);
+        EntityManager entityManager = getEntityManager(false);
+        if (entityManager != null) {
+            return entityManager.find(aClass, o);
+        } else {
+            entityManager = createEntityManager();
+            try {
+                return entityManager.find(aClass, o);
+            } finally {
+                entityManager.close();
+            }
+        }
     }
 
     public <T>T getReference(Class<T> aClass, Object o) {
-        return getEntityManager(false).getReference(aClass, o);
+        EntityManager entityManager = getEntityManager(false);
+        if (entityManager != null) {
+            return entityManager.getReference(aClass, o);
+        } else {
+            entityManager = createEntityManager();
+            try {
+                return entityManager.getReference(aClass, o);
+            } finally {
+                entityManager.close();
+            }
+        }
     }
 
     public void flush() {
-        getEntityManager(false).flush();
+        EntityManager entityManager = getEntityManager(false);
+        if (entityManager != null) {
+            entityManager.flush();
+        } else {
+            entityManager = createEntityManager();
+            try {
+                entityManager.flush();
+            } finally {
+                entityManager.close();
+            }
+        }
     }
 
     public void setFlushMode(FlushModeType flushModeType) {
-        getEntityManager(false).setFlushMode(flushModeType);
+        EntityManager entityManager = getEntityManager(false);
+        if (entityManager != null) {
+             entityManager.setFlushMode(flushModeType);
+        } else {
+            entityManager = createEntityManager();
+            try {
+                 entityManager.setFlushMode(flushModeType);
+            } finally {
+                entityManager.close();
+            }
+        }
     }
 
     public FlushModeType getFlushMode() {
-        return getEntityManager(false).getFlushMode();
+        EntityManager entityManager = getEntityManager(false);
+        if (entityManager != null) {
+            return entityManager.getFlushMode();
+        } else {
+            entityManager = createEntityManager();
+            try {
+                return entityManager.getFlushMode();
+            } finally {
+                entityManager.close();
+            }
+        }
     }
 
     public void lock(Object o, LockModeType lockModeType) {
-        getEntityManager(false).lock(o, lockModeType);
+        EntityManager entityManager = getEntityManager(false);
+        if (entityManager != null) {
+             entityManager.lock(o, lockModeType);
+        } else {
+            entityManager = createEntityManager();
+            try {
+                 entityManager.lock(o, lockModeType);
+            } finally {
+                entityManager.close();
+            }
+        }
     }
 
     public void refresh(Object o) {
-        getEntityManager(transactionScoped).refresh(o);
+        EntityManager entityManager = getEntityManager(true);
+        if (entityManager != null) {
+             entityManager.refresh(o);
+        } else {
+            entityManager = createEntityManager();
+            try {
+                 entityManager.refresh(o);
+            } finally {
+                entityManager.close();
+            }
+        }
     }
 
     public void clear() {
-        getEntityManager(false).clear();
+        EntityManager entityManager = getEntityManager(false);
+        if (entityManager != null) {
+             entityManager.clear();
+        } else {
+            entityManager = createEntityManager();
+            try {
+                 entityManager.clear();
+            } finally {
+                entityManager.close();
+            }
+        }
     }
 
     public boolean contains(Object o) {
-        return getEntityManager(false).contains(o);
+        EntityManager entityManager = getEntityManager(false);
+        if (entityManager != null) {
+            return entityManager.contains(o);
+        } else {
+            entityManager = createEntityManager();
+            try {
+                return entityManager.contains(o);
+            } finally {
+                entityManager.close();
+            }
+        }
     }
 
     public Query createQuery(String s) {
-        return getEntityManager(false).createQuery(s);
+        EntityManager entityManager = getEntityManager(false);
+        if (entityManager != null) {
+            return entityManager.createQuery(s);
+        } else {
+            entityManager = createEntityManager();
+            try {
+                return entityManager.createQuery(s);
+            } finally {
+                entityManager.close();
+            }
+        }
     }
 
     public Query createNamedQuery(String s) {
-        return getEntityManager(false).createNamedQuery(s);
+        EntityManager entityManager = getEntityManager(false);
+        if (entityManager != null) {
+            return entityManager.createNamedQuery(s);
+        } else {
+            entityManager = createEntityManager();
+            try {
+                return entityManager.createNamedQuery(s);
+            } finally {
+                entityManager.close();
+            }
+        }
     }
 
     public Query createNativeQuery(String s) {
-        return getEntityManager(false).createNativeQuery(s);
+        EntityManager entityManager = getEntityManager(false);
+        if (entityManager != null) {
+            return entityManager.createNativeQuery(s);
+        } else {
+            entityManager = createEntityManager();
+            try {
+                return entityManager.createNativeQuery(s);
+            } finally {
+                entityManager.close();
+            }
+        }
     }
 
     public Query createNativeQuery(String s, Class aClass) {
-        return getEntityManager(false).createNativeQuery(s, aClass);
+        EntityManager entityManager = getEntityManager(false);
+        if (entityManager != null) {
+            return entityManager.createNativeQuery(s, aClass);
+        } else {
+            entityManager = createEntityManager();
+            try {
+                return entityManager.createNativeQuery(s, aClass);
+            } finally {
+                entityManager.close();
+            }
+        }
     }
 
     public Query createNativeQuery(String s, String s1) {
-        return getEntityManager(false).createNativeQuery(s, s1);
+        EntityManager entityManager = getEntityManager(false);
+        if (entityManager != null) {
+            return entityManager.createNativeQuery(s, s1);
+        } else {
+            entityManager = createEntityManager();
+            try {
+                return entityManager.createNativeQuery(s, s1);
+            } finally {
+                entityManager.close();
+            }
+        }
     }
 
     public void close() {
@@ -144,37 +319,43 @@
     }
 
     public boolean isOpen() {
-        return getEntityManager(false).isOpen();
+        return true;
     }
 
     public EntityTransaction getTransaction() {
-        return getEntityManager(false).getTransaction();
+        throw new IllegalStateException("You cannot call getTransaction on a container managed EntityManager");
     }
 
     public void joinTransaction() {
-        getEntityManager(false).joinTransaction();
+        throw new IllegalStateException("You cannot call joinTransaction on a container managed EntityManager");
     }
 
     public Object getDelegate() {
-        return getEntityManager(false).getDelegate();
+        EntityManager entityManager = getEntityManager(false);
+        if (entityManager != null) {
+            return entityManager.getDelegate();
+        } else {
+            entityManager = createEntityManager();
+            try {
+                return entityManager.getDelegate();
+            } finally {
+                entityManager.close();
+            }
+        }
     }
 
-    private static class EntityManagerWrapper implements Closeable {
+    private static class EntityManagerWrapperTxScoped implements EntityManagerWrapper {
         private final EntityManager entityManager;
-        private final boolean transactionScoped;
 
-        public EntityManagerWrapper(EntityManager entityManager, boolean transactionScoped) {
+        public EntityManagerWrapperTxScoped(EntityManager entityManager) {
             if (entityManager == null) {
                 throw new IllegalArgumentException("Need a non-null entity manager");
             }
             this.entityManager = entityManager;
-            this.transactionScoped = transactionScoped;
         }
 
         public void close() {
-            if (transactionScoped) {
                 entityManager.close();
-            }
         }
 
         public EntityManager getEntityManager() {

Propchange: geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/CMPEntityManagerTxScoped.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/CMPEntityManagerTxScoped.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/CMPEntityManagerTxScoped.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/EntityManagerExtendedRegistry.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/EntityManagerExtendedRegistry.java?rev=437177&view=auto
==============================================================================
--- geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/EntityManagerExtendedRegistry.java (added)
+++ geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/EntityManagerExtendedRegistry.java Sat Aug 26 09:18:51 2006
@@ -0,0 +1,66 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.transaction.jpa;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import javax.transaction.Transaction;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class EntityManagerExtendedRegistry {
+
+    private static final ThreadLocal<Map<String, InternalCMPEntityManagerExtended>> entityManagerMaps = new ThreadLocal<Map<String, InternalCMPEntityManagerExtended>>() {
+        protected Map<String, InternalCMPEntityManagerExtended> initialValue() {
+            return new HashMap<String, InternalCMPEntityManagerExtended>();
+        }
+    };
+
+    public static InternalCMPEntityManagerExtended getEntityManager(String persistenceUnit) {
+        Map<String, InternalCMPEntityManagerExtended> entityManagerMap = entityManagerMaps.get();
+        return entityManagerMap.get(persistenceUnit);
+    }
+
+    public static void putEntityManager(String persistenceUnit, InternalCMPEntityManagerExtended entityManager) {
+        Map<String, InternalCMPEntityManagerExtended> entityManagerMap = entityManagerMaps.get();
+        InternalCMPEntityManagerExtended oldEntityManager = entityManagerMap.put(persistenceUnit, entityManager);
+        if (oldEntityManager != null) {
+            throw new IllegalStateException("There was already an EntityManager registered for persistenceUnit " + persistenceUnit);
+        }
+    }
+
+    public static void clearEntityManager(String persistenceUnit) {
+        Map<String, InternalCMPEntityManagerExtended> entityManagerMap = entityManagerMaps.get();
+        entityManagerMap.remove(persistenceUnit);
+    }
+
+    public static void threadAssociated(Transaction transaction) {
+        Map<String, InternalCMPEntityManagerExtended> entityManagerMap = entityManagerMaps.get();
+        for (Iterator i = entityManagerMap.values().iterator(); i.hasNext(); ) {
+            InternalCMPEntityManagerExtended entityManager = (InternalCMPEntityManagerExtended) i.next();
+            entityManager.joinTransaction();
+        }
+    }
+
+    public static void threadUnassociated(Transaction transaction) {
+        //Any way to unassociate?
+    }
+}

Propchange: geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/EntityManagerExtendedRegistry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/EntityManagerExtendedRegistry.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/EntityManagerExtendedRegistry.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/EntityManagerWrapper.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/EntityManagerWrapper.java?rev=437177&view=auto
==============================================================================
--- geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/EntityManagerWrapper.java (added)
+++ geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/EntityManagerWrapper.java Sat Aug 26 09:18:51 2006
@@ -0,0 +1,31 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.transaction.jpa;
+
+import javax.persistence.EntityManager;
+
+import org.apache.geronimo.transaction.manager.Closeable;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public interface EntityManagerWrapper extends Closeable {
+
+    EntityManager getEntityManager();
+    
+}

Propchange: geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/EntityManagerWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/EntityManagerWrapper.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/EntityManagerWrapper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/InternalCMPEntityManagerExtended.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/InternalCMPEntityManagerExtended.java?rev=437177&view=auto
==============================================================================
--- geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/InternalCMPEntityManagerExtended.java (added)
+++ geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/InternalCMPEntityManagerExtended.java Sat Aug 26 09:18:51 2006
@@ -0,0 +1,161 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.transaction.jpa;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+import javax.persistence.FlushModeType;
+import javax.persistence.LockModeType;
+import javax.persistence.Query;
+
+import org.apache.geronimo.transaction.manager.TransactionImpl;
+import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
+
+/**
+ * InternalCMPEntityManagerExtended is an EntityManager wrapper that CMPEntityManagerExtended wraps the
+ * real EntityManager with and registers with the transaction.
+ *
+ * @version $Rev$ $Date$
+ */
+public class InternalCMPEntityManagerExtended implements EntityManager, EntityManagerWrapper {
+
+    private final EntityManager entityManager;
+    private final String persistenceUnit;
+    private final TransactionManagerImpl transactionManager;
+    //Does this need to be thread safe???
+    private final AtomicInteger count = new AtomicInteger();
+
+    public InternalCMPEntityManagerExtended(EntityManager entityManager, String persistenceUnit, TransactionManagerImpl transactionManager) {
+        this.entityManager = entityManager;
+        this.persistenceUnit = persistenceUnit;
+        this.transactionManager = transactionManager;
+        if (transactionManager.getTransaction() != null) {
+            joinTransaction();
+        }
+    }
+
+    void registerBean() {
+        count.getAndIncrement();
+    }
+
+    void beanRemoved() {
+        if (count.decrementAndGet() ==0 ) {
+            entityManager.close();
+            EntityManagerExtendedRegistry.clearEntityManager(persistenceUnit);
+        }
+
+    }
+
+    public EntityManager getEntityManager() {
+        return entityManager;
+    }
+
+    public void persist(Object o) {
+        entityManager.persist(o);
+    }
+
+    public <T>T merge(T t) {
+        return entityManager.merge(t);
+    }
+
+    public void remove(Object o) {
+        entityManager.remove(o);
+    }
+
+    public <T>T find(Class<T> aClass, Object o) {
+        return entityManager.find(aClass, o);
+    }
+
+    public <T>T getReference(Class<T> aClass, Object o) {
+        return entityManager.getReference(aClass, o);
+    }
+
+    public void flush() {
+        entityManager.flush();
+    }
+
+    public void setFlushMode(FlushModeType flushModeType) {
+        entityManager.setFlushMode(flushModeType);
+    }
+
+    public FlushModeType getFlushMode() {
+        return entityManager.getFlushMode();
+    }
+
+    public void lock(Object o, LockModeType lockModeType) {
+        entityManager.lock(o, lockModeType);
+    }
+
+    public void refresh(Object o) {
+        entityManager.refresh(o);
+    }
+
+    public void clear() {
+        entityManager.clear();
+    }
+
+    public boolean contains(Object o) {
+        return entityManager.contains(o);
+    }
+
+    public Query createQuery(String s) {
+        return entityManager.createQuery(s);
+    }
+
+    public Query createNamedQuery(String s) {
+        return entityManager.createNamedQuery(s);
+    }
+
+    public Query createNativeQuery(String s) {
+        return entityManager.createNativeQuery(s);
+    }
+
+    public Query createNativeQuery(String s, Class aClass) {
+        return entityManager.createNativeQuery(s, aClass);
+    }
+
+    public Query createNativeQuery(String s, String s1) {
+        return entityManager.createNativeQuery(s, s1);
+    }
+
+    public void close() {
+        //a no-op
+    }
+
+    public boolean isOpen() {
+        return true;
+    }
+
+    public EntityTransaction getTransaction() {
+        throw new IllegalStateException("You cannot call getTransaction on a container managed EntityManager");
+    }
+
+    public void joinTransaction() {
+            TransactionImpl transaction = (TransactionImpl) transactionManager.getTransaction();
+            //This checks section 5.6.3.1, throwing an EJBException if there is already a PersistenceContext.
+            transaction.setEntityManager(persistenceUnit, this);
+        entityManager.joinTransaction();
+    }
+
+    public Object getDelegate() {
+        return entityManager.getDelegate();
+    }
+
+}

Propchange: geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/InternalCMPEntityManagerExtended.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/InternalCMPEntityManagerExtended.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/InternalCMPEntityManagerExtended.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/TransactionListener.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/TransactionListener.java?rev=437177&view=auto
==============================================================================
--- geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/TransactionListener.java (added)
+++ geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/TransactionListener.java Sat Aug 26 09:18:51 2006
@@ -0,0 +1,37 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.transaction.jpa;
+
+import javax.transaction.Transaction;
+
+import org.apache.geronimo.transaction.manager.TransactionManagerMonitor;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class TransactionListener implements TransactionManagerMonitor {
+
+    public void threadAssociated(Transaction transaction) {
+        EntityManagerExtendedRegistry.threadAssociated(transaction);
+    }
+
+    public void threadUnassociated(Transaction transaction) {
+        EntityManagerExtendedRegistry.threadUnassociated(transaction);
+    }
+    
+}

Propchange: geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/TransactionListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/TransactionListener.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/jee5-jta/transaction/src/java/org/apache/geronimo/transaction/jpa/TransactionListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/jee5-jta/transaction/src/test/org/apache/geronimo/transaction/jpa/CMPEntityManagerTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jee5-jta/transaction/src/test/org/apache/geronimo/transaction/jpa/CMPEntityManagerTest.java?rev=437177&r1=437176&r2=437177&view=diff
==============================================================================
--- geronimo/sandbox/jee5-jta/transaction/src/test/org/apache/geronimo/transaction/jpa/CMPEntityManagerTest.java (original)
+++ geronimo/sandbox/jee5-jta/transaction/src/test/org/apache/geronimo/transaction/jpa/CMPEntityManagerTest.java Sat Aug 26 09:18:51 2006
@@ -22,6 +22,7 @@
 
 import javax.persistence.EntityManager;
 import javax.persistence.TransactionRequiredException;
+import javax.ejb.EJBException;
 
 import junit.framework.TestCase;
 import org.apache.geronimo.transaction.jta11.GeronimoTransactionManagerJTA11;
@@ -29,7 +30,7 @@
 import org.apache.geronimo.transaction.mockjpa.MockEntityManager;
 
 /**
- * @version $Rev:$ $Date:$
+ * @version $Rev$ $Date$
  */
 public class CMPEntityManagerTest extends TestCase {
 
@@ -38,19 +39,153 @@
     private MockEntityManagerFactory entityManagerFactory;
 
     protected void setUp() throws Exception {
-        tm  = new GeronimoTransactionManagerJTA11();
+        tm = new GeronimoTransactionManagerJTA11();
+        tm.addTransactionAssociationListener(new TransactionListener());
         entityManagerFactory = new MockEntityManagerFactory();
     }
 
     /**
+     * section 3.1.1
+     * (not very clear).  getTransaction, joinTransaction throw IllegalStateException
+     */
+    public void testGetTransaction() throws Exception {
+        CMPEntityManagerTxScoped entityManager1 = new CMPEntityManagerTxScoped(tm, persistenceUnit, entityManagerFactory, null);
+        try {
+            entityManager1.getTransaction();
+            fail("Expected IllegalStateException");
+        } catch(IllegalStateException e) {
+            //expected
+        } catch (Exception e) {
+            fail("Wrong exception " + e);
+        }
+        tm.begin();
+        try {
+            entityManager1.getTransaction();
+            fail("Expected IllegalStateException");
+        } catch(IllegalStateException e) {
+            //expected
+        } catch (Exception e) {
+            fail("Wrong exception " + e);
+        }
+        tm.commit();
+    }
+
+    public void testJoinTransaction() throws Exception {
+        CMPEntityManagerTxScoped entityManager1 = new CMPEntityManagerTxScoped(tm, persistenceUnit, entityManagerFactory, null);
+        try {
+            entityManager1.joinTransaction();
+            fail("Expected IllegalStateException");
+        } catch(IllegalStateException e) {
+            //expected
+        } catch (Exception e) {
+            fail("Wrong exception " + e);
+        }
+        tm.begin();
+        try {
+            entityManager1.joinTransaction();
+            fail("Expected IllegalStateException");
+        } catch(IllegalStateException e) {
+            //expected
+        } catch (Exception e) {
+            fail("Wrong exception " + e);
+        }
+        tm.commit();
+    }
+
+    /**
+     * section 3.1.1 ????
+     * isOpen returns true
+     */
+    public void testIsOpen() throws Exception {
+        CMPEntityManagerTxScoped entityManager1 = new CMPEntityManagerTxScoped(tm, persistenceUnit, entityManagerFactory, null);
+        assertTrue(entityManager1.isOpen());
+        tm.begin();
+        assertTrue(entityManager1.isOpen());
+        tm.commit();
+        assertTrue(entityManager1.isOpen());
+        tm.begin();
+        assertTrue(entityManager1.isOpen());
+        tm.rollback();
+        assertTrue(entityManager1.isOpen());
+    }
+
+    /**
+     * section 5.6.2
+     * extended context is closed when the SFSB that caused it is removed
+     */
+    public void testExtendedClosedOnBeanRemove() throws Exception {
+        CMPEntityManagerExtended entityManager1 = new CMPEntityManagerExtended(tm, persistenceUnit, entityManagerFactory, null);
+        MockEntityManager pc1 = (MockEntityManager) entityManager1.find(EntityManager.class, "this");
+        assertTrue("base EntityManager should not be closed", !pc1.isClosed());
+        assertNotNull("InternalEntityManager should be registered", EntityManagerExtendedRegistry.getEntityManager(persistenceUnit));
+        entityManager1.beanRemoved();
+        assertTrue("base EntityManager should be closed", pc1.isClosed());
+        assertNull("InternalEntityManager should not be registered", EntityManagerExtendedRegistry.getEntityManager(persistenceUnit));
+    }
+
+    /**
+     * section 5.6.2.1
+     * extended context is closed when the SFSB that caused it and all others that share it are removed
+     */
+    public void testInheritedExtendedClosedOnBeanRemove() throws Exception {
+        CMPEntityManagerExtended entityManager1 = new CMPEntityManagerExtended(tm, persistenceUnit, entityManagerFactory, null);
+        MockEntityManager pc1 = (MockEntityManager) entityManager1.find(EntityManager.class, "this");
+        assertTrue("base EntityManager should not be closed", !pc1.isClosed());
+        InternalCMPEntityManagerExtended internalEntityManager1 = EntityManagerExtendedRegistry.getEntityManager(persistenceUnit);
+        assertNotNull("InternalEntityManager should be registered", internalEntityManager1);
+        CMPEntityManagerExtended entityManager2 = new CMPEntityManagerExtended(tm, persistenceUnit, entityManagerFactory, null);
+        InternalCMPEntityManagerExtended internalEntityManager2 = EntityManagerExtendedRegistry.getEntityManager(persistenceUnit);
+        //we should have got an exception if this isn't true
+        assertSame("2nd entity manager registering should use same internal entity manager", internalEntityManager1, internalEntityManager2);
+        MockEntityManager pc2 = (MockEntityManager) entityManager2.find(EntityManager.class, "this");
+        assertSame("2nd entity manager registering should use same mock entity manager", pc1, pc2);
+
+        //remove one bean, internal and mock entity managers should not change state
+        entityManager1.beanRemoved();
+        assertTrue("base EntityManager should not be closed", !pc1.isClosed());
+        assertNotNull("InternalEntityManager should be registered", EntityManagerExtendedRegistry.getEntityManager(persistenceUnit));
+
+        //close other bean, everything should close and unregister
+        entityManager2.beanRemoved();
+        assertTrue("base EntityManager should be closed", pc1.isClosed());
+        assertNull("InternalEntityManager should not be registered", EntityManagerExtendedRegistry.getEntityManager(persistenceUnit));
+    }
+
+    /**
+     * section 5.6.3.1
+     * Trying to propagate a JTA tx with a persistence context bound into a SFSB with Extended persistence context
+     * results in an EJBException
+     */
+    public void testNoSimultaneousEntityManagers() throws Exception {
+        //set up the extended persistence context:
+        CMPEntityManagerExtended entityManager1 = new CMPEntityManagerExtended(tm, persistenceUnit, entityManagerFactory, null);
+        //set up the caller
+        CMPEntityManagerTxScoped entityManager2 = new CMPEntityManagerTxScoped(tm, persistenceUnit, entityManagerFactory, null);
+        tm.begin();
+        //register the caller
+        MockEntityManager pc1 = (MockEntityManager) entityManager2.find(EntityManager.class, "this");
+        //caller calling SFSB means entityManager1 tries to join the trasaction:
+        InternalCMPEntityManagerExtended internalEntityManager = EntityManagerExtendedRegistry.getEntityManager(persistenceUnit);
+        try {
+            internalEntityManager.joinTransaction();
+            fail("Expected EJBException");
+        } catch (EJBException e) {
+            //expected
+        } catch (Exception e) {
+            fail("Unexpected exception " + e);
+        }
+        tm.commit();
+    }
+
+    /**
      * section 5.8.2
      * use the same persistence context for all work in a tx
      */
     public void testSamePersistenceContext() throws Exception {
         tm.begin();
-        CMPEntityManager entityManager1 = new CMPEntityManager(tm, persistenceUnit, entityManagerFactory, null, true);
+        CMPEntityManagerTxScoped entityManager1 = new CMPEntityManagerTxScoped(tm, persistenceUnit, entityManagerFactory, null);
         EntityManager pc1 = entityManager1.find(EntityManager.class, "this");
-        CMPEntityManager entityManager2 = new CMPEntityManager(tm, persistenceUnit, entityManagerFactory, null, true);
+        CMPEntityManagerTxScoped entityManager2 = new CMPEntityManagerTxScoped(tm, persistenceUnit, entityManagerFactory, null);
         EntityManager pc2 = entityManager2.find(EntityManager.class, "this");
         assertSame("Should get same entity manager for all work in a tx", pc1, pc2);
         tm.commit();
@@ -62,13 +197,13 @@
      */
     public void testCloseOnCommit() throws Exception {
         tm.begin();
-        CMPEntityManager entityManager1 = new CMPEntityManager(tm, persistenceUnit, entityManagerFactory, null, true);
+        CMPEntityManagerTxScoped entityManager1 = new CMPEntityManagerTxScoped(tm, persistenceUnit, entityManagerFactory, null);
         MockEntityManager pc1 = (MockEntityManager) entityManager1.find(EntityManager.class, "this");
         assertTrue("entityManager should not be closed or cleared", !pc1.isClosed() & !pc1.isCleared());
         tm.commit();
         assertTrue("entityManager should be closed or cleared", pc1.isClosed() || pc1.isCleared());
         tm.begin();
-        CMPEntityManager entityManager2 = new CMPEntityManager(tm, persistenceUnit, entityManagerFactory, null, true);
+        CMPEntityManagerTxScoped entityManager2 = new CMPEntityManagerTxScoped(tm, persistenceUnit, entityManagerFactory, null);
         MockEntityManager pc2 = (MockEntityManager) entityManager2.find(EntityManager.class, "this");
         assertTrue("entityManager should not be closed or cleared", !pc2.isClosed() & !pc2.isCleared());
         tm.rollback();
@@ -80,14 +215,14 @@
      * transaction required for persist, remove, merge, refresh
      */
     public void testTransactionRequired() throws Exception {
-        CMPEntityManager entityManager1 = new CMPEntityManager(tm, persistenceUnit, entityManagerFactory, null, true);
+        CMPEntityManagerTxScoped entityManager1 = new CMPEntityManagerTxScoped(tm, persistenceUnit, entityManagerFactory, null);
         try {
             entityManager1.persist("foo");
             fail("expected TransactionRequiredException");
         } catch (TransactionRequiredException e) {
             //expected
         } catch (Exception e) {
-            fail ("Wrong exception" + e);
+            fail("Wrong exception" + e);
         }
         try {
             entityManager1.remove("foo");
@@ -95,7 +230,7 @@
         } catch (TransactionRequiredException e) {
             //expected
         } catch (Exception e) {
-            fail ("Wrong exception" + e);
+            fail("Wrong exception" + e);
         }
         try {
             entityManager1.merge("foo");
@@ -103,7 +238,7 @@
         } catch (TransactionRequiredException e) {
             //expected
         } catch (Exception e) {
-            fail ("Wrong exception" + e);
+            fail("Wrong exception" + e);
         }
         try {
             entityManager1.refresh("foo");
@@ -111,16 +246,28 @@
         } catch (TransactionRequiredException e) {
             //expected
         } catch (Exception e) {
-            fail ("Wrong exception" + e);
+            fail("Wrong exception" + e);
         }
     }
 
     /**
      * section 5.9.1
+     * when a SFSB/extended context starts a UserTransaction or a CMT tx starts the EM must join the transaction
+     */
+    public void testExtendedEntityManagerJoinsNewTransactions() throws Exception {
+        CMPEntityManagerExtended entityManager1 = new CMPEntityManagerExtended(tm, persistenceUnit, entityManagerFactory, null);
+        tm.begin();
+        MockEntityManager pc1 = (MockEntityManager) entityManager1.find(EntityManager.class, "this");
+
+        assertTrue("EntityManager was supposed to join the tx", pc1.isJoined());
+    }
+
+    /**
+     * section 5.9.1
      * application must not call close on its entityManager
      */
     public void testAppCallsCloseForbidden() throws Exception {
-        CMPEntityManager entityManager1 = new CMPEntityManager(tm, persistenceUnit, entityManagerFactory, null, true);
+        CMPEntityManagerTxScoped entityManager1 = new CMPEntityManagerTxScoped(tm, persistenceUnit, entityManagerFactory, null);
         try {
             entityManager1.close();
             fail("Application should not be able to call close on its EntityManager");
@@ -140,11 +287,12 @@
 
     /**
      * section 5.9.1
+     *
      * @throws Exception
      */
     public void testNoPropertiesUsed() throws Exception {
 
-        CMPEntityManager entityManager = new CMPEntityManager(tm, persistenceUnit, entityManagerFactory, null, true);
+        CMPEntityManagerTxScoped entityManager = new CMPEntityManagerTxScoped(tm, persistenceUnit, entityManagerFactory, null);
         tm.begin();
         entityManager.contains("bar");
         Map props = entityManager.find(Map.class, "properties");
@@ -154,11 +302,12 @@
 
     /**
      * section 5.9.1
+     *
      * @throws Exception
      */
     public void testPropertiesUsed() throws Exception {
         Map properties = new HashMap();
-        CMPEntityManager entityManager = new CMPEntityManager(tm, persistenceUnit, entityManagerFactory, properties, true);
+        CMPEntityManagerTxScoped entityManager = new CMPEntityManagerTxScoped(tm, persistenceUnit, entityManagerFactory, properties);
         tm.begin();
         entityManager.contains("bar");
         Map props = entityManager.find(Map.class, "properties");

Modified: geronimo/sandbox/jee5-jta/transaction/src/test/org/apache/geronimo/transaction/mockjpa/MockEntityManager.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jee5-jta/transaction/src/test/org/apache/geronimo/transaction/mockjpa/MockEntityManager.java?rev=437177&r1=437176&r2=437177&view=diff
==============================================================================
--- geronimo/sandbox/jee5-jta/transaction/src/test/org/apache/geronimo/transaction/mockjpa/MockEntityManager.java (original)
+++ geronimo/sandbox/jee5-jta/transaction/src/test/org/apache/geronimo/transaction/mockjpa/MockEntityManager.java Sat Aug 26 09:18:51 2006
@@ -26,13 +26,14 @@
 import javax.persistence.EntityTransaction;
 
 /**
- * @version $Rev:$ $Date:$
+ * @version $Rev$ $Date$
  */
 public class MockEntityManager implements EntityManager {
 
     private final Map properties;
     private boolean closed = false;
     private boolean cleared = false;
+    private boolean joined = false;
 
     public MockEntityManager() {
         properties = null;
@@ -123,6 +124,7 @@
     }
 
     public void joinTransaction() {
+        joined = true;
     }
 
     public Object getDelegate() {
@@ -139,5 +141,9 @@
 
     public boolean isCleared() {
         return cleared;
+    }
+
+    public boolean isJoined() {
+        return joined;
     }
 }



Mime
View raw message