geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r604127 - in /geronimo/server/trunk/plugins/openejb: geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java geronimo-openejb/src/main/java/org/apache/geronimo/openejb/OpenEjbSystemGBean.java
Date Fri, 14 Dec 2007 08:12:28 GMT
Author: dblevins
Date: Fri Dec 14 00:12:27 2007
New Revision: 604127

URL: http://svn.apache.org/viewvc?rev=604127&view=rev
Log:
Rework to fix issue where this won't work if there is more than one persistence-unit in the
server:
@PersistenceContext(persistenceType=EXTENDED) EntityManager foo;
i.e. no unitName was specified.

Modified:
    geronimo/server/trunk/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java
    geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/OpenEjbSystemGBean.java

Modified: geronimo/server/trunk/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java?rev=604127&r1=604126&r2=604127&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java
(original)
+++ geronimo/server/trunk/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java
Fri Dec 14 00:12:27 2007
@@ -82,6 +82,7 @@
 import org.apache.geronimo.security.jacc.ComponentPermissions;
 import org.apache.geronimo.xbeans.geronimo.j2ee.GerSecurityDocument;
 import org.apache.geronimo.xbeans.javaee.EjbJarType;
+import org.apache.geronimo.persistence.PersistenceUnitGBean;
 import org.apache.openejb.OpenEJBException;
 import org.apache.openejb.assembler.classic.AppInfo;
 import org.apache.openejb.assembler.classic.CmpJarBuilder;
@@ -93,6 +94,9 @@
 import org.apache.openejb.assembler.classic.MdbContainerInfo;
 import org.apache.openejb.assembler.classic.MessageDrivenBeanInfo;
 import org.apache.openejb.assembler.classic.OpenEjbConfiguration;
+import org.apache.openejb.assembler.classic.LinkResolver;
+import org.apache.openejb.assembler.classic.StatefulBeanInfo;
+import org.apache.openejb.assembler.classic.PersistenceContextReferenceInfo;
 import org.apache.openejb.config.AppModule;
 import org.apache.openejb.config.ConfigurationFactory;
 import org.apache.openejb.config.DeploymentLoader;
@@ -732,6 +736,27 @@
         // add enc
         ejbDeploymentBuilder.buildEnc();
 
+        Set<GBeanData> gBeanDatas = earContext.getConfiguration().findGBeanDatas(Collections.singleton(new
AbstractNameQuery(PersistenceUnitGBean.class.getName())));
+        LinkResolver<String> linkResolver = new LinkResolver<String>();
+        for (GBeanData gBeanData : gBeanDatas) {
+            String name = (String) gBeanData.getAttribute("persistenceUnitName");
+            String rootUrl = (String) gBeanData.getAttribute("persistenceUnitRoot");
+            String id = name + " " + rootUrl.hashCode();
+            linkResolver.add(rootUrl, name, id);
+        }
+
+        EjbJarInfo ejbJarInfo = ejbModule.getEjbJarInfo();
+        for (EnterpriseBeanInfo beanInfo : ejbJarInfo.enterpriseBeans) {
+            if (beanInfo instanceof StatefulBeanInfo) {
+                StatefulBeanInfo statefulBeanInfo = (StatefulBeanInfo) beanInfo;
+                for (PersistenceContextReferenceInfo refInfo : statefulBeanInfo.jndiEnc.persistenceContextRefs)
{
+                    if (refInfo.extended) {
+                        String id = linkResolver.resolveLink(refInfo.persistenceUnitName,
ejbJarInfo.moduleId);
+                        refInfo.unitId = id;
+                    }
+                }
+            }
+        }
         // Add JSR77 EJBModule GBean
         GBeanData ejbModuleGBeanData = new GBeanData(ejbModule.getModuleName(), EjbModuleImplGBean.GBEAN_INFO);
         try {

Modified: geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/OpenEjbSystemGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/OpenEjbSystemGBean.java?rev=604127&r1=604126&r2=604127&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/OpenEjbSystemGBean.java
(original)
+++ geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/OpenEjbSystemGBean.java
Fri Dec 14 00:12:27 2007
@@ -29,6 +29,7 @@
 import javax.ejb.spi.HandleDelegate;
 import javax.management.ObjectName;
 import javax.naming.NamingException;
+import javax.naming.Context;
 import javax.persistence.EntityManagerFactory;
 import javax.resource.spi.ResourceAdapter;
 import javax.transaction.TransactionManager;
@@ -181,6 +182,54 @@
         return proxy;
     }
 
+    private void processPersistenceUnitGBeans(Collection<PersistenceUnitGBean> persistenceUnitGBeans)
{
+        if (persistenceUnitGBeans == null) {
+            return;
+        }
+
+        if (persistenceUnitGBeans instanceof ReferenceCollection) {
+            ReferenceCollection referenceCollection = (ReferenceCollection) persistenceUnitGBeans;
+            referenceCollection.addReferenceCollectionListener(new ReferenceCollectionListener()
{
+                public void memberAdded(ReferenceCollectionEvent event) {
+                    addPersistenceUnitGBean((PersistenceUnitGBean) event.getMember());
+                }
+
+                public void memberRemoved(ReferenceCollectionEvent event) {
+                    removePersistenceUnitGBean((PersistenceUnitGBean) event.getMember());
+                }
+
+            });
+        }
+        for (PersistenceUnitGBean persistenceUnitGBean : persistenceUnitGBeans) {
+            addPersistenceUnitGBean(persistenceUnitGBean);
+        }
+    }
+
+    private void addPersistenceUnitGBean(PersistenceUnitGBean persistenceUnitGBean) {
+        String unit = persistenceUnitGBean.getPersistenceUnitName();
+        String rootUrl = persistenceUnitGBean.getPersistenceUnitRoot();
+        String id = unit + " " + rootUrl.hashCode();
+        Context context = SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext();
+        try {
+            context.bind("java:openejb/PersistenceUnit/" + id, persistenceUnitGBean.getEntityManagerFactory());
+        } catch (Exception e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    private void removePersistenceUnitGBean(PersistenceUnitGBean persistenceUnitGBean) {
+        String unit = persistenceUnitGBean.getPersistenceUnitName();
+        String rootUrl = persistenceUnitGBean.getPersistenceUnitRoot();
+        String id = unit + " " + rootUrl.hashCode();
+        Context context = SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext();
+        try {
+            context.unbind("java:openejb/PersistenceUnit/" + id);
+        } catch (Exception e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+
     private void processResourceAdapterWrappers(Collection<ResourceAdapterWrapper>
resourceAdapterWrappers) {
         if (resourceAdapterWrappers == null) {
             return;
@@ -355,7 +404,7 @@
             }
         }
         try {
-            assembler.createEjbJar(ejbJarInfo, emfLinkResolver, classLoader);
+            assembler.createEjbJar(ejbJarInfo, classLoader);
         } finally {
             Thread.currentThread().setContextClassLoader(oldClassLoader);
         }



Mime
View raw message