You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by nt...@apache.org on 2019/10/08 07:49:10 UTC

[cayenne] 03/03: CAY-2628 dbimport: unable to add several relationships to existing entity

This is an automated email from the ASF dual-hosted git repository.

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

commit 3264658866afb34f746e9cb1889d87e92ce9e4c1
Author: Nikita Timofeev <st...@gmail.com>
AuthorDate: Mon Oct 7 17:59:51 2019 +0300

    CAY-2628 dbimport: unable to add several relationships to existing entity
    
    (cherry picked from commit 9a6ab370ab8dfe11c94723c79b05c6bd6ab35bb7)
---
 RELEASE-NOTES.txt                                        |  1 +
 .../cayenne/dbsync/merge/DbRelationshipDictionary.java   |  4 ++--
 .../dbimport/testImportNewRelationship.map.xml-result    | 16 ++++++++++++++++
 .../cayenne/tools/dbimport/testImportNewRelationship.sql | 10 +++++++++-
 4 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index 6c40987..cf57557 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -30,6 +30,7 @@ CAY-2586 Char can't be materialized to EnumType in some cases
 CAY-2616 Modeler: Wrong handling of path with spaces
 CAY-2624 SelectQuery "having" qualifier is not considered when calculating cache key
 CAY-2627 Modeler: ObjRelationship creation dialog ignores delete rule
+CAY-2628 dbimport: unable to add several relationships to existing entity
 
 ----------------------------------
 Release: 4.0.1
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbRelationshipDictionary.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbRelationshipDictionary.java
index 4d5d74c..1298c59 100644
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbRelationshipDictionary.java
+++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbRelationshipDictionary.java
@@ -72,9 +72,9 @@ class DbRelationshipDictionary extends MergerDictionary<DbRelationship> {
             TreeSet<String> joins = new TreeSet<>();
             for(DbJoin join : relationship.getJoins()) {
                 joins.add(
-                        (join.getSource() == null ? "~" : join.getSource().getName()) + "." + join.getSourceName()
+                        relationship.getSourceEntityName() + "." + join.getSourceName()
                         + ">" +
-                        (join.getTarget() == null ? "~" : join.getTarget().getName()) + "." + join.getTargetName()
+                        relationship.getTargetEntityName() + "." + join.getTargetName()
                 );
             }
             joinSignature = joins.toArray(new String[0]);
diff --git a/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewRelationship.map.xml-result b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewRelationship.map.xml-result
index 5daeef7..04198bd 100644
--- a/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewRelationship.map.xml-result
+++ b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewRelationship.map.xml-result
@@ -31,18 +31,34 @@
         <db-attribute name="T2_NAME" type="VARCHAR" length="45"/>
         <db-attribute name="TABLE1_ID" type="INTEGER" isMandatory="true" length="10"/>
      </db-entity>
+    <db-entity name="TABLE3" schema="SCHEMA_01">
+        <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/>
+        <db-attribute name="T3_NAME" type="VARCHAR" length="45"/>
+        <db-attribute name="TABLE1_ID" type="INTEGER" isMandatory="true" length="10"/>
+    </db-entity>
      <obj-entity name="Table1" className="Table1" dbEntityName="TABLE1">
          <obj-attribute name="t1Name" type="java.lang.String" db-attribute-path="T1_NAME"/>
      </obj-entity>
      <obj-entity name="Table2" className="Table2" dbEntityName="TABLE2">
         <obj-attribute name="t2Name" type="java.lang.String" db-attribute-path="T2_NAME"/>
      </obj-entity>
+    <obj-entity name="Table3" className="Table3" dbEntityName="TABLE3">
+        <obj-attribute name="t3Name" type="java.lang.String" db-attribute-path="T3_NAME"/>
+    </obj-entity>
+    <db-relationship name="table3s" source="TABLE1" target="TABLE3" toMany="true">
+        <db-attribute-pair source="ID" target="TABLE1_ID"/>
+    </db-relationship>
      <db-relationship name="table2s" source="TABLE1" target="TABLE2" toMany="true">
         <db-attribute-pair source="ID" target="TABLE1_ID"/>
      </db-relationship>
      <db-relationship name="table1" source="TABLE2" target="TABLE1" toMany="false">
         <db-attribute-pair source="TABLE1_ID" target="ID"/>
      </db-relationship>
+    <db-relationship name="table1" source="TABLE3" target="TABLE1" toMany="false">
+        <db-attribute-pair source="TABLE1_ID" target="ID"/>
+    </db-relationship>
+    <obj-relationship name="table3s" source="Table1" target="Table3" deleteRule="Deny" db-relationship-path="table3s"/>
      <obj-relationship name="table2s" source="Table1" target="Table2" deleteRule="Deny" db-relationship-path="table2s"/>
      <obj-relationship name="table1" source="Table2" target="Table1" deleteRule="Nullify" db-relationship-path="table1"/>
+    <obj-relationship name="table1" source="Table3" target="Table1" deleteRule="Nullify" db-relationship-path="table1"/>
 </data-map>
\ No newline at end of file
diff --git a/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewRelationship.sql b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewRelationship.sql
index 81115f9..7c667e5 100644
--- a/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewRelationship.sql
+++ b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewRelationship.sql
@@ -29,5 +29,13 @@ CREATE TABLE schema_01.table2 (
     t2_name VARCHAR (45),
     table1_id INTEGER  NOT NULL,
     PRIMARY KEY (id),
-    CONSTRAINT fk_address FOREIGN KEY (table1_id) REFERENCES schema_01.table1 (id)
+    CONSTRAINT fk_table2_table1_id FOREIGN KEY (table1_id) REFERENCES schema_01.table1 (id)
+);
+
+CREATE TABLE schema_01.table3 (
+    id INTEGER  NOT NULL,
+    t3_name VARCHAR (45),
+    table1_id INTEGER  NOT NULL,
+    PRIMARY KEY (id),
+    CONSTRAINT fk_table3_table1_id FOREIGN KEY (table1_id) REFERENCES schema_01.table1 (id)
 );
\ No newline at end of file