cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dkazimirc...@apache.org
Subject svn commit: r1158213 - /cayenne/main/trunk/framework/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ObjRelationshipValidator.java
Date Tue, 16 Aug 2011 11:53:54 GMT
Author: dkazimirchyk
Date: Tue Aug 16 11:53:54 2011
New Revision: 1158213

URL: http://svn.apache.org/viewvc?rev=1158213&view=rev
Log:
CAY-1601 Modeler: warn user if ObjRelationhip structure in model is not supported

added warnings to the modeler

Modified:
    cayenne/main/trunk/framework/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ObjRelationshipValidator.java

Modified: cayenne/main/trunk/framework/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ObjRelationshipValidator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ObjRelationshipValidator.java?rev=1158213&r1=1158212&r2=1158213&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ObjRelationshipValidator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ObjRelationshipValidator.java
Tue Aug 16 11:53:54 2011
@@ -133,6 +133,36 @@ class ObjRelationshipValidator extends C
                 }
             }
         }
+        
+        // check for relationships with same source and target entities
+        ObjEntity entity = (ObjEntity) relationship.getSourceEntity();
+        for (ObjRelationship rel : entity.getRelationships()) {
+            if (relationship.getDbRelationshipPath().equals(rel.getDbRelationshipPath()))
{
+                if (relationship != rel && 
+                        relationship.getTargetEntity() == rel.getTargetEntity() &&
+                        relationship.getSourceEntity() == rel.getSourceEntity()) {
+                    addFailure(
+                            validationResult, 
+                            relationship, 
+                            "ObjectRelationship '%s' duplicates relationship '%s'", 
+                            toString(relationship), 
+                            toString(rel));
+                }
+            }
+        }
+        
+        // check for invalid relationships in inherited entities
+        if (relationship.getReverseRelationship() != null) {
+            ObjRelationship revRel = relationship.getReverseRelationship();
+            if (relationship.getSourceEntity() != revRel.getTargetEntity() 
+                    || relationship.getTargetEntity() != revRel.getSourceEntity()) {
+                addFailure(
+                        validationResult,
+                        revRel,
+                        "Usage of super entity's relationships '%s' as reversed relationships
for sub entity is discouraged",
+                        toString(revRel));
+            }
+        }
     }
 
     private String toString(ObjRelationship relationship) {



Mime
View raw message