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-2321 Reverse relationship is not created after adding and rev engineeering new db table
Date Wed, 07 Jun 2017 15:00:58 GMT
Repository: cayenne
Updated Branches:
  refs/heads/STABLE-4.0 43d2ae652 -> b9e7fd974


CAY-2321 Reverse relationship is not created after adding and rev engineeering new db table


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

Branch: refs/heads/STABLE-4.0
Commit: e37312da20cd8f049dd0e4307a48aee82d583093
Parents: c299812
Author: Anton Dreka <drekoas@gmail.com>
Authored: Wed Jun 7 13:50:41 2017 +0300
Committer: Anton Dreka <drekoas@gmail.com>
Committed: Wed Jun 7 13:50:41 2017 +0300

----------------------------------------------------------------------
 .../dbsync/merge/DbRelationshipMerger.java      | 10 ++--
 .../cayenne/tools/DbImporterMojoTest.java       |  5 ++
 .../dbimport/testImportNewRelationship-pom.xml  | 44 ++++++++++++++++++
 .../dbimport/testImportNewRelationship.map.xml  | 32 +++++++++++++
 .../testImportNewRelationship.map.xml-result    | 48 ++++++++++++++++++++
 .../dbimport/testImportNewRelationship.sql      | 33 ++++++++++++++
 6 files changed, 168 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/e37312da/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbRelationshipMerger.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbRelationshipMerger.java
b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbRelationshipMerger.java
index 46b90a5..73644b4 100644
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbRelationshipMerger.java
+++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbRelationshipMerger.java
@@ -25,7 +25,6 @@ import java.util.List;
 
 import org.apache.cayenne.dbsync.merge.factory.MergerTokenFactory;
 import org.apache.cayenne.dbsync.merge.token.MergerToken;
-import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbJoin;
@@ -69,12 +68,11 @@ public class DbRelationshipMerger extends AbstractMerger<DbEntity,
DbRelationshi
         DbEntity originalDbEntity = getOriginalSourceDbEntity(imported);
         DbEntity targetEntity = getOriginalTargetDbEntity(imported);
 
-        if (targetEntity == null) {
-            return null;
+        if (targetEntity != null) {
+            imported.setTargetEntityName(targetEntity);
         }
 
         imported.setSourceEntity(originalDbEntity);
-        imported.setTargetEntityName(targetEntity);
 
         // manipulate the joins to match the DbAttributes in the model
         for (DbJoin join : imported.getJoins()) {
@@ -121,6 +119,10 @@ public class DbRelationshipMerger extends AbstractMerger<DbEntity,
DbRelationshi
      * by name
      */
     private DbAttribute findDbAttribute(DbEntity entity, String caseInsensitiveName) {
+        if (entity == null) {
+            return null;
+        }
+
         for (DbAttribute a : entity.getAttributes()) {
             if (a.getName().equalsIgnoreCase(caseInsensitiveName)) {
                 return a;

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e37312da/maven-plugins/cayenne-maven-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoTest.java
----------------------------------------------------------------------
diff --git a/maven-plugins/cayenne-maven-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoTest.java
b/maven-plugins/cayenne-maven-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoTest.java
index 5d446fd..d3ac706 100644
--- a/maven-plugins/cayenne-maven-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoTest.java
+++ b/maven-plugins/cayenne-maven-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoTest.java
@@ -109,6 +109,11 @@ public class DbImporterMojoTest extends AbstractMojoTestCase {
     }
 
     @Test
+    public void testImportNewRelationship() throws Exception {
+        test("testImportNewRelationship");
+    }
+
+    @Test
     public void testImportWithoutChanges() throws Exception {
         test("testImportWithoutChanges");
     }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e37312da/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewRelationship-pom.xml
----------------------------------------------------------------------
diff --git a/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewRelationship-pom.xml
b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewRelationship-pom.xml
new file mode 100644
index 0000000..263280b
--- /dev/null
+++ b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewRelationship-pom.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+  ~   Licensed to the Apache Software Foundation (ASF) under one
+  ~  or more contributor license agreements.  See the NOTICE file
+  ~  distributed with this work for additional information
+  ~  regarding copyright ownership.  The ASF licenses this file
+  ~  to you under the Apache License, Version 2.0 (the
+  ~  "License"); you may not use this file except in compliance
+  ~  with the License.  You may obtain a copy of the License at
+  ~
+  ~    http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~  Unless required by applicable law or agreed to in writing,
+  ~  software distributed under the License is distributed on an
+  ~  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~  KIND, either express or implied.  See the License for the
+  ~  specific language governing permissions and limitations
+  ~  under the License.
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+	http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <name>DbImporterMojo Test1</name>
+
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>cayenne-maven-plugin</artifactId>
+                <configuration>
+                    <map>target/test-classes/org/apache/cayenne/tools/dbimport/testImportNewRelationship.map.xml</map>
+                    <dataSource>
+                        <driver>org.apache.derby.jdbc.EmbeddedDriver</driver>
+                        <url>jdbc:derby:memory:DbImporterMojoTest;create=true</url>
+                    </dataSource>
+                    <dbimport>
+                        <schema>SCHEMA_01</schema>
+                    </dbimport>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e37312da/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewRelationship.map.xml
----------------------------------------------------------------------
diff --git a/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewRelationship.map.xml
b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewRelationship.map.xml
new file mode 100644
index 0000000..73043b1
--- /dev/null
+++ b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewRelationship.map.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+	Licensed to the Apache Software Foundation (ASF) under one
+	or more contributor license agreements.  See the NOTICE file
+	distributed with this work for additional information
+	regarding copyright ownership.  The ASF licenses this file
+	to you under the Apache License, Version 2.0 (the
+	"License"); you may not use this file except in compliance
+	with the License.  You may obtain a copy of the License at
+
+	http://www.apache.org/licenses/LICENSE-2.0
+
+	Unless required by applicable law or agreed to in writing,
+	software distributed under the License is distributed on an
+	"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+	KIND, either express or implied.  See the License for the
+	specific language governing permissions and limitations
+	under the License.
+-->
+<data-map xmlns="http://cayenne.apache.org/schema/9/modelMap"
+          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+          xsi:schemaLocation="http://cayenne.apache.org/schema/9/modelMap http://cayenne.apache.org/schema/9/modelMap.xsd"
+          project-version="9">
+    <property name="defaultSchema" value="SCHEMA_01"/>
+    <db-entity name="TABLE1" schema="SCHEMA_01">
+        <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"
length="10"/>
+        <db-attribute name="T1_NAME" type="VARCHAR" length="45"/>
+    </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>
+</data-map>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e37312da/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewRelationship.map.xml-result
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..5daeef7
--- /dev/null
+++ b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewRelationship.map.xml-result
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+  ~   Licensed to the Apache Software Foundation (ASF) under one
+  ~  or more contributor license agreements.  See the NOTICE file
+  ~  distributed with this work for additional information
+  ~  regarding copyright ownership.  The ASF licenses this file
+  ~  to you under the Apache License, Version 2.0 (the
+  ~  "License"); you may not use this file except in compliance
+  ~  with the License.  You may obtain a copy of the License at
+  ~
+  ~    http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~  Unless required by applicable law or agreed to in writing,
+  ~  software distributed under the License is distributed on an
+  ~  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~  KIND, either express or implied.  See the License for the
+  ~  specific language governing permissions and limitations
+  ~  under the License.
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+<data-map xmlns="http://cayenne.apache.org/schema/9/modelMap"
+	 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	 xsi:schemaLocation="http://cayenne.apache.org/schema/9/modelMap http://cayenne.apache.org/schema/9/modelMap.xsd"
+	 project-version="9">
+	 <property name="defaultSchema" value="SCHEMA_01"/>
+	 <db-entity name="TABLE1" schema="SCHEMA_01">
+    		<db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/>
+    		<db-attribute name="T1_NAME" type="VARCHAR" length="45"/>
+     </db-entity>
+     <db-entity name="TABLE2" schema="SCHEMA_01">
+        <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"
length="10"/>
+        <db-attribute name="T2_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>
+     <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>
+     <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"/>
+</data-map>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e37312da/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewRelationship.sql
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..81115f9
--- /dev/null
+++ b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewRelationship.sql
@@ -0,0 +1,33 @@
+--  Licensed to the Apache Software Foundation (ASF) under one
+--  or more contributor license agreements.  See the NOTICE file
+--  distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+--  to you under the Apache License, Version 2.0 (the
+--  "License"); you may not use this file except in compliance
+--  with the License.  You may obtain a copy of the License at
+--
+--    http://www.apache.org/licenses/LICENSE-2.0
+--
+--  Unless required by applicable law or agreed to in writing,
+--  software distributed under the License is distributed on an
+--  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+--  KIND, either express or implied.  See the License for the
+--  specific language governing permissions and limitations
+--  under the License.
+
+CREATE SCHEMA schema_01;
+SET SCHEMA schema_01;
+
+CREATE TABLE schema_01.table1 (
+    id INTEGER  NOT NULL,
+    t1_name VARCHAR (45),
+    PRIMARY KEY (id)
+);
+
+CREATE TABLE schema_01.table2 (
+    id INTEGER  NOT NULL,
+    t2_name VARCHAR (45),
+    table1_id INTEGER  NOT NULL,
+    PRIMARY KEY (id),
+    CONSTRAINT fk_address FOREIGN KEY (table1_id) REFERENCES schema_01.table1 (id)
+);
\ No newline at end of file


Mime
View raw message