Author: kmenard
Date: Tue May 30 05:49:37 2006
New Revision: 410263

URL: http://svn.apache.org/viewvc?rev=410263&view=rev
Log:
Fix for CAY-415.  Entities can no longer add relationships with the same name 
as an existing attribute, vice versa. 

Modified:
    
incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/map/Entity.java
    
incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/map/EntityTst.java

Modified: 
incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/map/Entity.java
URL: 
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/map/Entity.java?rev=410263&r1=410262&r2=410263&view=diff
==============================================================================
--- 
incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/map/Entity.java
 (original)
+++ 
incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/map/Entity.java
 Tue May 30 05:49:37 2006
@@ -170,6 +170,13 @@
                         + attribute.getName());
             }
         }
+        
+        // Check that there aren't any relationships with the same name as the 
given attribute.
+        Object existingRelationship = relationships.get(attribute.getName());
+        if (existingRelationship != null) {            
+            throw new IllegalArgumentException(
+                   "An attempt to override relationship '" + 
attribute.getName());
+        }
 
         attributes.put(attribute.getName(), attribute);
         attribute.setEntity(this);
@@ -211,6 +218,13 @@
                 throw new IllegalArgumentException(
                         "An attempt to override relationship '" + 
relationship.getName());
             }
+        }
+        
+        // Check that there aren't any attributes with the same name as the 
given relationship.
+        Object existingAttribute = attributes.get(relationship.getName());
+        if (existingAttribute != null) {
+            throw new IllegalArgumentException("An attempt to override 
attribute '"
+                    + relationship.getName());
         }
 
         relationships.put(relationship.getName(), relationship);

Modified: 
incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/map/EntityTst.java
URL: 
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/map/EntityTst.java?rev=410263&r1=410262&r2=410263&view=diff
==============================================================================
--- 
incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/map/EntityTst.java
 (original)
+++ 
incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/map/EntityTst.java
 Tue May 30 05:49:37 2006
@@ -161,6 +161,40 @@
         entity.removeRelationship(rel.getName());
         assertNull(entity.getRelationship(rel.getName()));
     }
+    
+    public void testAttributeClashWithRelationship() {
+        Entity entity = new MockEntity();
+        Relationship rel = new MockRelationship("tst_name");
+        
+        entity.addRelationship(rel);
+        
+        try {
+            Attribute attribute = new MockAttribute("tst_name");
+            entity.addAttribute(attribute);
+            
+            fail("Exception should have been thrown due to clashing attribute 
and relationship names.");
+        }
+        catch (Exception e) {
+            // Exception expected.
+        }
+    }
+    
+    public void testRelationshipClashWithAttribute() {
+        Entity entity = new MockEntity();
+        Attribute attribute = new MockAttribute("tst_name");
+        
+        entity.addAttribute(attribute);
+        
+        try {
+            Relationship rel = new MockRelationship("tst_name");
+            entity.addRelationship(rel);
+            
+            fail("Exception should have been thrown due to clashing attribute 
and relationship names.");
+        }
+        catch (Exception e) {
+            // Exception expected.
+        }
+    }
 
     public void testResolveBadObjPath1() {
         // test invalid expression path


Reply via email to