geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r524702 - in /geronimo/server/trunk/modules: geronimo-j2ee-builder/ geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/ geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/
Date Sun, 01 Apr 2007 23:18:39 GMT
Author: djencks
Date: Sun Apr  1 16:18:38 2007
New Revision: 524702

URL: http://svn.apache.org/viewvc?view=rev&rev=524702
Log:
GERONIMO-3022 PersistenceContext and PersistenceUnit annotation support

Added:
    geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/PersistenceContextAnnotationHelper.java
  (with props)
    geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/PersistenceUnitAnnotationHelper.java
  (with props)
Modified:
    geronimo/server/trunk/modules/geronimo-j2ee-builder/pom.xml
    geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/AnnotatedApp.java
    geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/AnnotatedApplicationClient.java
    geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/AnnotatedEjbJar.java
    geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/AnnotatedWebApp.java
    geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceContextRefBuilder.java
    geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitRefBuilder.java

Modified: geronimo/server/trunk/modules/geronimo-j2ee-builder/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-j2ee-builder/pom.xml?view=diff&rev=524702&r1=524701&r2=524702
==============================================================================
--- geronimo/server/trunk/modules/geronimo-j2ee-builder/pom.xml (original)
+++ geronimo/server/trunk/modules/geronimo-j2ee-builder/pom.xml Sun Apr  1 16:18:38 2007
@@ -72,6 +72,11 @@
             <artifactId>axis2-jaxws-api</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-jpa_3.0_spec</artifactId>
+        </dependency>
+
     </dependencies>
 
     <build>
@@ -151,7 +156,7 @@
                     </execution>
                 </executions>
             </plugin>
-            
+
             <!--
             HACK: Copy XmlBeans generated schemas.
             -->
@@ -181,7 +186,7 @@
                     </execution>
                 </executions>
             </plugin>
-            
+
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-antrun-plugin</artifactId>

Modified: geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/AnnotatedApp.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/AnnotatedApp.java?view=diff&rev=524702&r1=524701&r2=524702
==============================================================================
--- geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/AnnotatedApp.java
(original)
+++ geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/AnnotatedApp.java
Sun Apr  1 16:18:38 2007
@@ -22,11 +22,13 @@
 import org.apache.geronimo.xbeans.javaee.EjbLocalRefType;
 import org.apache.geronimo.xbeans.javaee.EjbRefType;
 import org.apache.geronimo.xbeans.javaee.EnvEntryType;
+import org.apache.geronimo.xbeans.javaee.LifecycleCallbackType;
 import org.apache.geronimo.xbeans.javaee.MessageDestinationRefType;
+import org.apache.geronimo.xbeans.javaee.PersistenceContextRefType;
+import org.apache.geronimo.xbeans.javaee.PersistenceUnitRefType;
 import org.apache.geronimo.xbeans.javaee.ResourceEnvRefType;
 import org.apache.geronimo.xbeans.javaee.ResourceRefType;
 import org.apache.geronimo.xbeans.javaee.ServiceRefType;
-import org.apache.geronimo.xbeans.javaee.LifecycleCallbackType;
 
 /**
  * Many of the classes generated from the JEE schemas have methods with identical signatures
(see
@@ -123,5 +125,9 @@
     LifecycleCallbackType[] getPreDestroyArray();
     LifecycleCallbackType addPreDestroy();
 
+    PersistenceContextRefType[] getPersistenceContextRefArray();
+    PersistenceContextRefType addNewPersistenceContextRef();
 
+    PersistenceUnitRefType[] getPersistenceUnitRefArray();
+    PersistenceUnitRefType addNewPersistenceUnitRef();
 }

Modified: geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/AnnotatedApplicationClient.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/AnnotatedApplicationClient.java?view=diff&rev=524702&r1=524701&r2=524702
==============================================================================
--- geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/AnnotatedApplicationClient.java
(original)
+++ geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/AnnotatedApplicationClient.java
Sun Apr  1 16:18:38 2007
@@ -26,11 +26,13 @@
 import org.apache.geronimo.xbeans.javaee.EjbLocalRefType;
 import org.apache.geronimo.xbeans.javaee.EjbRefType;
 import org.apache.geronimo.xbeans.javaee.EnvEntryType;
+import org.apache.geronimo.xbeans.javaee.LifecycleCallbackType;
 import org.apache.geronimo.xbeans.javaee.MessageDestinationRefType;
+import org.apache.geronimo.xbeans.javaee.PersistenceContextRefType;
+import org.apache.geronimo.xbeans.javaee.PersistenceUnitRefType;
 import org.apache.geronimo.xbeans.javaee.ResourceEnvRefType;
 import org.apache.geronimo.xbeans.javaee.ResourceRefType;
 import org.apache.geronimo.xbeans.javaee.ServiceRefType;
-import org.apache.geronimo.xbeans.javaee.LifecycleCallbackType;
 
 /**
  * Wrapper class to encapsulate the ApplicationClientType class with an interface that the
various
@@ -178,4 +180,21 @@
     public LifecycleCallbackType addPreDestroy() {
         return applicationClient.addNewPreDestroy();
     }
+
+    public PersistenceContextRefType[] getPersistenceContextRefArray() {
+        return null;                                            // Not supported by app clients
+    }
+
+    public PersistenceContextRefType addNewPersistenceContextRef() {
+        return null;                                            // Not supported by app clients
+    }
+
+    public PersistenceUnitRefType[] getPersistenceUnitRefArray() {
+        return applicationClient.getPersistenceUnitRefArray();
+    }
+
+    public PersistenceUnitRefType addNewPersistenceUnitRef() {
+        return applicationClient.addNewPersistenceUnitRef();
+    }
+
 }

Modified: geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/AnnotatedEjbJar.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/AnnotatedEjbJar.java?view=diff&rev=524702&r1=524701&r2=524702
==============================================================================
--- geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/AnnotatedEjbJar.java
(original)
+++ geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/AnnotatedEjbJar.java
Sun Apr  1 16:18:38 2007
@@ -29,6 +29,8 @@
 import org.apache.geronimo.xbeans.javaee.LifecycleCallbackType;
 import org.apache.geronimo.xbeans.javaee.MessageDestinationRefType;
 import org.apache.geronimo.xbeans.javaee.MessageDrivenBeanType;
+import org.apache.geronimo.xbeans.javaee.PersistenceContextRefType;
+import org.apache.geronimo.xbeans.javaee.PersistenceUnitRefType;
 import org.apache.geronimo.xbeans.javaee.ResourceEnvRefType;
 import org.apache.geronimo.xbeans.javaee.ResourceRefType;
 import org.apache.geronimo.xbeans.javaee.ServiceRefType;
@@ -149,6 +151,21 @@
         return delegate.addPreDestroy();
     }
 
+    public PersistenceContextRefType[] getPersistenceContextRefArray() {
+        return delegate.getPersistenceContextRefArray();
+    }
+
+    public PersistenceContextRefType addNewPersistenceContextRef() {
+        return delegate.addNewPersistenceContextRef();
+    }
+
+    public PersistenceUnitRefType[] getPersistenceUnitRefArray() {
+        return delegate.getPersistenceUnitRefArray();
+    }
+
+    public PersistenceUnitRefType addNewPersistenceUnitRef() {
+        return delegate.addNewPersistenceUnitRef();
+    }
 
     /**
      * ejbJar getter
@@ -286,6 +303,26 @@
         public LifecycleCallbackType addPreDestroy() {
             return bean.addNewPreDestroy();
         }
+
+
+        public PersistenceContextRefType[] getPersistenceContextRefArray() {
+            return bean.getPersistenceContextRefArray();
+        }
+
+
+        public PersistenceContextRefType addNewPersistenceContextRef() {
+            return bean.addNewPersistenceContextRef();
+        }
+
+
+        public PersistenceUnitRefType[] getPersistenceUnitRefArray() {
+            return bean.getPersistenceUnitRefArray();
+        }
+
+
+        public PersistenceUnitRefType addNewPersistenceUnitRef() {
+            return bean.addNewPersistenceUnitRef();
+        }
     }
 
     public static class MessageDriveBean implements AnnotatedApp {
@@ -394,6 +431,26 @@
         public LifecycleCallbackType addPreDestroy() {
             return bean.addNewPreDestroy();
         }
+
+
+        public PersistenceContextRefType[] getPersistenceContextRefArray() {
+            return bean.getPersistenceContextRefArray();
+        }
+
+
+        public PersistenceContextRefType addNewPersistenceContextRef() {
+            return bean.addNewPersistenceContextRef();
+        }
+
+
+        public PersistenceUnitRefType[] getPersistenceUnitRefArray() {
+            return bean.getPersistenceUnitRefArray();
+        }
+
+
+        public PersistenceUnitRefType addNewPersistenceUnitRef() {
+            return bean.addNewPersistenceUnitRef();
+        }
     }
 
     public static class SessionBean implements AnnotatedApp {
@@ -501,6 +558,26 @@
 
         public LifecycleCallbackType addPreDestroy() {
             return bean.addNewPreDestroy();
+        }
+
+
+        public PersistenceContextRefType[] getPersistenceContextRefArray() {
+            return bean.getPersistenceContextRefArray();
+        }
+
+
+        public PersistenceContextRefType addNewPersistenceContextRef() {
+            return bean.addNewPersistenceContextRef();
+        }
+
+
+        public PersistenceUnitRefType[] getPersistenceUnitRefArray() {
+            return bean.getPersistenceUnitRefArray();
+        }
+
+
+        public PersistenceUnitRefType addNewPersistenceUnitRef() {
+            return bean.addNewPersistenceUnitRef();
         }
     }
 }

Modified: geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/AnnotatedWebApp.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/AnnotatedWebApp.java?view=diff&rev=524702&r1=524701&r2=524702
==============================================================================
--- geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/AnnotatedWebApp.java
(original)
+++ geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/AnnotatedWebApp.java
Sun Apr  1 16:18:38 2007
@@ -25,12 +25,14 @@
 import org.apache.geronimo.xbeans.javaee.EjbLocalRefType;
 import org.apache.geronimo.xbeans.javaee.EjbRefType;
 import org.apache.geronimo.xbeans.javaee.EnvEntryType;
+import org.apache.geronimo.xbeans.javaee.LifecycleCallbackType;
 import org.apache.geronimo.xbeans.javaee.MessageDestinationRefType;
+import org.apache.geronimo.xbeans.javaee.PersistenceContextRefType;
+import org.apache.geronimo.xbeans.javaee.PersistenceUnitRefType;
 import org.apache.geronimo.xbeans.javaee.ResourceEnvRefType;
 import org.apache.geronimo.xbeans.javaee.ResourceRefType;
 import org.apache.geronimo.xbeans.javaee.ServiceRefType;
 import org.apache.geronimo.xbeans.javaee.WebAppType;
-import org.apache.geronimo.xbeans.javaee.LifecycleCallbackType;
 
 /**
  * Wrapper class to encapsulate the WebAppType class with an interface that the various
@@ -178,5 +180,21 @@
 
     public LifecycleCallbackType addPreDestroy() {
         return webApp.addNewPreDestroy();
+    }
+
+    public PersistenceContextRefType[] getPersistenceContextRefArray() {
+        return webApp.getPersistenceContextRefArray();
+    }
+
+    public PersistenceContextRefType addNewPersistenceContextRef() {
+        return webApp.addNewPersistenceContextRef();
+    }
+
+    public PersistenceUnitRefType[] getPersistenceUnitRefArray() {
+        return webApp.getPersistenceUnitRefArray();
+    }
+
+    public PersistenceUnitRefType addNewPersistenceUnitRef() {
+        return webApp.addNewPersistenceUnitRef();
     }
 }

Added: geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/PersistenceContextAnnotationHelper.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/PersistenceContextAnnotationHelper.java?view=auto&rev=524702
==============================================================================
--- geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/PersistenceContextAnnotationHelper.java
(added)
+++ geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/PersistenceContextAnnotationHelper.java
Sun Apr  1 16:18:38 2007
@@ -0,0 +1,275 @@
+/**
+ * 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.j2ee.deployment.annotation;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceContexts;
+import javax.persistence.PersistenceContextType;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.common.DeploymentException;
+import org.apache.geronimo.xbeans.javaee.DescriptionType;
+import org.apache.geronimo.xbeans.javaee.FullyQualifiedClassType;
+import org.apache.geronimo.xbeans.javaee.InjectionTargetType;
+import org.apache.geronimo.xbeans.javaee.JndiNameType;
+import org.apache.geronimo.xbeans.javaee.PersistenceContextRefType;
+import org.apache.geronimo.xbeans.javaee.PersistenceContextTypeType;
+import org.apache.geronimo.xbeans.javaee.PropertyType;
+import org.apache.geronimo.xbeans.javaee.XsdAnyURIType;
+import org.apache.xbean.finder.ClassFinder;
+
+
+/**
+ * Static helper class used to encapsulate all the functions related to the translation of
+ * <strong>@PersistenceContext</strong> and <strong>@PersistenceContexts</strong>
annotations to deployment
+ * descriptor tags. The PersistenceContextAnnotationHelper class can be used as part of the
deployment of
+ * a module into the Geronimo server. It performs the following major functions:
+ * <p/>
+ * <ol>
+ * <li>Translates annotations into corresponding deployment descriptor elements (so
that the
+ * actual deployment descriptor in the module can be updated or even created if necessary)
+ * </ol>
+ * <p/>
+ * <p><strong>Note(s):</strong>
+ * <ul>
+ * <li>The user is responsible for invoking change to metadata-complete
+ * <li>This helper class will validate any changes it makes to the deployment descriptor.
An
+ * exception will be thrown if it fails to parse
+ * </ul>
+ * <p/>
+ * <p><strong>Remaining ToDo(s):</strong>
+ * <ul>
+ * <li>None
+ * </ul>
+ *
+ * @version $Rev $Date
+ * @since 04-2007
+ */
+public final class PersistenceContextAnnotationHelper extends AnnotationHelper {
+
+    // Private instance variables
+    private static final Log log = LogFactory.getLog(PersistenceContextAnnotationHelper.class);
+
+    // Private constructor to prevent instantiation
+    private PersistenceContextAnnotationHelper() {
+    }
+
+    /**
+     * Update the deployment descriptor from the PersistenceContext and PersistenceContexts
annotations
+     *
+     * @param annotatedApp Access to the spec dd
+     * @param classFinder Access to the classes of interest
+     * @throws DeploymentException if parsing or validation error
+     */
+    public static void processAnnotations(AnnotatedApp annotatedApp, ClassFinder classFinder)
throws DeploymentException {
+        if (annotatedApp != null) {
+            if (classFinder.isAnnotationPresent(PersistenceContexts.class)) {
+                processPersistenceContexts(annotatedApp, classFinder);
+            }
+            if (classFinder.isAnnotationPresent(PersistenceContext.class)) {
+                processPersistenceContext(annotatedApp, classFinder);
+            }
+        }
+    }
+
+
+    /**
+     * Process annotations
+     *
+     * @param annotatedApp Access to the spec dd
+     * @param classFinder Access to the classes of interest
+     * @throws DeploymentException if parsing or validation error
+     */
+    private static void processPersistenceContext(AnnotatedApp annotatedApp, ClassFinder
classFinder) throws DeploymentException {
+        log.debug("processPersistenceContext(): Entry: AnnotatedApp: " + annotatedApp.toString());
+
+        List<Class> classeswithPersistenceContext = classFinder.findAnnotatedClasses(PersistenceContext.class);
+        List<Method> methodswithPersistenceContext = classFinder.findAnnotatedMethods(PersistenceContext.class);
+        List<Field> fieldswithPersistenceContext = classFinder.findAnnotatedFields(PersistenceContext.class);
+
+        // Class-level annotation
+        for (Class cls : classeswithPersistenceContext) {
+            PersistenceContext persistenceContext = (PersistenceContext) cls.getAnnotation(PersistenceContext.class);
+            if (persistenceContext != null) {
+                addPersistenceContext(annotatedApp, persistenceContext, cls, null, null);
+            }
+        }
+
+        // Method-level annotation
+        for (Method method : methodswithPersistenceContext) {
+            PersistenceContext persistenceContext = method.getAnnotation(PersistenceContext.class);
+            if (persistenceContext != null) {
+                addPersistenceContext(annotatedApp, persistenceContext, null, method, null);
+            }
+        }
+
+        // Field-level annotation
+        for (Field field : fieldswithPersistenceContext) {
+            PersistenceContext persistenceContext = field.getAnnotation(PersistenceContext.class);
+            if (persistenceContext != null) {
+                addPersistenceContext(annotatedApp, persistenceContext, null, null, field);
+            }
+        }
+
+        // Validate deployment descriptor to ensure it's still okay
+        validateDD(annotatedApp);
+
+        log.debug("processPersistenceContext(): Exit: AnnotatedApp: " + annotatedApp.toString());
+    }
+
+
+    /**
+     * Process multiple annotations
+     *
+     * @param annotatedApp Access to the spec dd
+     * @param classFinder Access to the classes of interest
+     * @throws DeploymentException if parsing or validation error
+     */
+    private static void processPersistenceContexts(AnnotatedApp annotatedApp, ClassFinder
classFinder) throws DeploymentException {
+        log.debug("processPersistenceContexts(): Entry");
+
+        List<Class> classeswithPersistenceContexts = classFinder.findAnnotatedClasses(PersistenceContexts.class);
+
+        // Class-level annotation(s)
+        List<PersistenceContext> persistenceContextList = new ArrayList<PersistenceContext>();
+        for (Class cls : classeswithPersistenceContexts) {
+            PersistenceContexts persistenceContexts = (PersistenceContexts) cls.getAnnotation(PersistenceContexts.class);
+            if (persistenceContexts != null) {
+                persistenceContextList.addAll(Arrays.asList(persistenceContexts.value()));
+            }
+            for (PersistenceContext persistenceContext : persistenceContextList) {
+                addPersistenceContext(annotatedApp, persistenceContext, cls, null, null);
+            }
+            persistenceContextList.clear();
+        }
+
+        log.debug("processPersistenceContexts(): Exit");
+    }
+
+
+    /**
+     * Add @PersistenceContext and @PersistenceContexts annotations to the deployment descriptor.
XMLBeans are used to
+     * read and manipulate the deployment descriptor as necessary. The PersistenceContext
annotation(s) will be
+     * converted to one of the following deployment descriptors:
+     *
+     * <ol>
+     *      <li><persistence-context-ref> -- Describes a single container-managed
entity manager
+     * </ol>
+     *
+     * <p><strong>Note(s):</strong>
+     * <ul>
+     *      <li>The deployment descriptor is the authoritative source so this method
ensures that
+     *          existing elements in it are not overwritten by annoations
+     * </ul>
+     *
+     * @param annotation @PersistenceContext annotation
+     * @param cls        Class name with the @PersistenceContext annoation
+     * @param method     Method name with the @PersistenceContext annoation
+     * @param field      Field name with the @PersistenceContext annoation
+     * @param annotatedApp  Access to the specc dd
+     */
+    private static void addPersistenceContext(AnnotatedApp annotatedApp, PersistenceContext
annotation, Class cls, Method method, Field field) {
+        log.debug("addPersistenceContext( [annotatedApp] " + annotatedApp.toString() + ","
+ '\n' +
+                "[annotation] " + annotation.toString() + "," + '\n' +
+                "[cls] " + (cls != null ? cls.getName() : null) + "," + '\n' +
+                "[method] " + (method != null ? method.getName() : null) + "," + '\n' +
+                "[field] " + (field != null ? field.getName() : null) + " ): Entry");
+
+        //------------------------------------------------------------------------------------------
+        // PersistenceContextRef name:
+        // -- When annotation is applied on a class:    Name must be provided (cannot be
inferred)
+        // -- When annotation is applied on a method:   Name is JavaBeans property name qualified
+        //                                              by the class (or as provided on the
+        //                                              annotation)
+        // -- When annotation is applied on a field:    Name is the field name qualified
by the
+        //                                              class (or as provided on the annotation)
+        //------------------------------------------------------------------------------------------
+        String persistenceContextRefName = annotation.name();
+        if (persistenceContextRefName.equals("")) {
+            if (method != null) {
+                StringBuilder stringBuilder = new StringBuilder(method.getName().substring(3));
+                stringBuilder.setCharAt(0, Character.toLowerCase(stringBuilder.charAt(0)));
+                persistenceContextRefName = method.getDeclaringClass().getName() + "/" +
stringBuilder.toString();
+            } else if (field != null) {
+                persistenceContextRefName = field.getDeclaringClass().getName() + "/" + field.getName();
+            }
+        }
+        log.debug("addPersistenceContext(): PersistenceContextRefName: " + persistenceContextRefName);
+
+        // If there is already xml for the persistence unit ref, just add injection targets
and return.
+        PersistenceContextRefType[] persistenceContextRefs = annotatedApp.getPersistenceContextRefArray();
+        for (PersistenceContextRefType persistenceContextRef : persistenceContextRefs) {
+            if (persistenceContextRef.getPersistenceContextRefName().getStringValue().trim().equals(persistenceContextRefName))
{
+                if (method != null || field != null) {
+                    InjectionTargetType[] targets = persistenceContextRef.getInjectionTargetArray();
+                    if (!hasTarget(method, field, targets)) {
+                        configureInjectionTarget(persistenceContextRef.addNewInjectionTarget(),
method, field);
+                    }
+                }
+                return;
+            }
+        }
+
+        // Doesn't exist in deployment descriptor -- add new
+        PersistenceContextRefType persistenceContextRef = annotatedApp.addNewPersistenceContextRef();
+
+        //------------------------------------------------------------------------------
+        // <persistence-context-ref> required elements:
+        //------------------------------------------------------------------------------
+
+        // persistence-context-ref-name
+        JndiNameType unitRefName = persistenceContextRef.addNewPersistenceContextRefName();
+        unitRefName.setStringValue(persistenceContextRefName);
+
+        //------------------------------------------------------------------------------
+        // <persistence-context-ref> optional elements:
+        //------------------------------------------------------------------------------
+
+        // persistence-unit-name
+        String unitNameAnnotation = annotation.unitName();
+        if (!unitNameAnnotation.equals("")) {
+            org.apache.geronimo.xbeans.javaee.String persistenceUnitName = persistenceContextRef.addNewPersistenceUnitName();
+            persistenceUnitName.setStringValue(unitNameAnnotation);
+        }
+
+        // persistence-context-type
+        if (annotation.type() == PersistenceContextType.TRANSACTION) {
+            PersistenceContextTypeType persistenceContextType = persistenceContextRef.addNewPersistenceContextType();
+            persistenceContextType.setStringValue("Transaction");
+            persistenceContextRef.setPersistenceContextType(persistenceContextType);
+        } else if (annotation.type() == PersistenceContextType.EXTENDED) {
+            PersistenceContextTypeType persistenceContextType = persistenceContextRef.addNewPersistenceContextType();
+            persistenceContextType.setStringValue("Extended");
+            persistenceContextRef.setPersistenceContextType(persistenceContextType);
+        }
+
+        // injection targets
+        if (method != null || field != null) {
+            configureInjectionTarget(persistenceContextRef.addNewInjectionTarget(), method,
field);
+        }
+
+    }
+
+}

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

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

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

Added: geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/PersistenceUnitAnnotationHelper.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/PersistenceUnitAnnotationHelper.java?view=auto&rev=524702
==============================================================================
--- geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/PersistenceUnitAnnotationHelper.java
(added)
+++ geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/annotation/PersistenceUnitAnnotationHelper.java
Sun Apr  1 16:18:38 2007
@@ -0,0 +1,262 @@
+/**
+ * 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.j2ee.deployment.annotation;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.persistence.PersistenceUnit;
+import javax.persistence.PersistenceUnits;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.common.DeploymentException;
+import org.apache.geronimo.xbeans.javaee.DescriptionType;
+import org.apache.geronimo.xbeans.javaee.FullyQualifiedClassType;
+import org.apache.geronimo.xbeans.javaee.InjectionTargetType;
+import org.apache.geronimo.xbeans.javaee.JndiNameType;
+import org.apache.geronimo.xbeans.javaee.PersistenceUnitRefType;
+import org.apache.geronimo.xbeans.javaee.XsdAnyURIType;
+import org.apache.xbean.finder.ClassFinder;
+
+
+/**
+ * Static helper class used to encapsulate all the functions related to the translation of
+ * <strong>@PersistenceUnit</strong> and <strong>@PersistenceUnits</strong>
annotations to deployment
+ * descriptor tags. The PersistenceUnitAnnotationHelper class can be used as part of the
deployment of
+ * a module into the Geronimo server. It performs the following major functions:
+ * <p/>
+ * <ol>
+ * <li>Translates annotations into corresponding deployment descriptor elements (so
that the
+ * actual deployment descriptor in the module can be updated or even created if necessary)
+ * </ol>
+ * <p/>
+ * <p><strong>Note(s):</strong>
+ * <ul>
+ * <li>The user is responsible for invoking change to metadata-complete
+ * <li>This helper class will validate any changes it makes to the deployment descriptor.
An
+ * exception will be thrown if it fails to parse
+ * </ul>
+ * <p/>
+ * <p><strong>Remaining ToDo(s):</strong>
+ * <ul>
+ * <li>None
+ * </ul>
+ *
+ * @version $Rev $Date
+ * @since 04-2007
+ */
+public final class PersistenceUnitAnnotationHelper extends AnnotationHelper {
+
+    // Private instance variables
+    private static final Log log = LogFactory.getLog(PersistenceUnitAnnotationHelper.class);
+
+    // Private constructor to prevent instantiation
+    private PersistenceUnitAnnotationHelper() {
+    }
+
+    /**
+     * Update the deployment descriptor from the PersistenceUnit and PersistenceUnits annotations
+     *
+     * @param annotatedApp Access to the spec dd
+     * @param classFinder Access to the classes of interest
+     * @throws DeploymentException if parsing or validation error
+     */
+    public static void processAnnotations(AnnotatedApp annotatedApp, ClassFinder classFinder)
throws DeploymentException {
+        if (annotatedApp != null) {
+            if (classFinder.isAnnotationPresent(PersistenceUnits.class)) {
+                processPersistenceUnits(annotatedApp, classFinder);
+            }
+            if (classFinder.isAnnotationPresent(PersistenceUnit.class)) {
+                processPersistenceUnit(annotatedApp, classFinder);
+            }
+        }
+    }
+
+
+    /**
+     * Process annotations
+     *
+     * @param annotatedApp Access to the spec dd
+     * @param classFinder Access to the classes of interest
+     * @throws DeploymentException if parsing or validation error
+     */
+    private static void processPersistenceUnit(AnnotatedApp annotatedApp, ClassFinder classFinder)
throws DeploymentException {
+        log.debug("processPersistenceUnit(): Entry: AnnotatedApp: " + annotatedApp.toString());
+
+        List<Class> classeswithPersistenceUnit = classFinder.findAnnotatedClasses(PersistenceUnit.class);
+        List<Method> methodswithPersistenceUnit = classFinder.findAnnotatedMethods(PersistenceUnit.class);
+        List<Field> fieldswithPersistenceUnit = classFinder.findAnnotatedFields(PersistenceUnit.class);
+
+        // Class-level annotation
+        for (Class cls : classeswithPersistenceUnit) {
+            PersistenceUnit persistenceUnit = (PersistenceUnit) cls.getAnnotation(PersistenceUnit.class);
+            if (persistenceUnit != null) {
+                addPersistenceUnit(annotatedApp, persistenceUnit, cls, null, null);
+            }
+        }
+
+        // Method-level annotation
+        for (Method method : methodswithPersistenceUnit) {
+            PersistenceUnit persistenceUnit = method.getAnnotation(PersistenceUnit.class);
+            if (persistenceUnit != null) {
+                addPersistenceUnit(annotatedApp, persistenceUnit, null, method, null);
+            }
+        }
+
+        // Field-level annotation
+        for (Field field : fieldswithPersistenceUnit) {
+            PersistenceUnit persistenceUnit = field.getAnnotation(PersistenceUnit.class);
+            if (persistenceUnit != null) {
+                addPersistenceUnit(annotatedApp, persistenceUnit, null, null, field);
+            }
+        }
+
+        // Validate deployment descriptor to ensure it's still okay
+        validateDD(annotatedApp);
+
+        log.debug("processPersistenceUnit(): Exit: AnnotatedApp: " + annotatedApp.toString());
+    }
+
+
+    /**
+     * Process multiple annotations
+     *
+     * @param annotatedApp Access to the spec dd
+     * @param classFinder Access to the classes of interest
+     * @throws DeploymentException if parsing or validation error
+     */
+    private static void processPersistenceUnits(AnnotatedApp annotatedApp, ClassFinder classFinder)
throws DeploymentException {
+        log.debug("processPersistenceUnits(): Entry");
+
+        List<Class> classeswithPersistenceUnits = classFinder.findAnnotatedClasses(PersistenceUnits.class);
+
+        // Class-level annotation(s)
+        List<PersistenceUnit> persistenceUnitList = new ArrayList<PersistenceUnit>();
+        for (Class cls : classeswithPersistenceUnits) {
+            PersistenceUnits persistenceUnits = (PersistenceUnits) cls.getAnnotation(PersistenceUnits.class);
+            if (persistenceUnits != null) {
+                persistenceUnitList.addAll(Arrays.asList(persistenceUnits.value()));
+            }
+            for (PersistenceUnit persistenceUnit : persistenceUnitList) {
+                addPersistenceUnit(annotatedApp, persistenceUnit, cls, null, null);
+            }
+            persistenceUnitList.clear();
+        }
+
+        log.debug("processPersistenceUnits(): Exit");
+    }
+
+
+    /**
+     * Add @PersistenceUnit and @PersistenceUnits annotations to the deployment descriptor.
XMLBeans are used to
+     * read and manipulate the deployment descriptor as necessary. The PersistenceUnit annotation(s)
will be
+     * converted to one of the following deployment descriptors:
+     *
+     * <ol>
+     *      <li><persistence-unit-ref> -- Describes a single entity manager factory
reference for the
+     *          persistence unit
+     * </ol>
+     *
+     * <p><strong>Note(s):</strong>
+     * <ul>
+     *      <li>The deployment descriptor is the authoritative source so this method
ensures that
+     *          existing elements in it are not overwritten by annoations
+     * </ul>
+     *
+     * @param annotation @PersistenceUnit annotation
+     * @param cls        Class name with the @PersistenceUnit annoation
+     * @param method     Method name with the @PersistenceUnit annoation
+     * @param field      Field name with the @PersistenceUnit annoation
+     * @param annotatedApp  Access to the specc dd
+     */
+    private static void addPersistenceUnit(AnnotatedApp annotatedApp, PersistenceUnit annotation,
Class cls, Method method, Field field) {
+        log.debug("addPersistenceUnit( [annotatedApp] " + annotatedApp.toString() + "," +
'\n' +
+                "[annotation] " + annotation.toString() + "," + '\n' +
+                "[cls] " + (cls != null ? cls.getName() : null) + "," + '\n' +
+                "[method] " + (method != null ? method.getName() : null) + "," + '\n' +
+                "[field] " + (field != null ? field.getName() : null) + " ): Entry");
+
+        //------------------------------------------------------------------------------------------
+        // PersistenceUnitRef name:
+        // -- When annotation is applied on a class:    Name must be provided (cannot be
inferred)
+        // -- When annotation is applied on a method:   Name is JavaBeans property name qualified
+        //                                              by the class (or as provided on the
+        //                                              annotation)
+        // -- When annotation is applied on a field:    Name is the field name qualified
by the
+        //                                              class (or as provided on the annotation)
+        //------------------------------------------------------------------------------------------
+        String persistenceUnitRefName = annotation.name();
+        if (persistenceUnitRefName.equals("")) {
+            if (method != null) {
+                StringBuilder stringBuilder = new StringBuilder(method.getName().substring(3));
+                stringBuilder.setCharAt(0, Character.toLowerCase(stringBuilder.charAt(0)));
+                persistenceUnitRefName = method.getDeclaringClass().getName() + "/" + stringBuilder.toString();
+            } else if (field != null) {
+                persistenceUnitRefName = field.getDeclaringClass().getName() + "/" + field.getName();
+            }
+        }
+        log.debug("addPersistenceUnit(): persistenceUnitRefName: " + persistenceUnitRefName);
+
+        // If there is already xml for the persistence unit ref, just add injection targets
and return.
+        PersistenceUnitRefType[] persistenceUnitRefs = annotatedApp.getPersistenceUnitRefArray();
+        for (PersistenceUnitRefType persistenceUnitRef : persistenceUnitRefs) {
+            if (persistenceUnitRef.getPersistenceUnitRefName().getStringValue().trim().equals(persistenceUnitRefName))
{
+                if (method != null || field != null) {
+                    InjectionTargetType[] targets = persistenceUnitRef.getInjectionTargetArray();
+                    if (!hasTarget(method, field, targets)) {
+                        configureInjectionTarget(persistenceUnitRef.addNewInjectionTarget(),
method, field);
+                    }
+                }
+                return;
+            }
+        }
+
+        // Doesn't exist in deployment descriptor -- add new
+        PersistenceUnitRefType persistenceUnitRef = annotatedApp.addNewPersistenceUnitRef();
+
+        //------------------------------------------------------------------------------
+        // <persistence-unit-ref> required elements:
+        //------------------------------------------------------------------------------
+
+        // persistence-unit-ref-name
+        JndiNameType unitRefName = persistenceUnitRef.addNewPersistenceUnitRefName();
+        unitRefName.setStringValue(persistenceUnitRefName);
+
+        //------------------------------------------------------------------------------
+        // <persistence-unit-ref> optional elements:
+        //------------------------------------------------------------------------------
+
+        // persistence-unit-name
+        String unitNameAnnotation = annotation.unitName();
+        if (!unitNameAnnotation.equals("")) {
+            org.apache.geronimo.xbeans.javaee.String persistenceUnitName = persistenceUnitRef.addNewPersistenceUnitName();
+            persistenceUnitName.setStringValue(unitNameAnnotation);
+        }
+
+        // injection targets
+        if (method != null || field != null) {
+            configureInjectionTarget(persistenceUnitRef.addNewInjectionTarget(), method,
field);
+        }
+
+    }
+
+}

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

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

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

Modified: geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceContextRefBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceContextRefBuilder.java?view=diff&rev=524702&r1=524701&r2=524702
==============================================================================
--- geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceContextRefBuilder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceContextRefBuilder.java
Sun Apr  1 16:18:38 2007
@@ -30,6 +30,7 @@
 import org.apache.geronimo.gbean.AbstractNameQuery;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.geronimo.j2ee.deployment.annotation.PersistenceContextAnnotationHelper;
 import org.apache.geronimo.j2ee.deployment.Module;
 import org.apache.geronimo.j2ee.deployment.NamingBuilder;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
@@ -204,18 +205,8 @@
     }
 
     private void processAnnotations(Module module) throws DeploymentException {
-
         // Process all the annotations for this naming builder type
-//      if (PersistenceContextRefAnnotationHelper.annotationsPresent(module.getClassFinder()))
-//              { try {
-//              PersistenceContextRefAnnotationHelper.processAnnotations(module.getAnnotatedApp(),
-//              module.getClassFinder());
-//          }
-//          catch (Exception e) {
-//              log.warn("Unable to process @PersistenceContextRef annotations for module"
+
-//              module.getName(), e);
-//          }
-//      }
+        PersistenceContextAnnotationHelper.processAnnotations(module.getAnnotatedApp(), module.getClassFinder());
     }
 
     public QNameSet getSpecQNameSet() {

Modified: geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitRefBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitRefBuilder.java?view=diff&rev=524702&r1=524701&r2=524702
==============================================================================
--- geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitRefBuilder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitRefBuilder.java
Sun Apr  1 16:18:38 2007
@@ -29,6 +29,7 @@
 import org.apache.geronimo.gbean.AbstractNameQuery;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.geronimo.j2ee.deployment.annotation.PersistenceUnitAnnotationHelper;
 import org.apache.geronimo.j2ee.deployment.Module;
 import org.apache.geronimo.j2ee.deployment.NamingBuilder;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
@@ -154,18 +155,8 @@
     }
 
     private void processAnnotations(Module module) throws DeploymentException {
-
         // Process all the annotations for this naming builder type
-//      if (PersistenceUnitRefAnnotationHelper.annotationsPresent(module.getClassFinder()))
{
-//          try {
-//              PersistenceUnitRefAnnotationHelper.processAnnotations(module.getAnnotatedApp(),
-//              module.getClassFinder());
-//          }
-//          catch (Exception e) {
-//              log.warn("Unable to process @PersistenceUnitRef annotations for module" +
-//              module.getName(), e);
-//          }
-//      }
+        PersistenceUnitAnnotationHelper.processAnnotations(module.getAnnotatedApp(), module.getClassFinder());
     }
 
     private AbstractNameQuery findPersistenceUnit(GerPersistenceUnitRefType gerPersistenceUnitRef)
{



Mime
View raw message