cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r428232 - in /incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa: conf/EntityMapDefaultsProcessor.java map/JpaAttributes.java
Date Thu, 03 Aug 2006 04:35:47 GMT
Author: aadamchik
Date: Wed Aug  2 21:35:46 2006
New Revision: 428232

URL: http://svn.apache.org/viewvc?rev=428232&view=rev
Log:
fixing attribute defaults loading

Modified:
    incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/EntityMapDefaultsProcessor.java
    incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaAttributes.java

Modified: incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/EntityMapDefaultsProcessor.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/EntityMapDefaultsProcessor.java?rev=428232&r1=428231&r2=428232&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/EntityMapDefaultsProcessor.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/EntityMapDefaultsProcessor.java
Wed Aug  2 21:35:46 2006
@@ -113,6 +113,10 @@
                 entity.setName(split > 0 ? fqName.substring(split + 1) : fqName);
             }
 
+            if (entity.getAttributes() == null) {
+                entity.setAttributes(new JpaAttributes());
+            }
+
             // * default persistent fields
             JpaClassDescriptor descriptor = entity.getClassDescriptor();
 
@@ -150,29 +154,27 @@
                 JpaClassDescriptor descriptor,
                 JpaPropertyDescriptor property) {
 
-            // if (entity.attributeForName(property.getName()) != null
-            // || entity.idForName(property.getName()) != null) {
-            // return;
-            // }
-            //
-            // if (property.isDefaultNonRelationalType()) {
-            //
-            // JpaAttribute attribute = new JpaAttribute();
-            //
-            // attribute.setPropertyDescriptor(property);
-            //
-            // attribute.setBasic(new JpaBasic());
-            // attribute.setName(property.getName());
-            // entity.getAttributes().add(attribute);
-            // }
-            // else {
-            // String path = descriptor.getManagedClass().getName()
-            // + "."
-            // + property.getName();
-            //                context.recordConflict(new SimpleValidationFailure(
-            //                        property.getMember(),
-            //                        "Undefined property persistence status: " + path));
-            //            }
+            JpaAttributes attributes = entity.getAttributes();
+            if (attributes.getAttribute(property.getName()) != null) {
+                return;
+            }
+
+            if (property.isDefaultNonRelationalType()) {
+
+                JpaBasic attribute = new JpaBasic();
+
+                attribute.setPropertyDescriptor(property);
+                attribute.setName(property.getName());
+                attributes.getBasicAttributes().add(attribute);
+            }
+            else {
+                String path = descriptor.getManagedClass().getName()
+                        + "."
+                        + property.getName();
+                context.recordConflict(new SimpleValidationFailure(
+                        property.getMember(),
+                        "Undefined property persistence status: " + path));
+            }
         }
     }
 
@@ -212,8 +214,7 @@
         public boolean onStartNode(ProjectPath path) {
             JpaColumn column = (JpaColumn) path.getObject();
 
-            JpaAttribute parent = (JpaAttribute) path
-                    .firstInstanceOf(JpaAttribute.class);
+            JpaAttribute parent = (JpaAttribute) path.firstInstanceOf(JpaAttribute.class);
 
             if (column.getName() == null) {
                 column.setName(parent.getName());

Modified: incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaAttributes.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaAttributes.java?rev=428232&r1=428231&r2=428232&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaAttributes.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaAttributes.java
Wed Aug  2 21:35:46 2006
@@ -41,6 +41,65 @@
     protected Collection<JpaEmbedded> embeddedAttributes;
     protected Collection<JpaTransient> transientAttributes;
 
+    public JpaAttribute getAttribute(String name) {
+        if (name == null) {
+            return null;
+        }
+
+        if (embeddedId != null && name.equals(embeddedId.getName())) {
+            return embeddedId;
+        }
+
+        JpaAttribute attribute;
+
+        attribute = getId(name);
+        if (attribute != null) {
+            return attribute;
+        }
+
+        attribute = getBasicAttribute(name);
+        if (attribute != null) {
+            return attribute;
+        }
+
+        attribute = getVersionAttribute(name);
+        if (attribute != null) {
+            return attribute;
+        }
+
+        attribute = getManyToOneRelationship(name);
+        if (attribute != null) {
+            return attribute;
+        }
+
+        attribute = getOneToManyRelationship(name);
+        if (attribute != null) {
+            return attribute;
+        }
+
+        attribute = getOneToOneRelationship(name);
+        if (attribute != null) {
+            return attribute;
+        }
+
+        attribute = getManyToManyRelationship(name);
+        if (attribute != null) {
+            return attribute;
+        }
+
+        attribute = getTransientAttribute(name);
+        if (attribute != null) {
+            return attribute;
+        }
+
+        attribute = getEmbeddedAttribute(name);
+        if (attribute != null) {
+            return attribute;
+        }
+
+        return null;
+    }
+
     /**
      * Returns combined count of all attributes and relationships.
      */
@@ -179,13 +238,29 @@
         return embeddedAttributes;
     }
 
+    public JpaEmbedded getEmbeddedAttribute(String attributeName) {
+        if (attributeName == null) {
+            throw new IllegalArgumentException("Null attribute name");
+        }
+
+        if (embeddedAttributes != null) {
+            for (JpaEmbedded attribute : embeddedAttributes) {
+                if (attributeName.equals(attribute.getName())) {
+                    return attribute;
+                }
+            }
+        }
+
+        return null;
+    }
+
     public Collection<JpaManyToMany> getManyToManyRelationships() {
         if (manyToManyRelationships == null) {
             manyToManyRelationships = new ArrayList<JpaManyToMany>();
         }
         return manyToManyRelationships;
     }
-    
+
     public JpaManyToMany getManyToManyRelationship(String attributeName) {
         if (attributeName == null) {
             throw new IllegalArgumentException("Null attribute name");
@@ -222,7 +297,7 @@
         }
         return oneToOneRelationships;
     }
-    
+
     public JpaOneToOne getOneToOneRelationship(String attributeName) {
         if (attributeName == null) {
             throw new IllegalArgumentException("Null attribute name");
@@ -245,7 +320,7 @@
         }
         return transientAttributes;
     }
-    
+
     /**
      * Returns a JpaTransient for a given property name
      */
@@ -270,5 +345,24 @@
             versionAttributes = new ArrayList<JpaVersion>();
         }
         return versionAttributes;
+    }
+
+    /**
+     * Returns a JpaTransient for a given property name
+     */
+    public JpaVersion getVersionAttribute(String attributeName) {
+        if (attributeName == null) {
+            throw new IllegalArgumentException("Null attribute name");
+        }
+
+        if (versionAttributes != null) {
+            for (JpaVersion attribute : versionAttributes) {
+                if (attributeName.equals(attribute.getName())) {
+                    return attribute;
+                }
+            }
+        }
+
+        return null;
     }
 }



Mime
View raw message