geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r505820 - in /geronimo/server/trunk: configs/persistence-jpa10-deployer/ modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/j2eeobjectnames/ modules/geronimo-persistence-jpa10-builder/ modules/geronimo-persistence-jpa10-builder/sr...
Date Sun, 11 Feb 2007 01:59:36 GMT
Author: djencks
Date: Sat Feb 10 17:59:35 2007
New Revision: 505820

URL: http://svn.apache.org/viewvc?view=rev&rev=505820
Log:
Make persistence unit deployer use better gbean names and search for persistence.xml files

Modified:
    geronimo/server/trunk/configs/persistence-jpa10-deployer/pom.xml
    geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/j2eeobjectnames/NameFactory.java
    geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/pom.xml
    geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitBuilder.java
    geronimo/server/trunk/modules/geronimo-persistence-jpa10/src/main/java/org/apache/geronimo/persistence/PersistenceUnitGBean.java

Modified: geronimo/server/trunk/configs/persistence-jpa10-deployer/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/configs/persistence-jpa10-deployer/pom.xml?view=diff&rev=505820&r1=505819&r2=505820
==============================================================================
--- geronimo/server/trunk/configs/persistence-jpa10-deployer/pom.xml (original)
+++ geronimo/server/trunk/configs/persistence-jpa10-deployer/pom.xml Sat Feb 10 17:59:35 2007
@@ -48,7 +48,12 @@
             <artifactId>geronimo-persistence-jpa10-builder</artifactId>
             <version>${version}</version>
         </dependency>
-        
+
+        <dependency>
+            <groupId>org.apache.xbean</groupId>
+            <artifactId>xbean-finder</artifactId>
+        </dependency>
+
         <dependency>
             <groupId>org.apache.geronimo.configs</groupId>
             <artifactId>transaction-jta11</artifactId>
@@ -58,10 +63,10 @@
         </dependency>
 
         <!--todo get the schema classes in a config -->
-        <dependency>
-            <groupId>org.apache.geronimo.schema</groupId>
-            <artifactId>geronimo-schema-jee_5</artifactId>
-        </dependency>
+        <!--<dependency>-->
+            <!--<groupId>org.apache.geronimo.schema</groupId>-->
+            <!--<artifactId>geronimo-schema-jee_5</artifactId>-->
+        <!--</dependency>-->
 
     </dependencies>
 

Modified: geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/j2eeobjectnames/NameFactory.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/j2eeobjectnames/NameFactory.java?view=diff&rev=505820&r1=505819&r2=505820
==============================================================================
--- geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/j2eeobjectnames/NameFactory.java
(original)
+++ geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/j2eeobjectnames/NameFactory.java
Sat Feb 10 17:59:35 2007
@@ -97,6 +97,7 @@
     public static final String SECURITY_REALM = "SecurityRealm";
     public static final String LOGIN_MODULE = "LoginModule";
     public static final String APP_CLIENT = "AppClient";
+    public static final String PERSISTENCE_UNIT = "PersistenceUnit";
     //jsr 88 configurer
     public static final String DEPLOYMENT_CONFIGURER = "DeploymentConfigurer";
     public static final String CONFIGURATION_STORE = "ConfigurationStore";

Modified: geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/pom.xml?view=diff&rev=505820&r1=505819&r2=505820
==============================================================================
--- geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/pom.xml (original)
+++ geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/pom.xml Sat Feb 10 17:59:35
2007
@@ -69,6 +69,11 @@
             <artifactId>geronimo-schema-jee_5</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>org.apache.xbean</groupId>
+            <artifactId>xbean-finder</artifactId>
+        </dependency>
+
     </dependencies>
     
     <build>

Modified: geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitBuilder.java?view=diff&rev=505820&r1=505819&r2=505820
==============================================================================
--- geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitBuilder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitBuilder.java
Sat Feb 10 17:59:35 2007
@@ -16,10 +16,11 @@
  */
 package org.apache.geronimo.persistence.builder;
 
+import java.io.IOException;
 import java.net.MalformedURLException;
-import java.net.URL;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Properties;
@@ -30,18 +31,22 @@
 import org.apache.geronimo.deployment.DeploymentContext;
 import org.apache.geronimo.deployment.NamespaceDrivenBuilder;
 import org.apache.geronimo.deployment.service.EnvironmentBuilder;
+import org.apache.geronimo.deployment.xmlbeans.XmlBeansUtil;
 import org.apache.geronimo.gbean.AbstractNameQuery;
 import org.apache.geronimo.gbean.GBeanData;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.j2ee.deployment.EARContext;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
 import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
 import org.apache.geronimo.kernel.repository.Environment;
 import org.apache.geronimo.persistence.PersistenceUnitGBean;
 import org.apache.geronimo.xbeans.persistence.PersistenceDocument;
-import org.apache.xmlbeans.XmlObject;
+import org.apache.xbean.finder.ResourceFinder;
 import org.apache.xmlbeans.QNameSet;
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlObject;
 
 /**
  * @version $Rev$ $Date$
@@ -68,94 +73,125 @@
         XmlObject[] raws = container.selectChildren(PERSISTENCE_QNAME);
         for (XmlObject raw : raws) {
             PersistenceDocument.Persistence persistence = (PersistenceDocument.Persistence)
raw.copy().changeType(PersistenceDocument.Persistence.type);
-            PersistenceDocument.Persistence.PersistenceUnit[] persistenceUnits = persistence.getPersistenceUnitArray();
-            for (PersistenceDocument.Persistence.PersistenceUnit persistenceUnit : persistenceUnits)
{
-                String persistenceUnitName = persistenceUnit.getName().trim();
-                GBeanData gbeanData;
+            buildPersistenceUnits(persistence, moduleContext);
+        }
+        ResourceFinder finder = new ResourceFinder("", moduleContext.getClassLoader(), null);
+        try {
+            List<URL> persistenceUrls = finder.findAll("META-INF/persistence.xml");
+            for (URL persistenceUrl: persistenceUrls) {
+                PersistenceDocument persistenceDocument;
                 try {
-                    gbeanData = moduleContext.addGBean(persistenceUnitName, PersistenceUnitGBean.GBEAN_INFO);
-                } catch (GBeanAlreadyExistsException e) {
-                    throw new DeploymentException("Duplicate persistenceUnit name " + persistenceUnitName,
e);
-                }
-                gbeanData.setAttribute("persistenceUnitName", persistenceUnitName);
-                if (persistenceUnit.isSetProvider()) {
-                    gbeanData.setAttribute("persistenceProviderClassName", persistenceUnit.getProvider().trim());
-                } else {
-                    gbeanData.setAttribute("persistenceProviderClassName", defaultPersistenceProviderClassName);
-                }
-                gbeanData.setAttribute("persistenceUnitTransactionType", persistenceUnit.getTransactionType().toString());
-                if (persistenceUnit.isSetJtaDataSource()) {
-                    String jtaDataSourceString = persistenceUnit.getJtaDataSource().trim();
-                    try {
-                        AbstractNameQuery jtaDataSourceNameQuery = new AbstractNameQuery(new
URI(jtaDataSourceString + "#org.apache.geronimo.connector.outbound.ConnectionFactorySource"));
-                        gbeanData.setReferencePattern("JtaDataSourceWrapper", jtaDataSourceNameQuery);
-                    } catch (URISyntaxException e) {
-                        throw new DeploymentException("Could not create jta-data-source AbstractNameQuery
from string: " + jtaDataSourceString, e);
-                    }
+                    persistenceDocument = (PersistenceDocument) XmlBeansUtil.parse(persistenceUrl,
moduleContext.getClassLoader());
+                } catch (XmlException e) {
+                    throw new DeploymentException("Could not parse persistence.xml file:
" + persistenceUrl, e);
                 }
+                PersistenceDocument.Persistence persistence = persistenceDocument.getPersistence();
+                buildPersistenceUnits(persistence, moduleContext);
+            }
+        } catch (IOException e) {
+            throw new DeploymentException("Could not look for META-INF/persistence.xml files",
e);
+        }
+    }
 
-                if (persistenceUnit.isSetNonJtaDataSource()) {
-                    String nonJtaDataSourceString = persistenceUnit.getNonJtaDataSource().trim();
-                    try {
-                        AbstractNameQuery nonJtaDataSourceNameQuery = new AbstractNameQuery(new
URI(nonJtaDataSourceString + "#org.apache.geronimo.connector.outbound.ConnectionFactorySource"));
-                        gbeanData.setReferencePattern("NonJtaDataSourceWrapper", nonJtaDataSourceNameQuery);
-                    } catch (URISyntaxException e) {
-                        throw new DeploymentException("Could not create non-jta-data-source
AbstractNameQuery from string: " + nonJtaDataSourceString, e);
-                    }
-                }
+    private void buildPersistenceUnits(PersistenceDocument.Persistence persistence, DeploymentContext
moduleContext) throws DeploymentException {
+        PersistenceDocument.Persistence.PersistenceUnit[] persistenceUnits = persistence.getPersistenceUnitArray();
+        for (PersistenceDocument.Persistence.PersistenceUnit persistenceUnit : persistenceUnits)
{
+            installPersistenceUnitGBean(persistenceUnit, moduleContext);
+        }
+    }
 
-                List<String> mappingFileNames = new ArrayList<String>();
-                String[] mappingFileNameStrings = persistenceUnit.getMappingFileArray();
-                for (String mappingFileNameString : mappingFileNameStrings) {
-                    mappingFileNames.add(mappingFileNameString.trim());
-                }
-                gbeanData.setAttribute("mappingFileNames", mappingFileNames);
+    private void installPersistenceUnitGBean(PersistenceDocument.Persistence.PersistenceUnit
persistenceUnit, DeploymentContext moduleContext) throws DeploymentException {
+        String persistenceUnitName = persistenceUnit.getName().trim();
+        AbstractName abstractName = moduleContext.getNaming().createChildName(moduleContext.getModuleName(),
persistenceUnitName, PersistenceUnitGBean.GBEAN_INFO.getJ2eeType());
+        GBeanData gbeanData = new GBeanData(abstractName, PersistenceUnitGBean.GBEAN_INFO);
+        try {
+            moduleContext.addGBean(gbeanData);
+        } catch (GBeanAlreadyExistsException e) {
+            throw new DeploymentException("Duplicate persistenceUnit name " + persistenceUnitName,
e);
+        }
+        gbeanData.setAttribute("persistenceUnitName", persistenceUnitName);
+        if (persistenceUnit.isSetProvider()) {
+            gbeanData.setAttribute("persistenceProviderClassName", persistenceUnit.getProvider().trim());
+        } else {
+            gbeanData.setAttribute("persistenceProviderClassName", defaultPersistenceProviderClassName);
+        }
+        gbeanData.setAttribute("persistenceUnitTransactionType", persistenceUnit.getTransactionType().toString());
+        if (persistenceUnit.isSetJtaDataSource()) {
+            String jtaDataSourceString = persistenceUnit.getJtaDataSource().trim();
+            if (jtaDataSourceString.indexOf('=') == -1) {
+                jtaDataSourceString = "name=" + jtaDataSourceString;
+            }
+            try {
+                AbstractNameQuery jtaDataSourceNameQuery = new AbstractNameQuery(new URI(jtaDataSourceString
+ "#org.apache.geronimo.connector.outbound.ConnectionFactorySource"));
+                gbeanData.setReferencePattern("JtaDataSourceWrapper", jtaDataSourceNameQuery);
+            } catch (URISyntaxException e) {
+                throw new DeploymentException("Could not create jta-data-source AbstractNameQuery
from string: " + jtaDataSourceString, e);
+            }
+        }
 
-                List<URL> jarFileUrls = new ArrayList<URL>();
-                String[] jarFileUrlStrings = persistenceUnit.getJarFileArray();
-                for (String jarFileUrlString1 : jarFileUrlStrings) {
-                    String jarFileUrlString = jarFileUrlString1.trim();
-                    try {
-                        URL jarFileUrl = new URL(jarFileUrlString);
-                        jarFileUrls.add(jarFileUrl);
-                    } catch (MalformedURLException e) {
-                        throw new DeploymentException("could not create URL for jarFileURL",
e);
-                    }
-                }
-                gbeanData.setAttribute("jarFileUrls", jarFileUrls);
-                //TODO what is this from??
+        if (persistenceUnit.isSetNonJtaDataSource()) {
+            String nonJtaDataSourceString = persistenceUnit.getNonJtaDataSource().trim();
+            if (nonJtaDataSourceString.indexOf('=') == -1) {
+                nonJtaDataSourceString = "name=" + nonJtaDataSourceString;
+            }
+            try {
+                AbstractNameQuery nonJtaDataSourceNameQuery = new AbstractNameQuery(new URI(nonJtaDataSourceString
+ "#org.apache.geronimo.connector.outbound.ConnectionFactorySource"));
+                gbeanData.setReferencePattern("NonJtaDataSourceWrapper", nonJtaDataSourceNameQuery);
+            } catch (URISyntaxException e) {
+                throw new DeploymentException("Could not create non-jta-data-source AbstractNameQuery
from string: " + nonJtaDataSourceString, e);
+            }
+        }
+
+        List<String> mappingFileNames = new ArrayList<String>();
+        String[] mappingFileNameStrings = persistenceUnit.getMappingFileArray();
+        for (String mappingFileNameString : mappingFileNameStrings) {
+            mappingFileNames.add(mappingFileNameString.trim());
+        }
+        gbeanData.setAttribute("mappingFileNames", mappingFileNames);
+
+        List<URL> jarFileUrls = new ArrayList<URL>();
+        String[] jarFileUrlStrings = persistenceUnit.getJarFileArray();
+        for (String jarFileUrlString1 : jarFileUrlStrings) {
+            String jarFileUrlString = jarFileUrlString1.trim();
+            try {
+                URL jarFileUrl = new URL(jarFileUrlString);
+                jarFileUrls.add(jarFileUrl);
+            } catch (MalformedURLException e) {
+                throw new DeploymentException("could not create URL for jarFileURL", e);
+            }
+        }
+        gbeanData.setAttribute("jarFileUrls", jarFileUrls);
+        //TODO what is this from??
 //                URL persistenceUnitRootUrl = new URL(persistenceUnit.get)
 //                gbeanData.setAttribute("persistenceUnitRootUrl", persistenceUnitRootUrl);
 
-                String[] managedClassNameStrings = persistenceUnit.getClass1Array();
-                List<String> managedClassNames = new ArrayList<String>();
-                for (String managedClassNameString : managedClassNameStrings) {
-                    managedClassNames.add(managedClassNameString.trim());
-                }
-                gbeanData.setAttribute("managedClassNames", managedClassNames);
-                if (persistenceUnit.isSetExcludeUnlistedClasses()) {
-                    gbeanData.setAttribute("excludeUnlistedClasses", persistenceUnit.getExcludeUnlistedClasses());
-                } else {
-                    gbeanData.setAttribute("excludeUnlistedClasses", false);
-                }
-
-                Properties properties = new Properties();
-                if (persistenceUnit.isSetProperties()) {
-                    PersistenceDocument.Persistence.PersistenceUnit.Properties.Property[]
propertyObjects = persistenceUnit.getProperties().getPropertyArray();
-                    for (PersistenceDocument.Persistence.PersistenceUnit.Properties.Property
propertyObject : propertyObjects)
-                    {
-                        String key = propertyObject.getName().trim();
-                        String value = propertyObject.getValue().trim();
-                        properties.setProperty(key, value);
-                    }
-                }
+        String[] managedClassNameStrings = persistenceUnit.getClass1Array();
+        List<String> managedClassNames = new ArrayList<String>();
+        for (String managedClassNameString : managedClassNameStrings) {
+            managedClassNames.add(managedClassNameString.trim());
+        }
+        gbeanData.setAttribute("managedClassNames", managedClassNames);
+        if (persistenceUnit.isSetExcludeUnlistedClasses()) {
+            gbeanData.setAttribute("excludeUnlistedClasses", persistenceUnit.getExcludeUnlistedClasses());
+        } else {
+            gbeanData.setAttribute("excludeUnlistedClasses", false);
+        }
 
-                gbeanData.setAttribute("properties", properties);
-                if (moduleContext instanceof EARContext) {
-                    AbstractNameQuery transactionManagerName = ((EARContext) moduleContext).getTransactionManagerName();
-                    gbeanData.setReferencePattern("TransactionManager", transactionManagerName);
-                }
+        Properties properties = new Properties();
+        if (persistenceUnit.isSetProperties()) {
+            PersistenceDocument.Persistence.PersistenceUnit.Properties.Property[] propertyObjects
= persistenceUnit.getProperties().getPropertyArray();
+            for (PersistenceDocument.Persistence.PersistenceUnit.Properties.Property propertyObject
: propertyObjects)
+            {
+                String key = propertyObject.getName().trim();
+                String value = propertyObject.getValue().trim();
+                properties.setProperty(key, value);
             }
+        }
+
+        gbeanData.setAttribute("properties", properties);
+        if (moduleContext instanceof EARContext) {
+            AbstractNameQuery transactionManagerName = ((EARContext) moduleContext).getTransactionManagerName();
+            gbeanData.setReferencePattern("TransactionManager", transactionManagerName);
         }
     }
 

Modified: geronimo/server/trunk/modules/geronimo-persistence-jpa10/src/main/java/org/apache/geronimo/persistence/PersistenceUnitGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-persistence-jpa10/src/main/java/org/apache/geronimo/persistence/PersistenceUnitGBean.java?view=diff&rev=505820&r1=505819&r2=505820
==============================================================================
--- geronimo/server/trunk/modules/geronimo-persistence-jpa10/src/main/java/org/apache/geronimo/persistence/PersistenceUnitGBean.java
(original)
+++ geronimo/server/trunk/modules/geronimo-persistence-jpa10/src/main/java/org/apache/geronimo/persistence/PersistenceUnitGBean.java
Sat Feb 10 17:59:35 2007
@@ -273,7 +273,7 @@
     public static final GBeanInfo GBEAN_INFO;
 
     static {
-        GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(PersistenceUnitGBean.class);
+        GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(PersistenceUnitGBean.class,
NameFactory.PERSISTENCE_UNIT);
         infoBuilder.setPriority(GBeanInfo.PRIORITY_CLASSLOADER);
 
         infoBuilder.addAttribute("persistenceUnitName", String.class, true, true);



Mime
View raw message