You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by da...@apache.org on 2007/01/11 21:18:56 UTC

svn commit: r495360 [1/2] - in /incubator/openejb/trunk/openejb3: container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ container/openejb-core/src/main/java/org/apache/openejb/core/ container/openejb-core/src/main/java/org/apache/o...

Author: dain
Date: Thu Jan 11 12:18:54 2007
New Revision: 495360

URL: http://svn.apache.org/viewvc?view=rev&rev=495360
Log:
OPENEJB-382 ENC: persistence-context-ref

Added:
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/SimpleTransactionSynchronizationRegistry.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/PersistenceContextReference.java
    incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/EntityManagerAlreadyRegisteredException.java
    incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/EntityManagerTxKey.java
    incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/JtaEntityManager.java
    incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/JtaEntityManagerRegistry.java
Modified:
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java
    incubator/openejb/trunk/openejb3/container/openejb-persistence/pom.xml
    incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/bmp/ContextLookupBmpBean.java
    incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/bmp/EncBmpBean.java
    incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/bmp/EncBmpObject.java
    incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/ContextLookupCmpBean.java
    incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/EncCmp2Bean.java
    incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/EncCmpBean.java
    incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/EncCmpObject.java
    incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/ContextLookupStatefulBean.java
    incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/ContextLookupStatefulPojoBean.java
    incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/EncStatefulBean.java
    incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/EncStatefulObject.java
    incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/ContextLookupStatelessBean.java
    incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/ContextLookupStatelessPojoBean.java
    incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/EncStatelessBean.java
    incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/EncStatelessObject.java
    incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/resources/META-INF/ejb-jar.xml
    incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/bmp/BmpContextLookupTests.java
    incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/bmp/BmpJndiEncTests.java
    incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmp/CmpContextLookupTests.java
    incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmp/CmpJndiEncTests.java
    incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmp2/Cmp2JndiEncTests.java
    incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateful/StatefulContextLookupTests.java
    incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateful/StatefulJndiEncTests.java
    incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateful/StatefulPojoContextLookupTests.java
    incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateless/StatelessContextLookupTests.java
    incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateless/StatelessJndiEncTests.java
    incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateless/StatelessPojoContextLookupTests.java

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java?view=diff&rev=495360&r1=495359&r2=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java Thu Jan 11 12:18:54 2007
@@ -18,7 +18,10 @@
 
 import org.apache.openejb.BeanType;
 import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.persistence.JtaEntityManager;
+import org.apache.openejb.persistence.JtaEntityManagerRegistry;
 import org.apache.openejb.core.CoreUserTransaction;
+import org.apache.openejb.core.SimpleTransactionSynchronizationRegistry;
 import org.apache.openejb.core.ivm.naming.IntraVmJndiReference;
 import org.apache.openejb.core.ivm.naming.IvmContext;
 import org.apache.openejb.core.ivm.naming.JndiReference;
@@ -26,6 +29,7 @@
 import org.apache.openejb.core.ivm.naming.ParsedName;
 import org.apache.openejb.core.ivm.naming.PersistenceUnitReference;
 import org.apache.openejb.core.ivm.naming.Reference;
+import org.apache.openejb.core.ivm.naming.PersistenceContextReference;
 
 import javax.naming.Context;
 import javax.naming.NamingException;
@@ -141,12 +145,17 @@
 
         // bind TransactionSynchronizationRegistry
         TransactionSynchronizationRegistry synchronizationRegistry = (TransactionSynchronizationRegistry) Assembler.getContext().get(TransactionSynchronizationRegistry.class.getName());
-        if (synchronizationRegistry == null && transactionManager instanceof TransactionSynchronizationRegistry) {
-            synchronizationRegistry = (TransactionSynchronizationRegistry) transactionManager;
-        }
-        if (synchronizationRegistry != null) {
-            bindings.put("java:comp/TransactionSynchronizationRegistry", synchronizationRegistry);
+        if (synchronizationRegistry == null) {
+            // todo this should be move to the main service assembler
+            if (transactionManager instanceof TransactionSynchronizationRegistry) {
+                synchronizationRegistry = (TransactionSynchronizationRegistry) transactionManager;
+            } else {
+                synchronizationRegistry = new SimpleTransactionSynchronizationRegistry(transactionManager);
+            }
+            // todo make sure this gets into the system instance
+            Assembler.getContext().put(TransactionSynchronizationRegistry.class.getName(), synchronizationRegistry);
         }
+        bindings.put("java:comp/TransactionSynchronizationRegistry", synchronizationRegistry);
 
         // bind UserTransaction if bean managed transactions
         if (beanManagedTransactions) {
@@ -286,9 +295,15 @@
                 throw new OpenEJBException("Deployment failed as the Persistence Unit could not be located. Try adding the 'persistence-unit-name' tag in ejb-jar.xml ");
             }
 
-// TODO create persistence context reference here
-//            Reference reference = new PersistenceUnitReference(factory);
-//            bindings.put(normalize(contextInfo.referenceName), wrapReference(reference));
+            JtaEntityManagerRegistry jtaEntityManagerRegistry = (JtaEntityManagerRegistry) Assembler.getContext().get(JtaEntityManagerRegistry.class.getName());
+            if (jtaEntityManagerRegistry == null) {
+                // todo make sure this gets into the system instance
+                jtaEntityManagerRegistry = new JtaEntityManagerRegistry(synchronizationRegistry);
+                Assembler.getContext().put(JtaEntityManagerRegistry.class.getName(), jtaEntityManagerRegistry);
+            }
+            JtaEntityManager jtaEntityManager = new JtaEntityManager(jtaEntityManagerRegistry, factory, contextInfo.properties, contextInfo.extended);
+            Reference reference = new PersistenceContextReference(jtaEntityManager);
+            bindings.put(normalize(contextInfo.referenceName), wrapReference(reference));
         }
 
         IvmContext enc = new IvmContext(new NameNode(null, new ParsedName("comp"), null));

Added: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/SimpleTransactionSynchronizationRegistry.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/SimpleTransactionSynchronizationRegistry.java?view=auto&rev=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/SimpleTransactionSynchronizationRegistry.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/SimpleTransactionSynchronizationRegistry.java Thu Jan 11 12:18:54 2007
@@ -0,0 +1,143 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.openejb.core;
+
+import java.util.Map;
+import java.util.HashMap;
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+import javax.transaction.TransactionSynchronizationRegistry;
+import javax.transaction.Transaction;
+
+public class SimpleTransactionSynchronizationRegistry implements TransactionSynchronizationRegistry {
+    private final TransactionManager transactionManager;
+    private final Map<Transaction,Map<Object,Object>> transactionResources = new HashMap<Transaction,Map<Object,Object>>();
+
+    public SimpleTransactionSynchronizationRegistry(TransactionManager transactionManager) {
+        this.transactionManager = transactionManager;
+    }
+
+    public Transaction getTransactionKey() {
+        try {
+            return transactionManager.getTransaction();
+        } catch (SystemException e) {
+            return null;
+        }
+    }
+
+    public Object getResource(Object key) {
+        Transaction transaction = getActiveTransaction();
+
+        Map<Object, Object> resources = transactionResources.get(transaction);
+        if (resources == null) {
+            return null;
+        }
+
+        Object value = resources.get(key);
+        return value;
+    }
+
+    public void putResource(Object key, Object value) {
+        Transaction transaction = getActiveTransaction();
+
+        Map<Object, Object> resources = transactionResources.get(transaction);
+        if (resources == null) {
+            // after transaction completes clean up resources
+            try {
+                transaction.registerSynchronization(new RemoveTransactionResources(transaction));
+            } catch (Exception e) {
+                throw new IllegalStateException("No transaction active");
+            }
+            resources = new HashMap<Object,Object>();
+            transactionResources.put(transaction,resources);
+        }
+
+        resources.put(key, value);
+    }
+
+    public int getTransactionStatus() {
+        try {
+            return transactionManager.getStatus();
+        } catch (SystemException e) {
+            return Status.STATUS_NO_TRANSACTION;
+        }
+    }
+
+    public void registerInterposedSynchronization(Synchronization synchronization) {
+        if (synchronization == null) {
+            throw new NullPointerException("synchronization is null");
+        }
+
+        Transaction transaction = getActiveTransaction();
+        try {
+            transaction.registerSynchronization(synchronization);
+        } catch (Exception ignored) {
+        }
+    }
+
+
+    public boolean getRollbackOnly() {
+        Transaction transaction = getActiveTransaction();
+        try {
+            return transaction.getStatus() == Status.STATUS_MARKED_ROLLBACK;
+        } catch (Exception e) {
+            throw new IllegalStateException("No transaction active");
+        }
+    }
+
+    public void setRollbackOnly() {
+        Transaction transaction = getActiveTransaction();
+        try {
+            transaction.setRollbackOnly();
+        } catch (Exception e) {
+            throw new IllegalStateException("No transaction active");
+        }
+    }
+    private Transaction getActiveTransaction() {
+        try {
+            Transaction transaction = transactionManager.getTransaction();
+            if (transaction == null) {
+                throw new IllegalStateException("No transaction active");
+            }
+            int status = transaction.getStatus();
+            if (status != Status.STATUS_ACTIVE && status != Status.STATUS_MARKED_ROLLBACK) {
+                throw new IllegalStateException("No transaction active");
+            }
+            return transaction;
+        } catch (SystemException e) {
+            throw new IllegalStateException("No transaction active");
+        }
+    }
+
+    private class RemoveTransactionResources implements Synchronization {
+        private final Transaction transaction;
+
+        public RemoveTransactionResources(Transaction transaction) {
+            this.transaction = transaction;
+        }
+
+        public void beforeCompletion() {
+        }
+
+        public void afterCompletion(int i) {
+            transactionResources.remove(transaction);
+        }
+    }
+}

Added: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/PersistenceContextReference.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/PersistenceContextReference.java?view=auto&rev=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/PersistenceContextReference.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/PersistenceContextReference.java Thu Jan 11 12:18:54 2007
@@ -0,0 +1,41 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.openejb.core.ivm.naming;
+
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityManager;
+import javax.naming.*;
+
+import org.apache.openejb.persistence.JtaEntityManager;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PersistenceContextReference implements Reference{
+
+    private EntityManager em;
+
+    public PersistenceContextReference(EntityManager em) {
+        this.em = em;
+    }
+
+    public Object getObject() throws javax.naming.NamingException {
+        return em;
+    }
+
+}

Modified: incubator/openejb/trunk/openejb3/container/openejb-persistence/pom.xml
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-persistence/pom.xml?view=diff&rev=495360&r1=495359&r2=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-persistence/pom.xml (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-persistence/pom.xml Thu Jan 11 12:18:54 2007
@@ -88,7 +88,6 @@
     <dependency>
       <groupId>org.apache.geronimo.specs</groupId>
       <artifactId>geronimo-jta_1.1_spec</artifactId>
-      <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>com.sun.xml.bind</groupId>

Added: incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/EntityManagerAlreadyRegisteredException.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/EntityManagerAlreadyRegisteredException.java?view=auto&rev=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/EntityManagerAlreadyRegisteredException.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/EntityManagerAlreadyRegisteredException.java Thu Jan 11 12:18:54 2007
@@ -0,0 +1,35 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.openejb.persistence;
+
+public class EntityManagerAlreadyRegisteredException extends Exception {
+    public EntityManagerAlreadyRegisteredException() {
+    }
+
+    public EntityManagerAlreadyRegisteredException(String message) {
+        super(message);
+    }
+
+    public EntityManagerAlreadyRegisteredException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public EntityManagerAlreadyRegisteredException(Throwable cause) {
+        super(cause);
+    }
+}

Added: incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/EntityManagerTxKey.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/EntityManagerTxKey.java?view=auto&rev=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/EntityManagerTxKey.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/EntityManagerTxKey.java Thu Jan 11 12:18:54 2007
@@ -0,0 +1,50 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.openejb.persistence;
+
+import javax.persistence.EntityManagerFactory;
+
+public class EntityManagerTxKey {
+    private final EntityManagerFactory entityManagerFactory;
+
+    public EntityManagerTxKey(EntityManagerFactory entityManagerFactory) {
+        this.entityManagerFactory = entityManagerFactory;
+    }
+
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+
+        final EntityManagerTxKey that = (EntityManagerTxKey) o;
+
+        return entityManagerFactory.equals(that.entityManagerFactory);
+
+    }
+
+    public int hashCode() {
+        return entityManagerFactory.hashCode();
+    }
+
+    public String toString() {
+        return entityManagerFactory.toString();
+    }
+}

Added: incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/JtaEntityManager.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/JtaEntityManager.java?view=auto&rev=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/JtaEntityManager.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/JtaEntityManager.java Thu Jan 11 12:18:54 2007
@@ -0,0 +1,231 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.openejb.persistence;
+
+import java.util.Map;
+import javax.persistence.FlushModeType;
+import javax.persistence.LockModeType;
+import javax.persistence.Query;
+import javax.persistence.EntityTransaction;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.TransactionRequiredException;
+
+/**
+ * The JtaEntityManager is a wrapper around an entity manager that automatically creates and closes entity managers
+ * for each transaction in which it is accessed.  This implementation supports both transaction and extended scoped
+ * JTA entity managers.
+ * </p>
+ * It is important that extended scoped entity managers add entity managers to the JtaEntityManagerRegistry when the
+ * component is entered and remove them when exited.  If this registration is not preformed, an IllegalStateException
+ * will be thrown when entity manger is used.
+ * It is important that a component adds extended scoped entity managers to the JtaEntityManagerRegistry when the
+ * component is entered and removes them when exited.  If this registration is not preformed, an IllegalStateException will
+ * be thrown when entity manger is accessed.
+ */
+public class JtaEntityManager implements EntityManager {
+    private final JtaEntityManagerRegistry registry;
+    private final EntityManagerFactory entityManagerFactory;
+    private final Map properties;
+    private final boolean extended;
+
+    public JtaEntityManager(JtaEntityManagerRegistry registry, EntityManagerFactory entityManagerFactory, Map properties) {
+        this(registry, entityManagerFactory, properties, false);
+
+    }
+    public JtaEntityManager(JtaEntityManagerRegistry registry, EntityManagerFactory entityManagerFactory, Map properties, boolean extended) {
+        this.registry = registry;
+        this.entityManagerFactory = entityManagerFactory;
+        this.properties = properties;
+        this.extended = extended;
+    }
+
+    private EntityManager getEntityManager() {
+        return registry.getEntityManager(entityManagerFactory, properties, extended);
+    }
+
+    private boolean isTransactionActive() {
+        return registry.isTransactionActive();
+    }
+
+    /**
+     * This method assures that a non-extended entity managers has an acive transaction.  This is
+     * required for some operations on the entity manager.
+     * @throws TransactionRequiredException if non-extended and a transaction is not active
+     */
+    private void assertTransactionActive() throws TransactionRequiredException {
+        if (!extended && !isTransactionActive()) {
+            throw new TransactionRequiredException();
+        }
+    }
+
+    /**
+     * Closes a non-extended entity manager if no transaction is active.  For methods on an
+     * entity manager that do not require an active transaction, a temp entity manager is created
+     * for the operation and then closed.
+     * @param entityManager the entity manager to close if non-extended and a transaction is not active
+     */
+    private void closeIfNoTx(EntityManager entityManager) {
+        if (!extended && !isTransactionActive()) {
+            entityManager.close();
+        }
+    }
+
+    public EntityManager getDelegate() {
+        return getEntityManager();
+    }
+
+    public void persist(Object entity) {
+        assertTransactionActive();
+        getEntityManager().persist(entity);
+    }
+
+    public <T>T merge(T entity) {
+        assertTransactionActive();
+        return getEntityManager().merge(entity);
+    }
+
+    public void remove(Object entity) {
+        assertTransactionActive();
+        getEntityManager().remove(entity);
+    }
+
+    public <T>T find(Class<T> entityClass, Object primaryKey) {
+        EntityManager entityManager = getEntityManager();
+        try {
+            return entityManager.find(entityClass, primaryKey);
+        } finally {
+            closeIfNoTx(entityManager);
+        }
+    }
+
+    public <T>T getReference(Class<T> entityClass, Object primaryKey) {
+        EntityManager entityManager = getEntityManager();
+        try {
+            return entityManager.getReference(entityClass, primaryKey);
+        } finally {
+            closeIfNoTx(entityManager);
+        }
+    }
+
+    public void flush() {
+        assertTransactionActive();
+        getEntityManager().flush();
+    }
+
+    public void setFlushMode(FlushModeType flushMode) {
+        EntityManager entityManager = getEntityManager();
+        try {
+            entityManager.setFlushMode(flushMode);
+        } finally {
+            closeIfNoTx(entityManager);
+        }
+    }
+
+    public FlushModeType getFlushMode() {
+        EntityManager entityManager = getEntityManager();
+        try {
+            return entityManager.getFlushMode();
+        } finally {
+            closeIfNoTx(entityManager);
+        }
+    }
+
+    public void lock(Object entity, LockModeType lockMode) {
+        assertTransactionActive();
+        getEntityManager().lock(entity, lockMode);
+    }
+
+    public void refresh(Object entity) {
+        assertTransactionActive();
+        getEntityManager().refresh(entity);
+    }
+
+    public void clear() {
+        if (!isTransactionActive()) {
+            return;
+        }
+        getEntityManager().clear();
+    }
+
+    public boolean contains(Object entity) {
+        if (!isTransactionActive()) {
+            return false;
+        }
+        return getEntityManager().contains(entity);
+    }
+
+    public Query createQuery(String qlString) {
+        EntityManager entityManager = getEntityManager();
+        try {
+            return entityManager.createQuery(qlString);
+        } finally {
+            closeIfNoTx(entityManager);
+        }
+    }
+
+    public Query createNamedQuery(String name) {
+        EntityManager entityManager = getEntityManager();
+        try {
+            return entityManager.createNamedQuery(name);
+        } finally {
+            closeIfNoTx(entityManager);
+        }
+    }
+
+    public Query createNativeQuery(String sqlString) {
+        EntityManager entityManager = getEntityManager();
+        try {
+            return entityManager.createNativeQuery(sqlString);
+        } finally {
+            closeIfNoTx(entityManager);
+        }
+    }
+
+    public Query createNativeQuery(String sqlString, Class resultClass) {
+        EntityManager entityManager = getEntityManager();
+        try {
+            return entityManager.createNativeQuery(sqlString, resultClass);
+        } finally {
+            closeIfNoTx(entityManager);
+        }
+    }
+
+    public Query createNativeQuery(String sqlString, String resultSetMapping) {
+        EntityManager entityManager = getEntityManager();
+        try {
+            return entityManager.createNativeQuery(sqlString, resultSetMapping);
+        } finally {
+            closeIfNoTx(entityManager);
+        }
+    }
+
+    public void joinTransaction() {
+    }
+
+    public void close() {
+    }
+
+    public boolean isOpen() {
+        return true;
+    }
+
+    public EntityTransaction getTransaction() {
+        throw new IllegalStateException("A JTA Entity Manager can not use an entity transaction");
+    }
+}

Added: incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/JtaEntityManagerRegistry.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/JtaEntityManagerRegistry.java?view=auto&rev=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/JtaEntityManagerRegistry.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/JtaEntityManagerRegistry.java Thu Jan 11 12:18:54 2007
@@ -0,0 +1,283 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.openejb.persistence;
+
+
+import java.util.Map;
+import java.util.TreeMap;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.TransactionRequiredException;
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+import javax.transaction.TransactionSynchronizationRegistry;
+
+/**
+ * The JtaEntityManagerRegistry tracks JTA entity managers for transation and extended scoped
+ * entity managers.  A signle instance of this object should be created and shared by all
+ * JtaEntityManagers in the server instance.  Failure to do this will result in multiple entity
+ * managers being created for a single persistence until, and that will result in cache
+ * incoherence.
+ */
+public class JtaEntityManagerRegistry {
+    /**
+     * Registry of transaction associated entity managers.
+     */
+    private final TransactionSynchronizationRegistry transactionRegistry;
+
+    /**
+     * Registry of entended context entity managers.
+     */
+    private final ThreadLocal<ExtendedRegistry> extendedRegistry = new ThreadLocal<ExtendedRegistry>() {
+        protected ExtendedRegistry initialValue() {
+            return new ExtendedRegistry();
+        }
+    };
+
+    /**
+     * Creates a JtaEntityManagerRegistry using the specified transactionSynchronizationRegistry for the registry
+     * if transaction associated entity managers.
+     */
+    public JtaEntityManagerRegistry(TransactionSynchronizationRegistry transactionSynchronizationRegistry) {
+        this.transactionRegistry = transactionSynchronizationRegistry;
+    }
+
+    /**
+     * Gets an entity manager instance from the transaction registry, extended regitry or for a transaction scoped
+     * entity manager, creates a new one when an exisitng instance is not found.
+     * </p>
+     * It is important that a component adds extended scoped entity managers to this registry when the component is
+     * entered and removes them when exited.  If this registration is not preformed, an IllegalStateException will
+     * be thrown when entity manger is fetched.
+     * @param entityManagerFactory the entity manager factory from which an entity manager is required
+     * @param properties the properties passed to the entity manager factory when an entity manager is created
+     * @param extended is the entity manager an extended context
+     * @return the new entity manager
+     * @throws IllegalStateException if the entity manger is extended and there is not an existing entity manager
+     * instance already registered
+     */
+    public EntityManager getEntityManager(EntityManagerFactory entityManagerFactory, Map properties, boolean extended) throws IllegalStateException {
+        EntityManagerTxKey txKey = new EntityManagerTxKey(entityManagerFactory);
+        boolean transactionActive = isTransactionActive();
+
+        // if we have an active transaction, check the tx registry
+        if (transactionActive) {
+            EntityManager entityManager = (EntityManager) transactionRegistry.getResource(txKey);
+            if (entityManager != null) {
+                return entityManager;
+            }
+        }
+
+        // if extended context, there must be an entity manager already registered with the tx
+        if (extended) {
+            EntityManager entityManager = getInheritedEntityManager(entityManagerFactory);
+            if (entityManager == null) {
+                throw new IllegalStateException("InternalError: an entity manager should already be registered for this entended persistence unit");
+            }
+
+            // if transaction is active, we need to register the entity manager with the transaction manager
+            if (transactionActive) {
+                entityManager.joinTransaction();
+                transactionRegistry.putResource(txKey, entityManager);
+            }
+
+            return entityManager;
+        } else {
+            // create a new entity manager
+            EntityManager entityManager;
+            if (properties != null) {
+                entityManager = entityManagerFactory.createEntityManager(properties);
+            } else {
+                entityManager = entityManagerFactory.createEntityManager();
+            }
+
+            // if we are in a transaction associate the entity manager with the transaction; otherwise it is
+            // expected the caller will close this entity manager after use
+            if (transactionActive) {
+                transactionRegistry.registerInterposedSynchronization(new CloseEntityManager(entityManager));
+                transactionRegistry.putResource(txKey, entityManager);
+            }
+            return entityManager;
+        }
+    }
+
+    /**
+     * Adds the entity managers for the specified component to the registry.  This should be called when the component
+     * is entered.
+     * @param deploymentId the id of the component
+     * @param entityManagers the entity managers to register
+     * @throws EntityManagerAlreadyRegisteredException if an entity manager is already registered with the transaction
+     * for one of the supplied entity manager factories; for EJBs this should be caught and rethown as an EJBException
+     */
+    public void addEntityManagers(String deploymentId, Object primaryKey, Map<EntityManagerFactory, EntityManager> entityManagers) throws EntityManagerAlreadyRegisteredException {
+        extendedRegistry.get().addEntityManagers(new InstanceId(deploymentId, primaryKey), entityManagers);
+    }
+
+    /**
+     * Removed the registered entity managers for the specified component.
+     * @param deploymentId the id of the component
+     */
+    public void removeEntityManagers(String deploymentId, Object primaryKey) {
+        extendedRegistry.get().removeEntityManagers(new InstanceId(deploymentId, primaryKey));
+    }
+
+    /**
+     * Gets an exiting extended entity manager created by a component down the call stack.
+     * @param entityManagerFactory the entity manager factory from which an entity manager is needed
+     * @return the existing entity manager or null if one is not found
+     */
+    public EntityManager getInheritedEntityManager(EntityManagerFactory entityManagerFactory) {
+        return extendedRegistry.get().getInheritedEntityManager(entityManagerFactory);
+    }
+
+    /**
+     * Notifies the registry that a user transaction has been started or the specified component.  When a transaction
+     * is started for a component with registered extended entity managers, the entity managers are enrolled in the
+     * transaction.
+     * @param deploymentId the id of the component
+     */
+    public void transactionStarted(String deploymentId, Object primaryKey) {
+        extendedRegistry.get().transactionStarted(new InstanceId(deploymentId, primaryKey));
+    }
+
+    /**
+     * Is a transaction active?
+     * @return true if a transaction is active; false otherwise
+     */
+    public boolean isTransactionActive() {
+        int txStatus = transactionRegistry.getTransactionStatus();
+        boolean transactionActive = txStatus == Status.STATUS_ACTIVE || txStatus == Status.STATUS_MARKED_ROLLBACK;
+        return transactionActive;
+    }
+
+    private class ExtendedRegistry {
+        private final Map<InstanceId, Map<EntityManagerFactory, EntityManager>> entityManagersByDeploymentId =
+                new TreeMap<InstanceId, Map<EntityManagerFactory, EntityManager>>();
+
+        private void addEntityManagers(InstanceId instanceId, Map<EntityManagerFactory, EntityManager> entityManagers) throws EntityManagerAlreadyRegisteredException {
+            if (instanceId == null) throw new NullPointerException("instanceId is null");
+            if (entityManagers == null) throw new NullPointerException("entityManagers is null");
+
+            if (isTransactionActive()) {
+                for (Map.Entry<EntityManagerFactory, EntityManager> entry : entityManagers.entrySet()) {
+                    EntityManagerFactory entityManagerFactory = entry.getKey();
+                    EntityManager entityManager = entry.getValue();
+                    EntityManagerTxKey txKey = new EntityManagerTxKey(entityManagerFactory);
+
+                    if (transactionRegistry.getResource(txKey) == null) {
+                        throw new EntityManagerAlreadyRegisteredException("Another entity manager is already registered for this persistence unit");
+                    }
+
+                    entityManager.joinTransaction();
+                    transactionRegistry.putResource(txKey, entityManager);
+                }
+            }
+            entityManagersByDeploymentId.put(instanceId, entityManagers);
+        }
+
+        private void removeEntityManagers(InstanceId instanceId) {
+            if (instanceId == null) {
+                throw new NullPointerException("InstanceId is null");
+            }
+
+            entityManagersByDeploymentId.remove(instanceId);
+        }
+
+        private EntityManager getInheritedEntityManager(EntityManagerFactory entityManagerFactory) {
+            if (entityManagerFactory == null) throw new NullPointerException("entityManagerFactory is null");
+
+            for (Map<EntityManagerFactory, EntityManager> entityManagers : entityManagersByDeploymentId.values()) {
+                EntityManager entityManager = entityManagers.get(entityManagerFactory);
+                if (entityManager != null) {
+                    return entityManager;
+                }
+            }
+            return null;
+        }
+
+        private void transactionStarted(InstanceId instanceId) {
+            if (instanceId == null) {
+                throw new NullPointerException("instanceId is null");
+            }
+            if (!isTransactionActive()) {
+                throw new TransactionRequiredException();
+            }
+
+            Map<EntityManagerFactory, EntityManager> entityManagers = entityManagersByDeploymentId.get(instanceId);
+            if (entityManagers == null) {
+                return;
+            }
+
+            for (EntityManager entityManager : entityManagers.values()) {
+                entityManager.joinTransaction();
+            }
+        }
+    }
+
+    private static class InstanceId {
+        private final String deploymentId;
+        private final Object primaryKey;
+
+        public InstanceId(String deploymentId, Object primaryKey) {
+            if (deploymentId == null) {
+                throw new NullPointerException("deploymentId is null");
+            }
+            if (primaryKey == null) {
+                throw new NullPointerException("primaryKey is null");
+            }
+            this.deploymentId = deploymentId;
+            this.primaryKey = primaryKey;
+        }
+
+        public boolean equals(Object o) {
+            if (this == o) {
+                return true;
+            }
+            if (o == null || getClass() != o.getClass()) {
+                return false;
+            }
+
+            final InstanceId that = (InstanceId) o;
+            return deploymentId.equals(that.deploymentId) &&
+                    primaryKey.equals(that.primaryKey);
+
+        }
+
+        public int hashCode() {
+            int result;
+            result = deploymentId.hashCode();
+            result = 29 * result + primaryKey.hashCode();
+            return result;
+        }
+    }
+
+    private static class CloseEntityManager implements Synchronization {
+        private final EntityManager entityManager;
+
+        public CloseEntityManager(EntityManager entityManager) {
+            this.entityManager = entityManager;
+        }
+
+        public void beforeCompletion() {
+        }
+
+        public void afterCompletion(int i) {
+            entityManager.close();
+        }
+    }
+}

Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/bmp/ContextLookupBmpBean.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/bmp/ContextLookupBmpBean.java?view=diff&rev=495360&r1=495359&r2=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/bmp/ContextLookupBmpBean.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/bmp/ContextLookupBmpBean.java Thu Jan 11 12:18:54 2007
@@ -29,6 +29,7 @@
 import javax.ejb.RemoveException;
 import javax.naming.InitialContext;
 import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityManager;
 import javax.sql.DataSource;
 import java.rmi.RemoteException;
 
@@ -330,6 +331,24 @@
         }
     }
     
+    public void lookupPersistenceContext() throws TestFailureException{
+        try{
+            try{
+                InitialContext ctx = new InitialContext();
+                Assert.assertNotNull("The InitialContext is null", ctx);
+                EntityManager em = (EntityManager)ctx.lookup("java:comp/env/persistence/TestContext");
+                Assert.assertNotNull("The EntityManager is null", em);
+
+                // call a do nothing method to assure entity manager actually exists
+                em.getFlushMode();
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
     //
     // Remote interface methods
     //=============================

Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/bmp/EncBmpBean.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/bmp/EncBmpBean.java?view=diff&rev=495360&r1=495359&r2=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/bmp/EncBmpBean.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/bmp/EncBmpBean.java Thu Jan 11 12:18:54 2007
@@ -23,6 +23,7 @@
 import javax.ejb.RemoveException;
 import javax.naming.InitialContext;
 import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityManager;
 import javax.sql.DataSource;
 
 import junit.framework.Assert;
@@ -373,7 +374,25 @@
         }
     }
     
-    //    
+    public void lookupPersistenceContext() throws TestFailureException{
+        try{
+            try{
+                InitialContext ctx = new InitialContext();
+                Assert.assertNotNull("The InitialContext is null", ctx);
+                EntityManager em = (EntityManager)ctx.lookup("java:comp/env/persistence/TestContext");
+                Assert.assertNotNull("The EntityManager is null", em);
+
+                // call a do nothing method to assure entity manager actually exists
+                em.getFlushMode();
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    //
     // Remote interface methods
     //=============================
 

Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/bmp/EncBmpObject.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/bmp/EncBmpObject.java?view=diff&rev=495360&r1=495359&r2=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/bmp/EncBmpObject.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/bmp/EncBmpObject.java Thu Jan 11 12:18:54 2007
@@ -33,6 +33,7 @@
 
     public void lookupResource() throws TestFailureException, RemoteException;
     public void lookupPersistenceUnit() throws TestFailureException, RemoteException;
+    public void lookupPersistenceContext() throws TestFailureException, RemoteException;
 
     public void lookupStringEntry()  throws TestFailureException, RemoteException;
     public void lookupDoubleEntry()  throws TestFailureException, RemoteException;

Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/ContextLookupCmpBean.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/ContextLookupCmpBean.java?view=diff&rev=495360&r1=495359&r2=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/ContextLookupCmpBean.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/ContextLookupCmpBean.java Thu Jan 11 12:18:54 2007
@@ -29,6 +29,7 @@
 import javax.ejb.RemoveException;
 import javax.naming.InitialContext;
 import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityManager;
 import javax.sql.DataSource;
 import java.rmi.RemoteException;
 import java.util.StringTokenizer;
@@ -305,6 +306,24 @@
         }
     }
     
+    public void lookupPersistenceContext() throws TestFailureException{
+        try{
+            try{
+                InitialContext ctx = new InitialContext();
+                Assert.assertNotNull("The InitialContext is null", ctx);
+                EntityManager em = (EntityManager)ctx.lookup("java:comp/env/persistence/TestContext");
+                Assert.assertNotNull("The EntityManager is null", em);
+
+                // call a do nothing method to assure entity manager actually exists
+                em.getFlushMode();
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
     //
     // Remote interface methods
     //=============================

Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/EncCmp2Bean.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/EncCmp2Bean.java?view=diff&rev=495360&r1=495359&r2=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/EncCmp2Bean.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/EncCmp2Bean.java Thu Jan 11 12:18:54 2007
@@ -22,6 +22,7 @@
 import javax.ejb.EntityContext;
 import javax.naming.InitialContext;
 import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityManager;
 
 import junit.framework.Assert;
 import junit.framework.AssertionFailedError;
@@ -340,6 +341,24 @@
         }
     }
     
+    public void lookupPersistenceContext() throws TestFailureException{
+        try{
+            try{
+                InitialContext ctx = new InitialContext();
+                Assert.assertNotNull("The InitialContext is null", ctx);
+                EntityManager em = (EntityManager)ctx.lookup("java:comp/env/persistence/TestContext");
+                Assert.assertNotNull("The EntityManager is null", em);
+
+                // call a do nothing method to assure entity manager actually exists
+                em.getFlushMode();
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
     //
     // Remote interface methods
     //=============================

Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/EncCmpBean.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/EncCmpBean.java?view=diff&rev=495360&r1=495359&r2=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/EncCmpBean.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/EncCmpBean.java Thu Jan 11 12:18:54 2007
@@ -24,6 +24,7 @@
 import javax.ejb.RemoveException;
 import javax.naming.InitialContext;
 import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityManager;
 import javax.sql.DataSource;
 
 import junit.framework.Assert;
@@ -350,7 +351,25 @@
         }
     }
     
-    //    
+    public void lookupPersistenceContext() throws TestFailureException{
+        try{
+            try{
+                InitialContext ctx = new InitialContext();
+                Assert.assertNotNull("The InitialContext is null", ctx);
+                EntityManager em = (EntityManager)ctx.lookup("java:comp/env/persistence/TestContext");
+                Assert.assertNotNull("The EntityManager is null", em);
+
+                // call a do nothing method to assure entity manager actually exists
+                em.getFlushMode();
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    //
     // Remote interface methods
     //=============================
 

Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/EncCmpObject.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/EncCmpObject.java?view=diff&rev=495360&r1=495359&r2=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/EncCmpObject.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/entity/cmp/EncCmpObject.java Thu Jan 11 12:18:54 2007
@@ -33,6 +33,7 @@
 
     public void lookupResource() throws TestFailureException, RemoteException;
     public void lookupPersistenceUnit() throws TestFailureException, RemoteException;
+    public void lookupPersistenceContext() throws TestFailureException, RemoteException;
 
     public void lookupStringEntry()  throws TestFailureException, RemoteException;
     public void lookupDoubleEntry()  throws TestFailureException, RemoteException;

Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/ContextLookupStatefulBean.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/ContextLookupStatefulBean.java?view=diff&rev=495360&r1=495359&r2=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/ContextLookupStatefulBean.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/ContextLookupStatefulBean.java Thu Jan 11 12:18:54 2007
@@ -29,6 +29,7 @@
 import javax.ejb.SessionSynchronization;
 import javax.naming.InitialContext;
 import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityManager;
 import javax.sql.DataSource;
 import java.rmi.RemoteException;
 
@@ -296,6 +297,24 @@
         }
     }
     
+    public void lookupPersistenceContext() throws TestFailureException{
+        try{
+            try{
+                InitialContext ctx = new InitialContext();
+                Assert.assertNotNull("The InitialContext is null", ctx);
+                EntityManager em = (EntityManager)ctx.lookup("java:comp/env/persistence/TestContext");
+                Assert.assertNotNull("The EntityManager is null", em);
+
+                // call a do nothing method to assure entity manager actually exists
+                em.getFlushMode();
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
     //
     // Remote interface methods
     //=============================

Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/ContextLookupStatefulPojoBean.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/ContextLookupStatefulPojoBean.java?view=diff&rev=495360&r1=495359&r2=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/ContextLookupStatefulPojoBean.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/ContextLookupStatefulPojoBean.java Thu Jan 11 12:18:54 2007
@@ -28,6 +28,7 @@
 import javax.sql.DataSource;
 import javax.naming.InitialContext;
 import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityManager;
 
 import junit.framework.Assert;
 import junit.framework.AssertionFailedError;
@@ -265,6 +266,24 @@
                 EntityManagerFactory emf = (EntityManagerFactory)ctx.lookup("java:comp/env/persistence/TestUnit");
                 Assert.assertNotNull("The EntityManagerFactory is null", emf );
 
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupPersistenceContext() throws TestFailureException{
+        try{
+            try{
+                InitialContext ctx = new InitialContext();
+                Assert.assertNotNull("The InitialContext is null", ctx);
+                EntityManager em = (EntityManager)ctx.lookup("java:comp/env/persistence/TestContext");
+                Assert.assertNotNull("The EntityManager is null", em);
+
+                // call a do nothing method to assure entity manager actually exists
+                em.getFlushMode();
             } catch (Exception e){
                 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
             }

Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/EncStatefulBean.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/EncStatefulBean.java?view=diff&rev=495360&r1=495359&r2=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/EncStatefulBean.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/EncStatefulBean.java Thu Jan 11 12:18:54 2007
@@ -23,6 +23,7 @@
 import javax.ejb.SessionSynchronization;
 import javax.naming.InitialContext;
 import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityManager;
 import javax.sql.DataSource;
 
 import junit.framework.Assert;
@@ -338,7 +339,25 @@
         }
     }
     
-    //    
+    public void lookupPersistenceContext() throws TestFailureException{
+        try{
+            try{
+                InitialContext ctx = new InitialContext();
+                Assert.assertNotNull("The InitialContext is null", ctx);
+                EntityManager em = (EntityManager)ctx.lookup("java:comp/env/persistence/TestContext");
+                Assert.assertNotNull("The EntityManager is null", em);
+
+                // call a do nothing method to assure entity manager actually exists
+                em.getFlushMode();
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    //
     // Remote interface methods
     //=============================
 

Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/EncStatefulObject.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/EncStatefulObject.java?view=diff&rev=495360&r1=495359&r2=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/EncStatefulObject.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateful/EncStatefulObject.java Thu Jan 11 12:18:54 2007
@@ -33,6 +33,7 @@
 
     public void lookupResource() throws TestFailureException, RemoteException;
     public void lookupPersistenceUnit() throws TestFailureException, RemoteException;
+    public void lookupPersistenceContext() throws TestFailureException, RemoteException;
 
     public void lookupStringEntry()  throws TestFailureException, RemoteException;
     public void lookupDoubleEntry()  throws TestFailureException, RemoteException;

Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/ContextLookupStatelessBean.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/ContextLookupStatelessBean.java?view=diff&rev=495360&r1=495359&r2=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/ContextLookupStatelessBean.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/ContextLookupStatelessBean.java Thu Jan 11 12:18:54 2007
@@ -28,6 +28,7 @@
 import javax.ejb.SessionContext;
 import javax.naming.InitialContext;
 import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityManager;
 import javax.sql.DataSource;
 import java.rmi.RemoteException;
 
@@ -282,6 +283,24 @@
         }
     }
     
+    public void lookupPersistenceContext() throws TestFailureException{
+        try{
+            try{
+                InitialContext ctx = new InitialContext();
+                Assert.assertNotNull("The InitialContext is null", ctx);
+                EntityManager em = (EntityManager)ctx.lookup("java:comp/env/persistence/TestContext");
+                Assert.assertNotNull("The EntityManager is null", em);
+
+                // call a do nothing method to assure entity manager actually exists
+                em.getFlushMode();
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
     //
     // Remote interface methods
     //=============================

Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/ContextLookupStatelessPojoBean.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/ContextLookupStatelessPojoBean.java?view=diff&rev=495360&r1=495359&r2=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/ContextLookupStatelessPojoBean.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/ContextLookupStatelessPojoBean.java Thu Jan 11 12:18:54 2007
@@ -27,6 +27,7 @@
 import javax.sql.DataSource;
 import javax.naming.InitialContext;
 import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityManager;
 
 import junit.framework.Assert;
 import junit.framework.AssertionFailedError;
@@ -260,6 +261,24 @@
                 EntityManagerFactory emf = (EntityManagerFactory)ctx.lookup("java:comp/env/persistence/TestUnit");
                 Assert.assertNotNull("The EntityManagerFactory is null", emf );
 
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupPersistenceContext() throws TestFailureException{
+        try{
+            try{
+                InitialContext ctx = new InitialContext();
+                Assert.assertNotNull("The InitialContext is null", ctx);
+                EntityManager em = (EntityManager)ctx.lookup("java:comp/env/persistence/TestContext");
+                Assert.assertNotNull("The EntityManager is null", em);
+
+                // call a do nothing method to assure entity manager actually exists
+                em.getFlushMode();
             } catch (Exception e){
                 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
             }

Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/EncStatelessBean.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/EncStatelessBean.java?view=diff&rev=495360&r1=495359&r2=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/EncStatelessBean.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/EncStatelessBean.java Thu Jan 11 12:18:54 2007
@@ -23,6 +23,7 @@
 import javax.ejb.SessionContext;
 import javax.naming.InitialContext;
 import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityManager;
 import javax.sql.DataSource;
 
 import junit.framework.Assert;
@@ -325,7 +326,25 @@
         }
     }
     
-    //    
+    public void lookupPersistenceContext() throws TestFailureException{
+        try{
+            try{
+                InitialContext ctx = new InitialContext();
+                Assert.assertNotNull("The InitialContext is null", ctx);
+                EntityManager em = (EntityManager)ctx.lookup("java:comp/env/persistence/TestContext");
+                Assert.assertNotNull("The EntityManager is null", em);
+
+                // call a do nothing method to assure entity manager actually exists
+                em.getFlushMode();
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    //
     // Remote interface methods
     //=============================
 

Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/EncStatelessObject.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/EncStatelessObject.java?view=diff&rev=495360&r1=495359&r2=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/EncStatelessObject.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/EncStatelessObject.java Thu Jan 11 12:18:54 2007
@@ -33,6 +33,7 @@
 
     public void lookupResource() throws TestFailureException, RemoteException;
     public void lookupPersistenceUnit() throws TestFailureException, RemoteException;
+    public void lookupPersistenceContext() throws TestFailureException, RemoteException;
 
     public void lookupStringEntry()  throws TestFailureException, RemoteException;
     public void lookupDoubleEntry()  throws TestFailureException, RemoteException;

Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/resources/META-INF/ejb-jar.xml
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/resources/META-INF/ejb-jar.xml?view=diff&rev=495360&r1=495359&r2=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/resources/META-INF/ejb-jar.xml (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/resources/META-INF/ejb-jar.xml Thu Jan 11 12:18:54 2007
@@ -289,6 +289,13 @@
         <persistence-unit-ref-name>persistence/TestUnit</persistence-unit-ref-name>
         <persistence-unit-name>openjpa-test-unit</persistence-unit-name>
       </persistence-unit-ref>
+      <persistence-context-ref>
+        <description>
+          Persistence context for testing the functionality.
+        </description>
+        <persistence-context-ref-name>persistence/TestContext</persistence-context-ref-name>
+        <persistence-unit-name>openjpa-test-unit</persistence-unit-name>
+      </persistence-context-ref>
       <persistence-unit-ref>
         <persistence-unit-ref-name>openejb/cmp</persistence-unit-ref-name>
         <persistence-unit-name>cmp</persistence-unit-name>
@@ -401,6 +408,13 @@
         <persistence-unit-ref-name>persistence/TestUnit</persistence-unit-ref-name>
         <persistence-unit-name>openjpa-test-unit</persistence-unit-name>
       </persistence-unit-ref>
+      <persistence-context-ref>
+        <description>
+          Persistence context for testing the functionality.
+        </description>
+        <persistence-context-ref-name>persistence/TestContext</persistence-context-ref-name>
+        <persistence-unit-name>openjpa-test-unit</persistence-unit-name>
+      </persistence-context-ref>
       <persistence-unit-ref>
         <persistence-unit-ref-name>openejb/cmp</persistence-unit-ref-name>
         <persistence-unit-name>cmp</persistence-unit-name>
@@ -508,6 +522,13 @@
         <persistence-unit-ref-name>persistence/TestUnit</persistence-unit-ref-name>
         <persistence-unit-name>openjpa-test-unit</persistence-unit-name>
       </persistence-unit-ref>
+      <persistence-context-ref>
+        <description>
+          Persistence context for testing the functionality.
+        </description>
+        <persistence-context-ref-name>persistence/TestContext</persistence-context-ref-name>
+        <persistence-unit-name>openjpa-test-unit</persistence-unit-name>
+      </persistence-context-ref>
       <persistence-unit-ref>
         <persistence-unit-ref-name>openejb/cmp</persistence-unit-ref-name>
         <persistence-unit-name>cmp</persistence-unit-name>
@@ -933,6 +954,13 @@
         <persistence-unit-ref-name>persistence/TestUnit</persistence-unit-ref-name>
         <persistence-unit-name>openjpa-test-unit</persistence-unit-name>
       </persistence-unit-ref>
+      <persistence-context-ref>
+        <description>
+          Persistence context for testing the functionality.
+        </description>
+        <persistence-context-ref-name>persistence/TestContext</persistence-context-ref-name>
+        <persistence-unit-name>openjpa-test-unit</persistence-unit-name>
+      </persistence-context-ref>
 
     </session>
 
@@ -1034,6 +1062,13 @@
         <persistence-unit-ref-name>persistence/TestUnit</persistence-unit-ref-name>
         <persistence-unit-name>openjpa-test-unit</persistence-unit-name>
       </persistence-unit-ref>
+      <persistence-context-ref>
+        <description>
+          Persistence context for testing the functionality.
+        </description>
+        <persistence-context-ref-name>persistence/TestContext</persistence-context-ref-name>
+        <persistence-unit-name>openjpa-test-unit</persistence-unit-name>
+      </persistence-context-ref>
     </session>
 
     <!--
@@ -1134,6 +1169,13 @@
         <persistence-unit-ref-name>persistence/TestUnit</persistence-unit-ref-name>
         <persistence-unit-name>openjpa-test-unit</persistence-unit-name>
       </persistence-unit-ref>
+      <persistence-context-ref>
+        <description>
+          Persistence context for testing the functionality.
+        </description>
+        <persistence-context-ref-name>persistence/TestContext</persistence-context-ref-name>
+        <persistence-unit-name>openjpa-test-unit</persistence-unit-name>
+      </persistence-context-ref>
     </session>
 
     <!--
@@ -1234,6 +1276,13 @@
         <persistence-unit-ref-name>persistence/TestUnit</persistence-unit-ref-name>
         <persistence-unit-name>openjpa-test-unit</persistence-unit-name>
       </persistence-unit-ref>
+      <persistence-context-ref>
+        <description>
+          Persistence context for testing the functionality.
+        </description>
+        <persistence-context-ref-name>persistence/TestContext</persistence-context-ref-name>
+        <persistence-unit-name>openjpa-test-unit</persistence-unit-name>
+      </persistence-context-ref>
     </session>
 
     <!--
@@ -1589,6 +1638,13 @@
         <persistence-unit-ref-name>persistence/TestUnit</persistence-unit-ref-name>
         <persistence-unit-name>openjpa-test-unit</persistence-unit-name>
       </persistence-unit-ref>
+      <persistence-context-ref>
+        <description>
+          Persistence context for testing the functionality.
+        </description>
+        <persistence-context-ref-name>persistence/TestContext</persistence-context-ref-name>
+        <persistence-unit-name>openjpa-test-unit</persistence-unit-name>
+      </persistence-context-ref>
     </session>
 
     <!--
@@ -1703,6 +1759,13 @@
         <persistence-unit-ref-name>persistence/TestUnit</persistence-unit-ref-name>
         <persistence-unit-name>openjpa-test-unit</persistence-unit-name>
       </persistence-unit-ref>
+      <persistence-context-ref>
+        <description>
+          Persistence context for testing the functionality.
+        </description>
+        <persistence-context-ref-name>persistence/TestContext</persistence-context-ref-name>
+        <persistence-unit-name>openjpa-test-unit</persistence-unit-name>
+      </persistence-context-ref>
     </session>
 
     <!--
@@ -1817,6 +1880,13 @@
         <persistence-unit-ref-name>persistence/TestUnit</persistence-unit-ref-name>
         <persistence-unit-name>openjpa-test-unit</persistence-unit-name>
       </persistence-unit-ref>
+      <persistence-context-ref>
+        <description>
+          Persistence context for testing the functionality.
+        </description>
+        <persistence-context-ref-name>persistence/TestContext</persistence-context-ref-name>
+        <persistence-unit-name>openjpa-test-unit</persistence-unit-name>
+      </persistence-context-ref>
     </session>
 
     <!--
@@ -2037,7 +2107,13 @@
         <persistence-unit-ref-name>persistence/TestUnit</persistence-unit-ref-name>
         <persistence-unit-name>openjpa-test-unit</persistence-unit-name>
       </persistence-unit-ref>
-
+      <persistence-context-ref>
+        <description>
+          Persistence context for testing the functionality.
+        </description>
+        <persistence-context-ref-name>persistence/TestContext</persistence-context-ref-name>
+        <persistence-unit-name>openjpa-test-unit</persistence-unit-name>
+      </persistence-context-ref>
     </entity>
 
     <!--
@@ -2141,6 +2217,13 @@
         <persistence-unit-ref-name>persistence/TestUnit</persistence-unit-ref-name>
         <persistence-unit-name>openjpa-test-unit</persistence-unit-name>
       </persistence-unit-ref>
+      <persistence-context-ref>
+        <description>
+          Persistence context for testing the functionality.
+        </description>
+        <persistence-context-ref-name>persistence/TestContext</persistence-context-ref-name>
+        <persistence-unit-name>openjpa-test-unit</persistence-unit-name>
+      </persistence-context-ref>
     </entity>
 
     <!--

Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/bmp/BmpContextLookupTests.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/bmp/BmpContextLookupTests.java?view=diff&rev=495360&r1=495359&r2=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/bmp/BmpContextLookupTests.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/bmp/BmpContextLookupTests.java Thu Jan 11 12:18:54 2007
@@ -190,4 +190,14 @@
         }
     }
 
+    public void test15_lookupPersistenceContext() {
+        try{
+            ejbObject.lookupPersistenceContext();
+        } catch (TestFailureException e){
+            throw e.error;
+        } catch (Exception e){
+            fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+        }
+    }
+
 }

Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/bmp/BmpJndiEncTests.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/bmp/BmpJndiEncTests.java?view=diff&rev=495360&r1=495359&r2=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/bmp/BmpJndiEncTests.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/bmp/BmpJndiEncTests.java Thu Jan 11 12:18:54 2007
@@ -190,5 +190,14 @@
         }
     }
     
+    public void test15_lookupPersistenceContext() {
+        try{
+            ejbObject.lookupPersistenceContext();
+        } catch (TestFailureException e){
+            throw e.error;
+        } catch (Exception e){
+            fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+        }
+    }
     
 }

Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmp/CmpContextLookupTests.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmp/CmpContextLookupTests.java?view=diff&rev=495360&r1=495359&r2=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmp/CmpContextLookupTests.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmp/CmpContextLookupTests.java Thu Jan 11 12:18:54 2007
@@ -190,4 +190,14 @@
         }
     }
 
+    public void test15_lookupPersistenceContext() {
+        try{
+            ejbObject.lookupPersistenceContext();
+        } catch (TestFailureException e){
+            throw e.error;
+        } catch (Exception e){
+            fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+        }
+    }
+
 }

Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmp/CmpJndiEncTests.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmp/CmpJndiEncTests.java?view=diff&rev=495360&r1=495359&r2=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmp/CmpJndiEncTests.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmp/CmpJndiEncTests.java Thu Jan 11 12:18:54 2007
@@ -190,4 +190,14 @@
         }
     }
     
+    public void test15_lookupPersistenceContext() {
+        try{
+            ejbObject.lookupPersistenceContext();
+        } catch (TestFailureException e){
+            throw e.error;
+        } catch (Exception e){
+            fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+        }
+    }
+
 }

Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmp2/Cmp2JndiEncTests.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmp2/Cmp2JndiEncTests.java?view=diff&rev=495360&r1=495359&r2=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmp2/Cmp2JndiEncTests.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmp2/Cmp2JndiEncTests.java Thu Jan 11 12:18:54 2007
@@ -179,5 +179,14 @@
         }
     }
     
+    public void test14_lookupPersistenceContext() {
+        try{
+            ejbObject.lookupPersistenceContext();
+        } catch (TestFailureException e){
+            throw e.error;
+        } catch (Exception e){
+            fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+        }
+    }
 
 }

Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateful/StatefulContextLookupTests.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateful/StatefulContextLookupTests.java?view=diff&rev=495360&r1=495359&r2=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateful/StatefulContextLookupTests.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateful/StatefulContextLookupTests.java Thu Jan 11 12:18:54 2007
@@ -199,4 +199,14 @@
         }
     }
 
+    public void test15_lookupPersistenceContext() {
+        try{
+            ejbObject.lookupPersistenceContext();
+        } catch (TestFailureException e){
+            throw e.error;
+        } catch (Exception e){
+            fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+        }
+    }
+
 }

Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateful/StatefulJndiEncTests.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateful/StatefulJndiEncTests.java?view=diff&rev=495360&r1=495359&r2=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateful/StatefulJndiEncTests.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateful/StatefulJndiEncTests.java Thu Jan 11 12:18:54 2007
@@ -199,5 +199,14 @@
         }
     }
     
-    
+    public void test15_lookupPersistenceContext() {
+        try{
+            ejbObject.lookupPersistenceContext();
+        } catch (TestFailureException e){
+            throw e.error;
+        } catch (Exception e){
+            fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+        }
+    }
+
 }

Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateful/StatefulPojoContextLookupTests.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateful/StatefulPojoContextLookupTests.java?view=diff&rev=495360&r1=495359&r2=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateful/StatefulPojoContextLookupTests.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateful/StatefulPojoContextLookupTests.java Thu Jan 11 12:18:54 2007
@@ -199,4 +199,14 @@
         }
     }
 
+    public void test15_lookupPersistenceContext() {
+        try{
+            ejbObject.lookupPersistenceContext();
+        } catch (TestFailureException e){
+            throw e.error;
+        } catch (Exception e){
+            fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+        }
+    }
+
 }

Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateless/StatelessContextLookupTests.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateless/StatelessContextLookupTests.java?view=diff&rev=495360&r1=495359&r2=495360
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateless/StatelessContextLookupTests.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/stateless/StatelessContextLookupTests.java Thu Jan 11 12:18:54 2007
@@ -199,4 +199,14 @@
         }
     }
     
+    public void test15_lookupPersistenceContext() {
+        try{
+            ejbObject.lookupPersistenceContext();
+        } catch (TestFailureException e){
+            throw e.error;
+        } catch (Exception e){
+            fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+        }
+    }
+
 }