cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r428224 - in /incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa: conf/EntityMapAnnotationLoader.java conf/MemberAnnotationProcessorFactory.java map/JpaAssociationOverride.java map/JpaAttributeOverride.java
Date Thu, 03 Aug 2006 04:06:20 GMT
Author: aadamchik
Date: Wed Aug  2 21:06:20 2006
New Revision: 428224

URL: http://svn.apache.org/viewvc?rev=428224&view=rev
Log:
fixing attribute override processing; 
adding association overrides

Modified:
    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/main/java/org/apache/cayenne/jpa/map/JpaAssociationOverride.java
    incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaAttributeOverride.java

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=428224&r1=428223&r2=428224&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 21:06:20 2006
@@ -121,26 +121,28 @@
         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);
+        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(AssociationOverride.class.getName(), 1);
+        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(AssociationOverrides.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);
-
+        // second level - attribute overrides (can belong to Embedded or can be a part of
+        // the entity )
         MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(AttributeOverride.class.getName(), 2);
         MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(AttributeOverrides.class.getName(), 2);
-        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(AssociationOverride.class.getName(), 2);
-        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(AssociationOverrides.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);
-        
-        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(MapKey.class.getName(), 2);
-        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(OrderBy.class.getName(), 2);
-        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(Column.class.getName(), 2);
+        // third level of member annotations - details implying one of the attributes
+        // above
+        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(GeneratedValue.class.getName(), 3);
+        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(Temporal.class.getName(), 3);
+        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(TableGenerator.class.getName(), 3);
+        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(SequenceGenerator.class.getName(), 3);
+
+        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(Lob.class.getName(), 3);
+        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(Temporal.class.getName(), 3);
+        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(Enumerated.class.getName(), 3);
+
+        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(MapKey.class.getName(), 3);
+        MEMBER_ANNOTATION_ORDERING_WEIGHTS.put(OrderBy.class.getName(), 3);
+        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=428224&r1=428223&r2=428224&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 21:06:20 2006
@@ -24,6 +24,8 @@
 import java.util.ArrayList;
 import java.util.Collection;
 
+import javax.persistence.AssociationOverride;
+import javax.persistence.AssociationOverrides;
 import javax.persistence.AttributeOverride;
 import javax.persistence.AttributeOverrides;
 import javax.persistence.Basic;
@@ -43,12 +45,14 @@
 import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
 
+import org.apache.cayenne.jpa.map.JpaAssociationOverride;
 import org.apache.cayenne.jpa.map.JpaAttribute;
 import org.apache.cayenne.jpa.map.JpaAttributeOverride;
 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.JpaJoinColumn;
@@ -69,7 +73,7 @@
 class MemberAnnotationProcessorFactory extends AnnotationProcessorFactory {
 
     // superclass of the top-level member annotations
-    abstract static class L1AnnotationProcessor implements AnnotationProcessor {
+    abstract static class L1Processor implements AnnotationProcessor {
 
         public void onStartElement(
                 AnnotatedElement element,
@@ -120,7 +124,7 @@
     }
 
     // superclass of the second-level member annotations
-    abstract static class L2AnnotationProcessor implements AnnotationProcessor {
+    abstract static class L2Processor implements AnnotationProcessor {
 
         public void onStartElement(
                 AnnotatedElement element,
@@ -186,7 +190,49 @@
         }
     }
 
-    static final class AttributeOverrideProcessor extends L2AnnotationProcessor {
+    static final class AssociationOverrideProcessor extends L1Processor {
+
+        @Override
+        void onManagedClass(
+                JpaManagedClass managedClass,
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+
+            if (managedClass instanceof JpaEntity) {
+                JpaAssociationOverride override = new JpaAssociationOverride(element
+                        .getAnnotation(AssociationOverride.class));
+                ((JpaEntity) managedClass).getAssociationOverrides().add(override);
+            }
+            else {
+                super.onManagedClass(managedClass, element, context);
+            }
+        }
+    }
+
+    static final class AssociationOverridesProcessor extends L1Processor {
+
+        @Override
+        void onManagedClass(
+                JpaManagedClass managedClass,
+                AnnotatedElement element,
+                AnnotationProcessorStack context) {
+
+            if (managedClass instanceof JpaEntity) {
+                AssociationOverrides overrides = element
+                        .getAnnotation(AssociationOverrides.class);
+                for (AssociationOverride overrideAnnotation : overrides.value()) {
+                    JpaAssociationOverride override = new JpaAssociationOverride(
+                            overrideAnnotation);
+                    ((JpaEntity) managedClass).getAssociationOverrides().add(override);
+                }
+            }
+            else {
+                super.onManagedClass(managedClass, element, context);
+            }
+        }
+    }
+
+    static final class AttributeOverrideProcessor extends L1Processor {
 
         @Override
         void onAttribute(
@@ -205,7 +251,7 @@
         }
     }
 
-    static final class AttributeOverridesProcessor extends L1AnnotationProcessor {
+    static final class AttributeOverridesProcessor extends L1Processor {
 
         @Override
         void onAttribute(
@@ -229,7 +275,7 @@
         }
     }
 
-    static final class BasicProcessor extends L1AnnotationProcessor {
+    static final class BasicProcessor extends L1Processor {
 
         @Override
         void onManagedClass(
@@ -263,7 +309,7 @@
         }
     }
 
-    static final class ColumnProcessor extends L2AnnotationProcessor {
+    static final class ColumnProcessor extends L2Processor {
 
         @Override
         void onAttribute(
@@ -288,7 +334,7 @@
         }
     }
 
-    static final class EmbeddedProcessor extends L1AnnotationProcessor {
+    static final class EmbeddedProcessor extends L1Processor {
 
         @Override
         void onManagedClass(
@@ -323,7 +369,7 @@
         }
     }
 
-    static final class EmbeddedIdProcessor extends L1AnnotationProcessor {
+    static final class EmbeddedIdProcessor extends L1Processor {
 
         @Override
         void onManagedClass(
@@ -360,7 +406,7 @@
         }
     }
 
-    static final class EnumeratedProcessor extends L2AnnotationProcessor {
+    static final class EnumeratedProcessor extends L2Processor {
 
         @Override
         void onAttribute(
@@ -378,7 +424,7 @@
         }
     }
 
-    static final class GeneratedValueProcessor extends L2AnnotationProcessor {
+    static final class GeneratedValueProcessor extends L2Processor {
 
         @Override
         void onAttribute(
@@ -398,7 +444,7 @@
         }
     }
 
-    static final class IdProcessor extends L1AnnotationProcessor {
+    static final class IdProcessor extends L1Processor {
 
         @Override
         void onManagedClass(
@@ -435,7 +481,7 @@
         }
     }
 
-    static final class JoinColumnProcessor extends L2AnnotationProcessor {
+    static final class JoinColumnProcessor extends L2Processor {
 
         @Override
         void onAttribute(
@@ -461,7 +507,7 @@
         }
     }
 
-    static final class JoinColumnsProcessor extends L2AnnotationProcessor {
+    static final class JoinColumnsProcessor extends L2Processor {
 
         @Override
         void onAttribute(
@@ -491,7 +537,7 @@
         }
     }
 
-    static final class JoinTableProcessor extends L2AnnotationProcessor {
+    static final class JoinTableProcessor extends L2Processor {
 
         @Override
         void onAttribute(
@@ -520,7 +566,7 @@
         }
     }
 
-    static final class LobProcessor extends L2AnnotationProcessor {
+    static final class LobProcessor extends L2Processor {
 
         @Override
         void onAttribute(
@@ -537,7 +583,7 @@
         }
     }
 
-    static final class ManyToManyProcessor extends L1AnnotationProcessor {
+    static final class ManyToManyProcessor extends L1Processor {
 
         @Override
         void onManagedClass(
@@ -572,7 +618,7 @@
         }
     }
 
-    static final class ManyToOneProcessor extends L1AnnotationProcessor {
+    static final class ManyToOneProcessor extends L1Processor {
 
         @Override
         void onManagedClass(
@@ -607,7 +653,7 @@
         }
     }
 
-    static final class MapKeyProcessor extends L2AnnotationProcessor {
+    static final class MapKeyProcessor extends L2Processor {
 
         @Override
         void onAttribute(
@@ -628,7 +674,7 @@
         }
     }
 
-    static final class OneToManyProcessor extends L1AnnotationProcessor {
+    static final class OneToManyProcessor extends L1Processor {
 
         @Override
         void onManagedClass(
@@ -663,7 +709,7 @@
         }
     }
 
-    static final class OneToOneProcessor extends L1AnnotationProcessor {
+    static final class OneToOneProcessor extends L1Processor {
 
         @Override
         void onManagedClass(
@@ -697,7 +743,7 @@
         }
     }
 
-    static final class OrderByProcessor extends L1AnnotationProcessor {
+    static final class OrderByProcessor extends L2Processor {
 
         @Override
         void onAttribute(
@@ -718,7 +764,7 @@
         }
     }
 
-    static final class TemporalProcessor extends L2AnnotationProcessor {
+    static final class TemporalProcessor extends L2Processor {
 
         @Override
         void onAttribute(
@@ -745,7 +791,7 @@
         }
     }
 
-    static final class TransientProcessor extends L1AnnotationProcessor {
+    static final class TransientProcessor extends L1Processor {
 
         @Override
         void onManagedClass(
@@ -780,7 +826,7 @@
         }
     }
 
-    static final class VersionProcessor extends L1AnnotationProcessor {
+    static final class VersionProcessor extends L1Processor {
 
         @Override
         void onManagedClass(

Modified: incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaAssociationOverride.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaAssociationOverride.java?rev=428224&r1=428223&r2=428224&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaAssociationOverride.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaAssociationOverride.java
Wed Aug  2 21:06:20 2006
@@ -21,10 +21,26 @@
 import java.util.ArrayList;
 import java.util.Collection;
 
+import javax.persistence.AssociationOverride;
+
 public class JpaAssociationOverride {
 
     protected String name;
     protected Collection<JpaJoinColumn> joinColumns;
+
+    public JpaAssociationOverride() {
+
+    }
+
+    public JpaAssociationOverride(AssociationOverride annotation) {
+        this.name = annotation.name();
+        if (annotation.joinColumns() != null) {
+
+            for (int i = 0; i < annotation.joinColumns().length; i++) {
+                getJoinColumns().add(new JpaJoinColumn(annotation.joinColumns()[i]));
+            }
+        }
+    }
 
     public Collection<JpaJoinColumn> getJoinColumns() {
         if (joinColumns == null) {

Modified: incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaAttributeOverride.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaAttributeOverride.java?rev=428224&r1=428223&r2=428224&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaAttributeOverride.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaAttributeOverride.java
Wed Aug  2 21:06:20 2006
@@ -17,16 +17,14 @@
  *  under the License.
  ****************************************************************/
 
-
 package org.apache.cayenne.jpa.map;
 
 import javax.persistence.AttributeOverride;
 
 import org.apache.cayenne.util.TreeNodeChild;
 
-public class JpaAttributeOverride {
+public class JpaAttributeOverride extends JpaAttribute {
 
-    protected String name;
     protected JpaColumn column;
 
     public JpaAttributeOverride() {
@@ -48,22 +46,5 @@
 
     public void setColumn(JpaColumn column) {
         this.column = column;
-    }
-
-    /**
-     * Returns overriden attribute name.
-     * <h3>Specification Documentation</h3>
-     * <p>
-     * <b>Description:</b> (Required) The name of the property in the embedded
object
-     * that is being mapped if property-based access is being used, or the name of the
-     * field if field-based access is used.
-     * </p>
-     */
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
     }
 }



Mime
View raw message