cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject [cayenne] branch STABLE-4.1 updated: CAY-2566 Flush action generates update for PK attribute in case of toDepPK relationship
Date Wed, 17 Apr 2019 06:59:18 GMT
This is an automated email from the ASF dual-hosted git repository.

ntimofeev pushed a commit to branch STABLE-4.1
in repository https://gitbox.apache.org/repos/asf/cayenne.git


The following commit(s) were added to refs/heads/STABLE-4.1 by this push:
     new e8772c0  CAY-2566 Flush action generates update for PK attribute in case of toDepPK
relationship
e8772c0 is described below

commit e8772c0aa5f1ef3c4aa74948108284c39354cca5
Author: Nikita Timofeev <stariy95@gmail.com>
AuthorDate: Wed Apr 17 09:54:42 2019 +0300

    CAY-2566 Flush action generates update for PK attribute in case of toDepPK relationship
---
 RELEASE-NOTES.txt                                  |  2 ++
 .../cayenne/access/DataDomainDBDiffBuilder.java    | 13 ++++++++---
 .../apache/cayenne/access/IdentityColumnsIT.java   | 27 ++++++++++++++++++----
 3 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index d81100a..539574a 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -12,10 +12,12 @@ Release: 4.1.B2
 Date:
 ----------------------------------
 Bug Fixes:
+
 CAY-2550 Modeler: ObjAttribute inspector modifies wrong columns in attribute table
 CAY-2559 Modeler: Warning dialog shows wrong information after changing target entity in
dbRelationship
 CAY-2561 Modeler: cgen type combobox doesn't set templates
 CAY-2564 No import for Property after generation classes with pk properties
+CAY-2566 Flush action generates update for PK attribute in case of toDepPK relationship
 
 ----------------------------------
 Release: 4.1.B1
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/DataDomainDBDiffBuilder.java
b/cayenne-server/src/main/java/org/apache/cayenne/access/DataDomainDBDiffBuilder.java
index 80db9c5..e3878f0 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/DataDomainDBDiffBuilder.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/DataDomainDBDiffBuilder.java
@@ -33,6 +33,7 @@ import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 
@@ -178,7 +179,9 @@ class DataDomainDBDiffBuilder implements GraphChangeHandler {
             }
 
         } else {
-            if (!relationship.isToMany() && relationship.isToPK()) {
+            List<DbRelationship> dbRelationships = relationship.getDbRelationships();
+            DbRelationship lastDbRelationship = dbRelationships.get(dbRelationships.size()
- 1);
+            if (!relationship.isToMany() && lastDbRelationship.isToPK() &&
!lastDbRelationship.isToDependentPK()) {
                 doArcCreated(targetNodeId, arcId);
             }
         }
@@ -209,8 +212,12 @@ class DataDomainDBDiffBuilder implements GraphChangeHandler {
                 throw new IllegalArgumentException("Bad arcId: " + arcId);
             }
 
-        } else if (!relationship.isSourceIndependentFromTargetChange()) {
-            doArcDeleted(targetNodeId, arcId);
+        } else {
+            List<DbRelationship> dbRelationships = relationship.getDbRelationships();
+            DbRelationship lastDbRelationship = dbRelationships.get(dbRelationships.size()
- 1);
+            if (!relationship.isToMany() && lastDbRelationship.isToPK() &&
!lastDbRelationship.isToDependentPK()) {
+                doArcDeleted(targetNodeId, arcId);
+            }
         }
     }
 
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/IdentityColumnsIT.java
b/cayenne-server/src/test/java/org/apache/cayenne/access/IdentityColumnsIT.java
index c072c62..fda8c32 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/IdentityColumnsIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/IdentityColumnsIT.java
@@ -20,6 +20,7 @@
 package org.apache.cayenne.access;
 
 import org.apache.cayenne.Cayenne;
+import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.ObjectId;
 import org.apache.cayenne.Persistent;
@@ -45,10 +46,7 @@ import org.junit.Test;
 
 import java.util.List;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
 
 @UseServerRuntime(CayenneProjects.GENERATED_PROJECT)
 public class IdentityColumnsIT extends ServerCase {
@@ -339,4 +337,25 @@ public class IdentityColumnsIT extends ServerCase {
         assertNotNull(Cayenne.objectForPK(context, GeneratedColumnTestEntity.class, id1));
         assertNotNull(Cayenne.objectForPK(context, GeneratedColumnDep.class, id2));
     }
+
+    /**
+     * This will fail if commit will attempt to update generated PK.
+     * See CAY-2566.
+     */
+    @Test
+    public void testUpdateMasterEntity() {
+        GeneratedColumnTestEntity idObject = context.newObject(GeneratedColumnTestEntity.class);
+        idObject.setName("aaa");
+        context.commitChanges();
+
+        GeneratedColumnDep dependent = context.newObject(GeneratedColumnDep.class);
+        dependent.setName("aaa");
+        dependent.setToMaster(idObject);
+
+        try {
+            context.commitChanges();
+        } catch(CayenneRuntimeException ex) {
+            fail("Commit should succeed");
+        }
+    }
 }


Mime
View raw message