geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r471685 - in /geronimo/server/trunk: configs/j2ee-deployer/src/plan/ modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/ modules/geronimo-naming-builder/src/main/schema/ modules/geronimo-naming/src/main/java...
Date Mon, 06 Nov 2006 10:35:01 GMT
Author: djencks
Date: Mon Nov  6 02:35:00 2006
New Revision: 471685

URL: http://svn.apache.org/viewvc?view=rev&rev=471685
Log:
GERONIMO-2460 add application managed JPA support

Added:
    geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/EntityManagerFactoryRefBuilder.java
  (with props)
    geronimo/server/trunk/modules/geronimo-naming/src/main/java/org/apache/geronimo/naming/reference/EntityManagerFactoryReference.java
  (with props)
Modified:
    geronimo/server/trunk/configs/j2ee-deployer/src/plan/plan.xml
    geronimo/server/trunk/modules/geronimo-naming-builder/src/main/schema/geronimo-naming-1.2.xsd

Modified: geronimo/server/trunk/configs/j2ee-deployer/src/plan/plan.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/configs/j2ee-deployer/src/plan/plan.xml?view=diff&rev=471685&r1=471684&r2=471685
==============================================================================
--- geronimo/server/trunk/configs/j2ee-deployer/src/plan/plan.xml (original)
+++ geronimo/server/trunk/configs/j2ee-deployer/src/plan/plan.xml Mon Nov  6 02:35:00 2006
@@ -105,6 +105,9 @@
                 <name>PersistenceContextRefBuilder</name>
             </pattern>
             <pattern>
+                <name>EntityManagerFactoryRefBuilder</name>
+            </pattern>
+            <pattern>
                 <name>ResourceRefBuilder</name>
             </pattern>
             <pattern>
@@ -133,6 +136,7 @@
 
     <gbean name="GBeanRefBuilder" class="org.apache.geronimo.naming.deployment.GBeanRefBuilder"/>
     <gbean name="PersistenceContextRefBuilder" class="org.apache.geronimo.naming.deployment.PersistenceContextRefBuilder"/>
+    <gbean name="EntityManagerFactoryRefBuilder" class="org.apache.geronimo.naming.deployment.EntityManagerFactoryRefBuilder"/>
     <gbean name="EnvironmentEntryBuilder" class="org.apache.geronimo.naming.deployment.EnvironmentEntryBuilder">
         <attribute name="eeNamespaces">http://java.sun.com/xml/ns/j2ee</attribute>
     </gbean>

Added: geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/EntityManagerFactoryRefBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/EntityManagerFactoryRefBuilder.java?view=auto&rev=471685
==============================================================================
--- geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/EntityManagerFactoryRefBuilder.java
(added)
+++ geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/EntityManagerFactoryRefBuilder.java
Mon Nov  6 02:35:00 2006
@@ -0,0 +1,132 @@
+/*
+ * 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.geronimo.naming.deployment;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+
+import org.apache.geronimo.common.DeploymentException;
+import org.apache.geronimo.deployment.service.EnvironmentBuilder;
+import org.apache.geronimo.gbean.AbstractNameQuery;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.geronimo.j2ee.deployment.Module;
+import org.apache.geronimo.j2ee.deployment.NamingBuilder;
+import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
+import org.apache.geronimo.kernel.config.Configuration;
+import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.kernel.repository.Dependency;
+import org.apache.geronimo.kernel.repository.Environment;
+import org.apache.geronimo.kernel.repository.ImportType;
+import org.apache.geronimo.naming.reference.EntityManagerFactoryReference;
+import org.apache.geronimo.schema.NamespaceElementConverter;
+import org.apache.geronimo.schema.SchemaConversionUtils;
+import org.apache.geronimo.xbeans.geronimo.naming.GerEntityManagerFactoryRefDocument;
+import org.apache.geronimo.xbeans.geronimo.naming.GerEntityManagerFactoryRefType;
+import org.apache.geronimo.xbeans.geronimo.naming.GerPatternType;
+import org.apache.xmlbeans.QNameSet;
+import org.apache.xmlbeans.XmlObject;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class EntityManagerFactoryRefBuilder implements NamingBuilder {
+    private static final QName ENTITY_MANAGER_FACTORY_REF_QNAME = GerEntityManagerFactoryRefDocument.type.getDocumentElementName();
+    private static final QNameSet ENTITY_MANAGER_FACTORY_REF_QNAME_SET = QNameSet.singleton(EntityManagerFactoryRefBuilder.ENTITY_MANAGER_FACTORY_REF_QNAME);
+
+    private final Environment defaultEnvironment = new Environment();
+
+    public EntityManagerFactoryRefBuilder() {
+        defaultEnvironment.addDependency(new Dependency(new Artifact("org.apache.geronimo.modules",
"geronimo-persistence-jpa10", (String)null, "jar"), ImportType.CLASSES));
+    }
+
+    public void buildEnvironment(XmlObject specDD, XmlObject plan, Environment environment)
{
+        if (getEntityManagerFactoryRefs(plan).length > 0) {
+            EnvironmentBuilder.mergeEnvironments(environment, defaultEnvironment);
+        }
+    }
+
+    public void initContext(XmlObject specDD, XmlObject plan, Configuration localConfiguration,
Configuration remoteConfiguration, Module module) throws DeploymentException {
+    }
+
+    public void buildNaming(XmlObject specDD, XmlObject plan, Configuration localConfiguration,
Configuration remoteConfiguration, Module module, Map componentContext) throws DeploymentException
{
+        XmlObject[] EntityManagerFactoryRefsUntyped = getEntityManagerFactoryRefs(plan);
+        for (int i = 0; i < EntityManagerFactoryRefsUntyped.length; i++) {
+            XmlObject EntityManagerFactoryRefUntyped = EntityManagerFactoryRefsUntyped[i];
+            GerEntityManagerFactoryRefType EntityManagerFactoryRef = (GerEntityManagerFactoryRefType)
EntityManagerFactoryRefUntyped.copy().changeType(GerEntityManagerFactoryRefType.type);
+            if (EntityManagerFactoryRef == null) {
+                throw new DeploymentException("Could not read EntityManagerFactoryRef " +
EntityManagerFactoryRefUntyped + " as the correct xml type");
+            }
+            String EntityManagerFactoryRefName = EntityManagerFactoryRef.getEntityManagerFactoryRefName();
+
+            Set interfaceTypes = Collections.singleton("org.apache.geronimo.persistence.PersistenceUnitGBean");
+            AbstractNameQuery persistenceUnitNameQuery;
+            if (EntityManagerFactoryRef.isSetPersistenceUnitName()) {
+                String persistenceUnitName = EntityManagerFactoryRef.getPersistenceUnitName();
+                persistenceUnitNameQuery = new AbstractNameQuery(null, Collections.singletonMap("name",
persistenceUnitName), interfaceTypes);
+            } else {
+                GerPatternType gbeanLocator = EntityManagerFactoryRef.getPattern();
+
+                persistenceUnitNameQuery = ENCConfigBuilder.buildAbstractNameQuery(gbeanLocator,
null, null, interfaceTypes);
+            }
+
+            try {
+                localConfiguration.findGBeanData(persistenceUnitNameQuery);
+            } catch (GBeanNotFoundException e) {
+                throw new DeploymentException("Could not resolve reference at deploy time
for query " + persistenceUnitNameQuery, e);
+            }
+
+            EntityManagerFactoryReference reference = new EntityManagerFactoryReference(localConfiguration.getId(),
persistenceUnitNameQuery);
+
+            ((Map)componentContext.get(JNDI_KEY)).put(ENV + EntityManagerFactoryRefName,
reference);
+
+        }
+    }
+
+    public QNameSet getSpecQNameSet() {
+        SchemaConversionUtils.registerNamespaceConversions(Collections.singletonMap(EntityManagerFactoryRefBuilder.ENTITY_MANAGER_FACTORY_REF_QNAME.getLocalPart(),
new NamespaceElementConverter(EntityManagerFactoryRefBuilder.ENTITY_MANAGER_FACTORY_REF_QNAME.getNamespaceURI())));
+        return QNameSet.EMPTY;
+    }
+
+    public QNameSet getPlanQNameSet() {
+        return EntityManagerFactoryRefBuilder.ENTITY_MANAGER_FACTORY_REF_QNAME_SET;
+    }
+
+    private XmlObject[] getEntityManagerFactoryRefs(XmlObject plan) {
+        return plan == null? NO_REFS: plan.selectChildren(EntityManagerFactoryRefBuilder.ENTITY_MANAGER_FACTORY_REF_QNAME_SET);
+    }
+
+    public static final GBeanInfo GBEAN_INFO;
+
+    static {
+        GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(EntityManagerFactoryRefBuilder.class,
NameFactory.MODULE_BUILDER);
+
+        GBEAN_INFO = infoBuilder.getBeanInfo();
+    }
+
+    public static GBeanInfo getGBeanInfo() {
+        return EntityManagerFactoryRefBuilder.GBEAN_INFO;
+    }
+}

Propchange: geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/EntityManagerFactoryRefBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/EntityManagerFactoryRefBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/EntityManagerFactoryRefBuilder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/modules/geronimo-naming-builder/src/main/schema/geronimo-naming-1.2.xsd
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-naming-builder/src/main/schema/geronimo-naming-1.2.xsd?view=diff&rev=471685&r1=471684&r2=471685
==============================================================================
--- geronimo/server/trunk/modules/geronimo-naming-builder/src/main/schema/geronimo-naming-1.2.xsd
(original)
+++ geronimo/server/trunk/modules/geronimo-naming-builder/src/main/schema/geronimo-naming-1.2.xsd
Mon Nov  6 02:35:00 2006
@@ -129,6 +129,23 @@
         </xsd:complexContent>
     </xsd:complexType>
 
+    <xsd:element name="entity-manager-factory-ref" type="gernaming:entity-manager-factory-refType"
+                 substitutionGroup="gernaming:abstract-naming-entry"/>
+
+    <xsd:complexType name="entity-manager-factory-refType">
+        <xsd:complexContent>
+            <xsd:extension base="gernaming:abstract-naming-entryType">
+                <xsd:sequence>
+                    <xsd:element name="entity-manager-factory-ref-name" type="xsd:string"/>
+                    <xsd:choice>
+                        <xsd:element name="persistence-unit-name" type="xsd:string"/>
+                        <xsd:element name="pattern" type="gernaming:patternType"/>
+                    </xsd:choice>
+                </xsd:sequence>
+            </xsd:extension>
+        </xsd:complexContent>
+    </xsd:complexType>
+
     <xsd:element name="persistence-context-ref" type="gernaming:persistence-context-refType"
                  substitutionGroup="gernaming:abstract-naming-entry"/>
 

Added: geronimo/server/trunk/modules/geronimo-naming/src/main/java/org/apache/geronimo/naming/reference/EntityManagerFactoryReference.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-naming/src/main/java/org/apache/geronimo/naming/reference/EntityManagerFactoryReference.java?view=auto&rev=471685
==============================================================================
--- geronimo/server/trunk/modules/geronimo-naming/src/main/java/org/apache/geronimo/naming/reference/EntityManagerFactoryReference.java
(added)
+++ geronimo/server/trunk/modules/geronimo-naming/src/main/java/org/apache/geronimo/naming/reference/EntityManagerFactoryReference.java
Mon Nov  6 02:35:00 2006
@@ -0,0 +1,66 @@
+/*
+ * 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.geronimo.naming.reference;
+
+import javax.naming.NameNotFoundException;
+
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.AbstractNameQuery;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.repository.Artifact;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class EntityManagerFactoryReference extends ConfigurationAwareReference {
+
+
+    public EntityManagerFactoryReference(Artifact configId, AbstractNameQuery abstractNameQuery)
{
+        super(configId, abstractNameQuery);
+    }
+
+    public String getClassName() {
+        return "javax.persistence.EntityManagerFactory";
+    }
+
+    public Object getContent() throws NameNotFoundException {
+    Kernel kernel = getKernel();
+
+    AbstractName target;
+    try {
+        target = resolveTargetName();
+    } catch (GBeanNotFoundException e) {
+        throw (NameNotFoundException) new NameNotFoundException("Could not resolve name query:
" + abstractNameQueries).initCause(e);
+    }
+
+    Object entityManagerFactory;
+    try {
+        entityManagerFactory = kernel.invoke(target, "getEntityManagerFactory");
+    } catch (Exception e) {
+        throw (IllegalStateException) new IllegalStateException("Could not get EntityManagerFactory").initCause(e);
+    }
+    if (entityManagerFactory == null) {
+        throw new IllegalStateException("entity manager not returned. Target " + target +
" not started");
+    }
+    return entityManagerFactory;
+}
+}

Propchange: geronimo/server/trunk/modules/geronimo-naming/src/main/java/org/apache/geronimo/naming/reference/EntityManagerFactoryReference.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/modules/geronimo-naming/src/main/java/org/apache/geronimo/naming/reference/EntityManagerFactoryReference.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/modules/geronimo-naming/src/main/java/org/apache/geronimo/naming/reference/EntityManagerFactoryReference.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message