cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject [1/2] cayenne git commit: CAY-2489 Add validation to the case of not to PK relationships
Date Thu, 18 Oct 2018 14:00:18 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master 23dc84b66 -> 5855ffc71


CAY-2489 Add validation to the case of not to PK relationships


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/4dbcfd31
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/4dbcfd31
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/4dbcfd31

Branch: refs/heads/master
Commit: 4dbcfd31879aaa1ed070ada9d423f9166f9f8b4f
Parents: 20b166a
Author: Arseni Bulatski <ancarseni@gmail.com>
Authored: Wed Oct 17 10:53:39 2018 +0300
Committer: Arseni Bulatski <ancarseni@gmail.com>
Committed: Wed Oct 17 10:57:42 2018 +0300

----------------------------------------------------------------------
 RELEASE-NOTES.txt                                  |  1 +
 .../validation/DbRelationshipValidator.java        | 11 +++++++++++
 .../validation/ObjRelationshipValidator.java       | 17 ++++++++++++++---
 .../org/apache/cayenne/map/DbRelationship.java     |  6 +++---
 4 files changed, 29 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/4dbcfd31/RELEASE-NOTES.txt
----------------------------------------------------------------------
diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index 2905bab..c670328 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -19,6 +19,7 @@ CAY-2471 Support multiple XML project versions
 CAY-2473 Modeler: cleanup attributes and relationship editors
 CAY-2474 Modeler: swap buttons in dialog toolbar
 CAY-2475 Modeler: move inheritance icon to name column in objAttr table and objRel table
+CAY-2489 Add validation to the case of not to PK relationships
 
 Bug Fixes:
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/4dbcfd31/cayenne-project/src/main/java/org/apache/cayenne/project/validation/DbRelationshipValidator.java
----------------------------------------------------------------------
diff --git a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/DbRelationshipValidator.java
b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/DbRelationshipValidator.java
index 68854fb..8ddc5f9 100644
--- a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/DbRelationshipValidator.java
+++ b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/DbRelationshipValidator.java
@@ -71,6 +71,17 @@ class DbRelationshipValidator extends ConfigurationNodeValidator {
             }
         }
 
+        if(!relationship.isToPK()) {
+            DbRelationship reverseRelationship = relationship.getReverseRelationship();
+            if(reverseRelationship == null || !reverseRelationship.isToPK()) {
+                addFailure(
+                        validationResult,
+                        relationship,
+                        "DbRelationship '%s' has join not to PK. Cayenne doesn't allow this
type of relashionships",
+                        toString(relationship));
+            }
+        }
+
         if (Util.isEmptyString(relationship.getName())) {
             addFailure(validationResult, relationship, "Unnamed DbRelationship");
         } else if (relationship.getSourceEntity().getAttribute(relationship.getName()) !=
null) {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/4dbcfd31/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ObjRelationshipValidator.java
----------------------------------------------------------------------
diff --git a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ObjRelationshipValidator.java
b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ObjRelationshipValidator.java
index 733c300..d75cc1a 100644
--- a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ObjRelationshipValidator.java
+++ b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ObjRelationshipValidator.java
@@ -18,9 +18,6 @@
  ****************************************************************/
 package org.apache.cayenne.project.validation;
 
-import java.util.Iterator;
-import java.util.List;
-
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbJoin;
 import org.apache.cayenne.map.DbRelationship;
@@ -30,6 +27,9 @@ import org.apache.cayenne.map.ObjRelationship;
 import org.apache.cayenne.util.Util;
 import org.apache.cayenne.validation.ValidationResult;
 
+import java.util.Iterator;
+import java.util.List;
+
 class ObjRelationshipValidator extends ConfigurationNodeValidator {
 
     void validate(ObjRelationship relationship, ValidationResult validationResult) {
@@ -126,6 +126,17 @@ class ObjRelationshipValidator extends ConfigurationNodeValidator {
             }
         }
 
+        if(!relationship.isToPK()) {
+            ObjRelationship reverseRelationship = relationship.getReverseRelationship();
+            if(reverseRelationship == null || !reverseRelationship.isToPK()) {
+                addFailure(
+                        validationResult,
+                        relationship,
+                        "ObjRelationship '%s' has join not to PK. Cayenne doesn't allow this
type of relashioships",
+                        toString(relationship));
+            }
+        }
+
         // check for relationships with same source and target entities
         ObjEntity entity = relationship.getSourceEntity();
         for (ObjRelationship rel : entity.getRelationships()) {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/4dbcfd31/cayenne-server/src/main/java/org/apache/cayenne/map/DbRelationship.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/map/DbRelationship.java b/cayenne-server/src/main/java/org/apache/cayenne/map/DbRelationship.java
index 2eb89c0..ae2ee61 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/map/DbRelationship.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/map/DbRelationship.java
@@ -238,12 +238,12 @@ public class DbRelationship extends Relationship implements ConfigurationNode
{
                 return false;
             }
 
-            if (target.isPrimaryKey()) {
-                return true;
+            if (!target.isPrimaryKey()) {
+                return false;
             }
         }
 
-        return false;
+        return true;
     }
 
     /**


Mime
View raw message