cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r428214 - in /incubator/cayenne/main/trunk/core/cayenne-jpa/src: main/java/org/apache/cayenne/jpa/conf/ test/java/org/apache/cayenne/jpa/conf/
Date Thu, 03 Aug 2006 02:39:46 GMT
Author: aadamchik
Date: Wed Aug  2 19:39:45 2006
New Revision: 428214

URL: http://svn.apache.org/viewvc?rev=428214&view=rev
Log:
fixing more annotation processors

Added:
    incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/conf/MockAnnotatedBeanOrdering.java
Modified:
    incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/AnnotationProcessorFactory.java
    incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/ClassAnnotationProcessorFactory.java
    incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/EntityMapAnnotationLoader.java
    incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/MemberAnnotationProcessorFactory.java
    incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/conf/EntityMapAnnotationLoaderTest.java

Modified: incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/AnnotationProcessorFactory.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/AnnotationProcessorFactory.java?rev=428214&r1=428213&r2=428214&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/AnnotationProcessorFactory.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/AnnotationProcessorFactory.java
Wed Aug  2 19:39:45 2006
@@ -150,7 +150,6 @@
 
             try {
                 return (AnnotationProcessor) processorClass.newInstance();
-
             }
             catch (Exception e) {
                 return NOOP_PROCESSOR;

Modified: incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/ClassAnnotationProcessorFactory.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/ClassAnnotationProcessorFactory.java?rev=428214&r1=428213&r2=428214&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/ClassAnnotationProcessorFactory.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/ClassAnnotationProcessorFactory.java
Wed Aug  2 19:39:45 2006
@@ -43,6 +43,7 @@
 import javax.persistence.TableGenerator;
 
 import org.apache.cayenne.jpa.map.JpaAttributeOverride;
+import org.apache.cayenne.jpa.map.JpaAttributes;
 import org.apache.cayenne.jpa.map.JpaDiscriminatorColumn;
 import org.apache.cayenne.jpa.map.JpaEmbeddable;
 import org.apache.cayenne.jpa.map.JpaEntity;
@@ -78,6 +79,7 @@
 
             JpaEntity entity = new JpaEntity();
             entity.setClassName(((Class) element).getName());
+            entity.setAttributes(new JpaAttributes());
 
             if (!Util.isEmptyString(entityAnnotation.name())) {
                 entity.setName(entityAnnotation.name());
@@ -103,6 +105,7 @@
 
             JpaEmbeddable embeddable = new JpaEmbeddable();
             embeddable.setClassName(((Class) element).getName());
+            embeddable.setAttributes(new JpaAttributes());
             context.push(embeddable);
         }
 
@@ -123,6 +126,7 @@
 
             JpaMappedSuperclass superclass = new JpaMappedSuperclass();
             superclass.setClassName(((Class) element).getName());
+            superclass.setAttributes(new JpaAttributes());
             context.push(superclass);
         }
 

Modified: incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/EntityMapAnnotationLoader.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/EntityMapAnnotationLoader.java?rev=428214&r1=428213&r2=428214&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/EntityMapAnnotationLoader.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/EntityMapAnnotationLoader.java
Wed Aug  2 19:39:45 2006
@@ -31,19 +31,34 @@
 import java.util.LinkedList;
 import java.util.Map;
 
+import javax.persistence.AssociationOverride;
+import javax.persistence.AttributeOverride;
+import javax.persistence.Basic;
+import javax.persistence.Column;
 import javax.persistence.Embeddable;
+import javax.persistence.Embedded;
 import javax.persistence.EmbeddedId;
 import javax.persistence.Entity;
 import javax.persistence.EntityListeners;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
 import javax.persistence.Id;
+import javax.persistence.Lob;
+import javax.persistence.ManyToMany;
+import javax.persistence.ManyToOne;
 import javax.persistence.MappedSuperclass;
 import javax.persistence.NamedNativeQueries;
 import javax.persistence.NamedNativeQuery;
 import javax.persistence.NamedQueries;
 import javax.persistence.NamedQuery;
+import javax.persistence.OneToMany;
+import javax.persistence.OneToOne;
 import javax.persistence.SequenceGenerator;
 import javax.persistence.SqlResultSetMapping;
 import javax.persistence.TableGenerator;
+import javax.persistence.Temporal;
+import javax.persistence.Transient;
+import javax.persistence.Version;
 
 import org.apache.cayenne.jpa.JpaProviderException;
 import org.apache.cayenne.jpa.map.JpaAbstractEntity;
@@ -90,11 +105,35 @@
 
         MEMBER_ANNOTATION_ORDERING_WEIGHTS = new HashMap<String, Integer>();
 
-        // direct entity children annotations
-        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(EmbeddedId.class.getName(), 1);
+        // first level of member annotations - annotations representing different types of
+        // attributes
         MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(Id.class.getName(), 1);
+        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(Basic.class.getName(), 1);
+        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(EmbeddedId.class.getName(), 1);
+        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(Version.class.getName(), 1);
+        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(ManyToOne.class.getName(), 1);
+        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(OneToMany.class.getName(), 1);
+        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(OneToOne.class.getName(), 1);
+        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(ManyToMany.class.getName(), 1);
+        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(Embedded.class.getName(), 1);
+        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(Transient.class.getName(), 1);
+
+        // second level of member annotations - details implying one of the attributes
+        // above
+        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(GeneratedValue.class.getName(), 2);
+        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(Temporal.class.getName(), 2);
+        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(TableGenerator.class.getName(), 2);
+        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(SequenceGenerator.class.getName(), 2);
+
+        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(AttributeOverride.class.getName(), 2);
+        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(AssociationOverride.class.getName(), 2);
+
+        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(Lob.class.getName(), 2);
+        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(Temporal.class.getName(), 2);
+        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(Enumerated.class.getName(), 2);
 
-        // 'attribute' is implied...
+        // third-level
+        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(Column.class.getName(), 3);
     }
 
     protected EntityMapLoaderContext context;

Modified: incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/MemberAnnotationProcessorFactory.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/MemberAnnotationProcessorFactory.java?rev=428214&r1=428213&r2=428214&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/MemberAnnotationProcessorFactory.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/MemberAnnotationProcessorFactory.java
Wed Aug  2 19:39:45 2006
@@ -20,26 +20,23 @@
 package org.apache.cayenne.jpa.conf;
 
 import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Member;
 
-import javax.persistence.AttributeOverride;
-import javax.persistence.AttributeOverrides;
 import javax.persistence.Basic;
-import javax.persistence.Column;
-import javax.persistence.EmbeddedId;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
 import javax.persistence.GeneratedValue;
 import javax.persistence.ManyToMany;
 import javax.persistence.ManyToOne;
 import javax.persistence.OneToMany;
 import javax.persistence.OneToOne;
 import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
 
-import org.apache.cayenne.jpa.map.JpaAbstractEntity;
-import org.apache.cayenne.jpa.map.JpaAttributeOverride;
-import org.apache.cayenne.jpa.map.JpaAttributes;
+import org.apache.cayenne.jpa.map.JpaAttribute;
 import org.apache.cayenne.jpa.map.JpaBasic;
-import org.apache.cayenne.jpa.map.JpaColumn;
+import org.apache.cayenne.jpa.map.JpaEmbedded;
 import org.apache.cayenne.jpa.map.JpaEmbeddedId;
-import org.apache.cayenne.jpa.map.JpaEntity;
 import org.apache.cayenne.jpa.map.JpaGeneratedValue;
 import org.apache.cayenne.jpa.map.JpaId;
 import org.apache.cayenne.jpa.map.JpaManagedClass;
@@ -57,7 +54,8 @@
  */
 class MemberAnnotationProcessorFactory extends AnnotationProcessorFactory {
 
-    abstract static class AbstractChildProcessor implements AnnotationProcessor {
+    // superclass of the top-level member annotations
+    abstract static class L1AnnotationProcessor implements AnnotationProcessor {
 
         public void onStartElement(
                 AnnotatedElement element,
@@ -65,19 +63,14 @@
 
             Object parent = context.peek();
 
-            if (parent instanceof JpaId) {
-                onId((JpaId) parent, element, context);
+            if (parent instanceof JpaManagedClass) {
+                onManagedClass((JpaManagedClass) parent, element, context);
             }
-            else if (parent instanceof JpaEmbeddedId) {
-                onEmbeddedId((JpaEmbeddedId) parent, element, context);
+            else if (parent instanceof JpaAttribute) {
+                onAttribute((JpaAttribute) parent, element, context);
             }
-            else if (parent instanceof JpaManagedClass) {
-                JpaManagedClass managedClass = (JpaManagedClass) parent;
-                if (managedClass.getAttributes() == null) {
-                    managedClass.setAttributes(new JpaAttributes());
-                }
-
-                onAttributes(managedClass.getAttributes(), element, context);
+            else {
+                recordUnsupportedAnnotation(element, context);
             }
         }
 
@@ -88,25 +81,22 @@
         public void onFinishElement(
                 AnnotatedElement element,
                 AnnotationProcessorStack context) {
-
         }
 
-        void onEmbeddedId(
-                JpaEmbeddedId id,
+        void onManagedClass(
+                JpaManagedClass managedClass,
                 AnnotatedElement element,
                 AnnotationProcessorStack context) {
-            recordUnsupportedAnnotation(element, context);
-        }
-
-        void onId(JpaId id, AnnotatedElement element, AnnotationProcessorStack context) {
-            recordUnsupportedAnnotation(element, context);
+            context.recordConflict(element, AnnotationProcessorFactory
+                    .annotationClass(getClass()), "Unsupported in this place");
         }
 
-        void onAttributes(
-                JpaAttributes attributes,
+        void onAttribute(
+                JpaAttribute attribute,
                 AnnotatedElement element,
                 AnnotationProcessorStack context) {
-            recordUnsupportedAnnotation(element, context);
+            context.recordConflict(element, AnnotationProcessorFactory
+                    .annotationClass(getClass()), "Unsupported in this place");
         }
 
         void recordUnsupportedAnnotation(
@@ -117,107 +107,98 @@
         }
     }
 
-    static final class FlushModeProcessor implements AnnotationProcessor {
+    // superclass of the second-level member annotations
+    abstract static class L2AnnotationProcessor implements AnnotationProcessor {
 
         public void onStartElement(
                 AnnotatedElement element,
                 AnnotationProcessorStack context) {
 
-            // TODO: andrus, 4/23/2006 - where does this annotation belong??
+            JpaAttribute attribute = null;
 
-            context.recordConflict(
-                    element,
-                    EmbeddedId.class,
-                    "FlushMode annotation is not fully defined in the specification");
-        }
+            Object parent = context.peek();
+            if (parent instanceof JpaAttribute) {
+                attribute = (JpaAttribute) parent;
+            }
+            else {
+                attribute = findOrCreateAttribute(element, parent);
+            }
 
-        public void onFinishElement(
-                AnnotatedElement element,
-                AnnotationProcessorStack context) {
+            if (parent != null) {
+                onAttribute(attribute, element, context);
+            }
+            else {
+                recordUnsupportedAnnotation(element, context);
+            }
         }
-    }
 
-    static final class EmbeddedIdProcessor implements AnnotationProcessor {
+        JpaAttribute findOrCreateAttribute(AnnotatedElement element, Object parent) {
 
-        public void onStartElement(
-                AnnotatedElement element,
-                AnnotationProcessorStack context) {
+            JpaBasic basic = null;
 
-            JpaEmbeddedId id = new JpaEmbeddedId();
-
-            Object parent = context.peek();
-            // only JpaEntity and JpaMappedSuperclass can have it
-            if (parent instanceof JpaAbstractEntity) {
-                ((JpaAbstractEntity) parent).getAttributes().setEmbeddedId(id);
-            }
-            else {
-                context.recordConflict(element, AnnotationProcessorFactory
-                        .annotationClass(getClass()), "Unsupported in this place");
+            if (parent instanceof JpaManagedClass) {
+                JpaManagedClass managedClass = (JpaManagedClass) parent;
+                String name = ((Member) element).getName();
+                basic = managedClass.getAttributes().getBasicAttribute(name);
+                if (basic == null) {
+                    basic = new JpaBasic();
+                    basic.setName(name);
+                    managedClass.getAttributes().getBasicAttributes().add(basic);
+                }
             }
 
-            context.push(id);
+            return basic;
         }
 
+        /**
+         * Does nothing by default. Any elements that push themselves on stack in the
+         * start method, must pop the stack here.
+         */
         public void onFinishElement(
                 AnnotatedElement element,
                 AnnotationProcessorStack context) {
-
-            context.pop();
         }
-    }
 
-    static final class IdProcessor implements AnnotationProcessor {
-
-        public void onStartElement(
+        void onAttribute(
+                JpaAttribute attribute,
                 AnnotatedElement element,
                 AnnotationProcessorStack context) {
-
-            JpaId id = new JpaId();
-
-            Object parent = context.peek();
-            if (parent instanceof JpaEntity) {
-                ((JpaEntity) parent).getAttributes().getIds().add(id);
-            }
-            else {
-                context.recordConflict(element, AnnotationProcessorFactory
-                        .annotationClass(getClass()), "Unsupported in this place");
-            }
-
-            context.push(id);
+            context.recordConflict(element, AnnotationProcessorFactory
+                    .annotationClass(getClass()), "Unsupported in this place");
         }
 
-        public void onFinishElement(
+        void recordUnsupportedAnnotation(
                 AnnotatedElement element,
                 AnnotationProcessorStack context) {
-
-            context.pop();
+            context.recordConflict(element, AnnotationProcessorFactory
+                    .annotationClass(getClass()), "Unsupported in this place");
         }
     }
 
-    // ====== Concrete processor classes ========
-
-    static final class AttributeOverrideProcessor extends AbstractChildProcessor {
+    static final class AttributeOverrideProcessor extends L1AnnotationProcessor {
 
         // @Override
         // void onAttribute(
         // JpaAttribute attribute,
         // AnnotatedElement element,
         // AnnotationProcessorStack context) {
+        // AttributeOverride annotation =
+        // element.getAnnotation(AttributeOverride.class);
+        // attribute.getAttributeOverrides().add(new
+        // JpaAttributeOverride(annotation));
+        // }
+        //
+        // @Override
+        // void onEmbeddedId(
+        // JpaEmbeddedId id,
+        // AnnotatedElement element,
+        // AnnotationProcessorStack context) {
         // AttributeOverride annotation = element.getAnnotation(AttributeOverride.class);
-        // attribute.getAttributeOverrides().add(new JpaAttributeOverride(annotation));
+        // id.getAttributeOverrides().add(new JpaAttributeOverride(annotation));
         // }
-
-        @Override
-        void onEmbeddedId(
-                JpaEmbeddedId id,
-                AnnotatedElement element,
-                AnnotationProcessorStack context) {
-            AttributeOverride annotation = element.getAnnotation(AttributeOverride.class);
-            id.getAttributeOverrides().add(new JpaAttributeOverride(annotation));
-        }
     }
 
-    static final class AttributeOverridesProcessor extends AbstractChildProcessor {
+    static final class AttributeOverridesProcessor extends L1AnnotationProcessor {
 
         // @Override
         // void onAttribute(
@@ -233,43 +214,56 @@
         // }
         // }
 
-        @Override
-        void onEmbeddedId(
-                JpaEmbeddedId id,
-                AnnotatedElement element,
-                AnnotationProcessorStack context) {
-            AttributeOverrides annotation = element
-                    .getAnnotation(AttributeOverrides.class);
-
-            for (int i = 0; i < annotation.value().length; i++) {
-                id.getAttributeOverrides().add(
-                        new JpaAttributeOverride(annotation.value()[i]));
-            }
-        }
+        // @Override
+        // void onEmbeddedId(
+        // JpaEmbeddedId id,
+        // AnnotatedElement element,
+        // AnnotationProcessorStack context) {
+        // AttributeOverrides annotation = element
+        // .getAnnotation(AttributeOverrides.class);
+        //
+        // for (int i = 0; i < annotation.value().length; i++) {
+        // id.getAttributeOverrides().add(
+        // new JpaAttributeOverride(annotation.value()[i]));
+        // }
+        // }
     }
 
-    static final class BasicProcessor extends AbstractChildProcessor {
+    static final class BasicProcessor extends L1AnnotationProcessor {
 
         @Override
-        void onAttributes(
-                JpaAttributes attributes,
+        void onManagedClass(
+                JpaManagedClass managedClass,
                 AnnotatedElement element,
                 AnnotationProcessorStack context) {
-
             JpaBasic attribute = new JpaBasic(element.getAnnotation(Basic.class));
-            attributes.getBasicAttributes().add(attribute);
+            managedClass.getAttributes().getBasicAttributes().add(attribute);
             context.push(attribute);
         }
 
         @Override
+        void onAttribute(
+                JpaAttribute attribute,
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+            if (!(attribute instanceof JpaBasic)) {
+                super.onAttribute(attribute, element, context);
+            }
+        }
+
+        @Override
         public void onFinishElement(
                 AnnotatedElement element,
                 AnnotationProcessorStack context) {
-            context.pop();
+
+            Object pop = context.pop();
+            if (!(pop instanceof JpaBasic)) {
+                context.push(pop);
+            }
         }
     }
 
-    static final class ColumnProcessor extends AbstractChildProcessor {
+    static final class ColumnProcessor extends L1AnnotationProcessor {
 
         // @Override
         // void onAttribute(
@@ -289,55 +283,162 @@
         // attribute.setColumn(new JpaColumn(annotation));
         // }
 
+        // @Override
+        // void onId(JpaId id, AnnotatedElement element, AnnotationProcessorStack context)
+        // {
+        // Column annotation = element.getAnnotation(Column.class);
+        // id.setColumn(new JpaColumn(annotation));
+        // }
+    }
+
+    static final class EmbeddedProcessor extends L1AnnotationProcessor {
+
+        @Override
+        void onManagedClass(
+                JpaManagedClass managedClass,
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+            JpaEmbedded attribute = new JpaEmbedded();
+            managedClass.getAttributes().getEmbeddedAttributes().add(attribute);
+            context.push(attribute);
+        }
+
         @Override
-        void onId(JpaId id, AnnotatedElement element, AnnotationProcessorStack context) {
-            Column annotation = element.getAnnotation(Column.class);
-            id.setColumn(new JpaColumn(annotation));
+        void onAttribute(
+                JpaAttribute attribute,
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+
+            if (!(attribute instanceof JpaEmbedded)) {
+                super.onAttribute(attribute, element, context);
+            }
+        }
+
+        @Override
+        public void onFinishElement(
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+
+            Object pop = context.pop();
+            if (!(pop instanceof JpaEmbedded)) {
+                context.push(pop);
+            }
         }
     }
 
-    static final class EmbeddedProcessor extends AbstractChildProcessor {
-        //
-        // @Override
-        // void onAttribute(
-        // JpaAttribute attribute,
-        // AnnotatedElement element,
-        // AnnotationProcessorStack context) {
-        // attribute.setEmbedded(true);
-        // }
+    static final class EmbeddedIdProcessor extends L1AnnotationProcessor {
+
+        @Override
+        void onManagedClass(
+                JpaManagedClass managedClass,
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+            JpaEmbeddedId id = new JpaEmbeddedId();
+            managedClass.getAttributes().setEmbeddedId(id);
+            context.push(id);
+        }
+
+        @Override
+        void onAttribute(
+                JpaAttribute attribute,
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+            if (attribute instanceof JpaEmbeddedId) {
+                // was created implictly by another annotation
+            }
+            else {
+                super.onAttribute(attribute, element, context);
+            }
+        }
+
+        @Override
+        public void onFinishElement(
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+
+            Object pop = context.pop();
+            if (!(pop instanceof JpaEmbeddedId)) {
+                context.push(pop);
+            }
+        }
     }
 
-    static final class EnumeratedProcessor extends AbstractChildProcessor {
+    static final class EnumeratedProcessor extends L2AnnotationProcessor {
 
-        // @Override
-        // void onAttribute(
-        // JpaAttribute attribute,
-        // AnnotatedElement element,
-        // AnnotationProcessorStack context) {
-        // Enumerated annotation = element.getAnnotation(Enumerated.class);
-        // attribute.setEnumerated(annotation.value());
-        // }
+        @Override
+        void onAttribute(
+                JpaAttribute attribute,
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
 
-        // @Override
-        // void onEmbeddableAttribute(
-        // JpaEmbeddableAttribute attribute,
-        // AnnotatedElement element,
-        // AnnotationProcessorStack context) {
-        // Enumerated annotation = element.getAnnotation(Enumerated.class);
-        // attribute.setEnumerated(annotation.value());
-        // }
+            if (attribute instanceof JpaBasic) {
+                EnumType enumType = element.getAnnotation(Enumerated.class).value();
+                ((JpaBasic) attribute).setEnumerated(enumType);
+            }
+            else {
+                super.onAttribute(attribute, element, context);
+            }
+        }
+    }
+
+    static final class GeneratedValueProcessor extends L2AnnotationProcessor {
+
+        @Override
+        void onAttribute(
+                JpaAttribute attribute,
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+
+            // can only attach to id
+            if (attribute instanceof JpaId) {
+                JpaGeneratedValue generated = new JpaGeneratedValue(element
+                        .getAnnotation(GeneratedValue.class));
+                ((JpaId) attribute).setGeneratedValue(generated);
+            }
+            else {
+                super.onAttribute(attribute, element, context);
+            }
+        }
     }
 
-    static final class GeneratedValueProcessor extends AbstractChildProcessor {
+    static final class IdProcessor extends L1AnnotationProcessor {
 
         @Override
-        void onId(JpaId id, AnnotatedElement element, AnnotationProcessorStack context) {
-            GeneratedValue annotation = element.getAnnotation(GeneratedValue.class);
-            id.setGeneratedValue(new JpaGeneratedValue(annotation));
+        void onManagedClass(
+                JpaManagedClass managedClass,
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+            JpaId attribute = new JpaId();
+            managedClass.getAttributes().getIds().add(attribute);
+            context.push(attribute);
+        }
+
+        @Override
+        void onAttribute(
+                JpaAttribute attribute,
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+            if (attribute instanceof JpaId) {
+                // id was created implictly by another annotation
+            }
+            else {
+                super.onAttribute(attribute, element, context);
+            }
+        }
+
+        @Override
+        public void onFinishElement(
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+
+            Object pop = context.pop();
+            if (!(pop instanceof JpaId)) {
+                context.push(pop);
+            }
         }
     }
 
-    static final class JoinColumnProcessor extends AbstractChildProcessor {
+    static final class JoinColumnProcessor extends L1AnnotationProcessor {
 
         // @Override
         // void onAttribute(
@@ -349,7 +450,7 @@
         // }
     }
 
-    static final class JoinColumnsProcessor extends AbstractChildProcessor {
+    static final class JoinColumnsProcessor extends L1AnnotationProcessor {
 
         // @Override
         // void onAttribute(
@@ -364,7 +465,7 @@
         // }
     }
 
-    static final class JoinTableProcessor extends AbstractChildProcessor {
+    static final class JoinTableProcessor extends L1AnnotationProcessor {
 
         // @Override
         // void onAttribute(
@@ -376,56 +477,94 @@
         // }
     }
 
-    static final class LobProcessor extends AbstractChildProcessor {
+    static final class LobProcessor extends L2AnnotationProcessor {
 
-     
+        @Override
+        void onAttribute(
+                JpaAttribute attribute,
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+
+            if (attribute instanceof JpaBasic) {
+                ((JpaBasic) attribute).setLob(true);
+            }
+            else {
+                super.onAttribute(attribute, element, context);
+            }
+        }
     }
 
-    static final class ManyToManyProcessor extends AbstractChildProcessor {
+    static final class ManyToManyProcessor extends L1AnnotationProcessor {
 
         @Override
-        void onAttributes(
-                JpaAttributes attributes,
+        void onManagedClass(
+                JpaManagedClass managedClass,
                 AnnotatedElement element,
                 AnnotationProcessorStack context) {
-
             JpaManyToMany attribute = new JpaManyToMany(element
                     .getAnnotation(ManyToMany.class));
-            attributes.getManyToManyRelationships().add(attribute);
+            managedClass.getAttributes().getManyToManyRelationships().add(attribute);
             context.push(attribute);
         }
 
         @Override
+        void onAttribute(
+                JpaAttribute attribute,
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+            if (!(attribute instanceof JpaManyToMany)) {
+                super.onAttribute(attribute, element, context);
+            }
+        }
+
+        @Override
         public void onFinishElement(
                 AnnotatedElement element,
                 AnnotationProcessorStack context) {
-            context.pop();
+
+            Object pop = context.pop();
+            if (!(pop instanceof JpaManyToMany)) {
+                context.push(pop);
+            }
         }
     }
 
-    static final class ManyToOneProcessor extends AbstractChildProcessor {
+    static final class ManyToOneProcessor extends L1AnnotationProcessor {
 
         @Override
-        void onAttributes(
-                JpaAttributes attributes,
+        void onManagedClass(
+                JpaManagedClass managedClass,
                 AnnotatedElement element,
                 AnnotationProcessorStack context) {
-
             JpaManyToOne attribute = new JpaManyToOne(element
                     .getAnnotation(ManyToOne.class));
-            attributes.getManyToOneRelationships().add(attribute);
+            managedClass.getAttributes().getManyToOneRelationships().add(attribute);
             context.push(attribute);
         }
 
         @Override
+        void onAttribute(
+                JpaAttribute attribute,
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+            if (!(attribute instanceof JpaManyToMany)) {
+                super.onAttribute(attribute, element, context);
+            }
+        }
+
+        @Override
         public void onFinishElement(
                 AnnotatedElement element,
                 AnnotationProcessorStack context) {
-            context.pop();
+
+            Object pop = context.pop();
+            if (!(pop instanceof JpaManyToOne)) {
+                context.push(pop);
+            }
         }
     }
 
-    static final class MapKeyProcessor extends AbstractChildProcessor {
+    static final class MapKeyProcessor extends L1AnnotationProcessor {
 
         // @Override
         // void onAttribute(
@@ -437,50 +576,76 @@
         // }
     }
 
-    static final class OneToManyProcessor extends AbstractChildProcessor {
+    static final class OneToManyProcessor extends L1AnnotationProcessor {
 
         @Override
-        void onAttributes(
-                JpaAttributes attributes,
+        void onManagedClass(
+                JpaManagedClass managedClass,
                 AnnotatedElement element,
                 AnnotationProcessorStack context) {
-
             JpaOneToMany attribute = new JpaOneToMany(element
                     .getAnnotation(OneToMany.class));
-            attributes.getOneToManyRelationships().add(attribute);
+            managedClass.getAttributes().getOneToManyRelationships().add(attribute);
             context.push(attribute);
         }
 
         @Override
+        void onAttribute(
+                JpaAttribute attribute,
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+            if (!(attribute instanceof JpaOneToMany)) {
+                super.onAttribute(attribute, element, context);
+            }
+        }
+
+        @Override
         public void onFinishElement(
                 AnnotatedElement element,
                 AnnotationProcessorStack context) {
-            context.pop();
+
+            Object pop = context.pop();
+            if (!(pop instanceof JpaOneToMany)) {
+                context.push(pop);
+            }
         }
     }
 
-    static final class OneToOneProcessor extends AbstractChildProcessor {
+    static final class OneToOneProcessor extends L1AnnotationProcessor {
 
         @Override
-        void onAttributes(
-                JpaAttributes attributes,
+        void onManagedClass(
+                JpaManagedClass managedClass,
                 AnnotatedElement element,
                 AnnotationProcessorStack context) {
-
             JpaOneToOne attribute = new JpaOneToOne(element.getAnnotation(OneToOne.class));
-            attributes.getOneToOneRelationships().add(attribute);
+            managedClass.getAttributes().getOneToOneRelationships().add(attribute);
             context.push(attribute);
         }
 
         @Override
+        void onAttribute(
+                JpaAttribute attribute,
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+            if (!(attribute instanceof JpaOneToOne)) {
+                super.onAttribute(attribute, element, context);
+            }
+        }
+
+        @Override
         public void onFinishElement(
                 AnnotatedElement element,
                 AnnotationProcessorStack context) {
-            context.pop();
+
+            Object pop = context.pop();
+            if (!(pop instanceof JpaOneToOne)) {
+                context.push(pop);
+            }
         }
     }
 
-    static final class OrderByProcessor extends AbstractChildProcessor {
+    static final class OrderByProcessor extends L1AnnotationProcessor {
 
         // @Override
         // void onAttribute(
@@ -492,70 +657,100 @@
         // }
     }
 
-    static final class TemporalProcessor extends AbstractChildProcessor {
+    static final class TemporalProcessor extends L2AnnotationProcessor {
 
-        // @Override
-        // void onAttribute(
-        // JpaAttribute attribute,
-        // AnnotatedElement element,
-        // AnnotationProcessorStack context) {
-        // Temporal annotation = element.getAnnotation(Temporal.class);
-        // attribute.setTemporal(annotation.value());
-        // }
+        @Override
+        void onAttribute(
+                JpaAttribute attribute,
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
 
-        // @Override
-        // void onEmbeddableAttribute(
-        // JpaEmbeddableAttribute attribute,
-        // AnnotatedElement element,
-        // AnnotationProcessorStack context) {
-        // Temporal annotation = element.getAnnotation(Temporal.class);
-        // attribute.setTemporal(annotation.value());
-        // }
+            TemporalType value = element.getAnnotation(Temporal.class).value();
 
-        @Override
-        void onId(JpaId id, AnnotatedElement element, AnnotationProcessorStack context) {
-            Temporal annotation = element.getAnnotation(Temporal.class);
-            id.setTemporal(annotation.value());
+            if (attribute instanceof JpaBasic) {
+                ((JpaBasic) attribute).setTemporal(value);
+            }
+            // according to the spec, only @Basic is compatibel with @Temporal, however
+            // @Id and @Version also support it in the schema
+            else if (attribute instanceof JpaId) {
+                ((JpaId) attribute).setTemporal(value);
+            }
+            else if (attribute instanceof JpaVersion) {
+                ((JpaVersion) attribute).setTemporal(value);
+            }
+            else {
+                super.onAttribute(attribute, element, context);
+            }
         }
     }
 
-    static final class TransientProcessor extends AbstractChildProcessor {
+    static final class TransientProcessor extends L1AnnotationProcessor {
 
         @Override
-        void onAttributes(
-                JpaAttributes attributes,
+        void onManagedClass(
+                JpaManagedClass managedClass,
                 AnnotatedElement element,
                 AnnotationProcessorStack context) {
             JpaTransient attribute = new JpaTransient();
-            attributes.getTransientAttributes().add(attribute);
+            managedClass.getAttributes().getTransientAttributes().add(attribute);
             context.push(attribute);
         }
 
         @Override
+        void onAttribute(
+                JpaAttribute attribute,
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+
+            if (!(attribute instanceof JpaTransient)) {
+                super.onAttribute(attribute, element, context);
+            }
+        }
+
+        @Override
         public void onFinishElement(
                 AnnotatedElement element,
                 AnnotationProcessorStack context) {
-            context.pop();
+
+            Object pop = context.pop();
+            if (!(pop instanceof JpaTransient)) {
+                context.push(pop);
+            }
         }
     }
 
-    static final class VersionProcessor extends AbstractChildProcessor {
+    static final class VersionProcessor extends L1AnnotationProcessor {
 
         @Override
-        void onAttributes(
-                JpaAttributes attributes,
+        void onManagedClass(
+                JpaManagedClass managedClass,
                 AnnotatedElement element,
                 AnnotationProcessorStack context) {
             JpaVersion attribute = new JpaVersion();
-            attributes.getVersionAttributes().add(attribute);
+            managedClass.getAttributes().getVersionAttributes().add(attribute);
             context.push(attribute);
         }
 
         @Override
+        void onAttribute(
+                JpaAttribute attribute,
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+
+            if (!(attribute instanceof JpaVersion)) {
+                super.onAttribute(attribute, element, context);
+            }
+        }
+
+        @Override
         public void onFinishElement(
                 AnnotatedElement element,
                 AnnotationProcessorStack context) {
-            context.pop();
+
+            Object pop = context.pop();
+            if (!(pop instanceof JpaVersion)) {
+                context.push(pop);
+            }
         }
     }
 }

Modified: incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/conf/EntityMapAnnotationLoaderTest.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/conf/EntityMapAnnotationLoaderTest.java?rev=428214&r1=428213&r2=428214&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/conf/EntityMapAnnotationLoaderTest.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/conf/EntityMapAnnotationLoaderTest.java
Wed Aug  2 19:39:45 2006
@@ -41,13 +41,14 @@
 import org.apache.cayenne.jpa.entity.MockMappedSuperclass2;
 import org.apache.cayenne.jpa.entity.MockMappedSuperclass3;
 import org.apache.cayenne.jpa.map.JpaAttributeOverride;
+import org.apache.cayenne.jpa.map.JpaBasic;
 import org.apache.cayenne.jpa.map.JpaEntity;
 import org.apache.cayenne.jpa.map.JpaEntityMap;
 import org.apache.cayenne.jpa.spi.MockPersistenceUnitInfo;
 
 public class EntityMapAnnotationLoaderTest extends TestCase {
 
-    public void testSortAnnotations() throws Exception {
+    public void testSortAnnotations1() throws Exception {
 
         EntityMapAnnotationLoader loader = new EntityMapAnnotationLoader(
                 new EntityMapLoaderContext(new MockPersistenceUnitInfo()));
@@ -62,6 +63,28 @@
         assertEquals(Entity.class, a1[0].annotationType());
         assertEquals(NamedQuery.class, a1[1].annotationType());
         assertEquals(IdClass.class, a1[2].annotationType());
+    }
+
+    public void testSortAnnotations2() throws Exception {
+        EntityMapLoaderContext context = new EntityMapLoaderContext(
+                new MockPersistenceUnitInfo());
+        EntityMapAnnotationLoader loader = new EntityMapAnnotationLoader(context);
+        loader.loadClassMapping(MockAnnotatedBeanOrdering.class);
+
+        JpaEntityMap map = context.getEntityMap();
+        JpaEntity entity = map.getEntities().iterator().next();
+
+        // regardless of the ordering of annotations, we should get the same result for
+        // both attributes
+        assertEquals(3, entity.getAttributes().getBasicAttributes().size());
+        JpaBasic a1 = entity.getAttributes().getBasicAttribute("attribute1");
+        assertTrue(a1.isLob());
+
+        JpaBasic a2 = entity.getAttributes().getBasicAttribute("attribute2");
+        assertTrue(a2.isLob());
+        
+        JpaBasic a3 = entity.getAttributes().getBasicAttribute("attribute3");
+        assertTrue(a3.isLob());
     }
 
     /**

Added: incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/conf/MockAnnotatedBeanOrdering.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/conf/MockAnnotatedBeanOrdering.java?rev=428214&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/conf/MockAnnotatedBeanOrdering.java
(added)
+++ incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/conf/MockAnnotatedBeanOrdering.java
Wed Aug  2 19:39:45 2006
@@ -0,0 +1,38 @@
+/*****************************************************************
+ *   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.cayenne.jpa.conf;
+
+import javax.persistence.Basic;
+import javax.persistence.Entity;
+import javax.persistence.Lob;
+
+@Entity
+public class MockAnnotatedBeanOrdering {
+
+    @Basic
+    @Lob
+    protected String attribute1;
+
+    @Lob
+    @Basic
+    protected String attribute2;
+    
+    @Lob
+    protected String attribute3;
+}



Mime
View raw message