You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by ko...@apache.org on 2015/10/12 21:26:30 UTC

[1/2] cayenne git commit: fix issue with flatten many-to-many relationship table to itself

Repository: cayenne
Updated Branches:
  refs/heads/master 3a412a4aa -> 727f9de4d


fix issue with flatten many-to-many relationship table to itself


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

Branch: refs/heads/master
Commit: 1196d0bfe05682e7c6667adfeafe815c62a4a8b7
Parents: 58c7c3b
Author: kolonitsky <Al...@gmail.com>
Authored: Mon Oct 12 22:12:55 2015 +0300
Committer: kolonitsky <Al...@gmail.com>
Committed: Mon Oct 12 22:12:55 2015 +0300

----------------------------------------------------------------------
 .../loader/ManyToManyCandidateEntity.java       |  2 +-
 .../cayenne/tools/DbImporterMojoTest.java       | 28 ++++++++++++
 ...tFlattensManyToManyWithRecursiveLink-pom.xml | 40 ++++++++++++++++
 ...nsManyToManyWithRecursiveLink.map.xml-result | 48 ++++++++++++++++++++
 .../testFlattensManyToManyWithRecursiveLink.sql | 31 +++++++++++++
 5 files changed, 148 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/1196d0bf/cayenne-server/src/main/java/org/apache/cayenne/access/loader/ManyToManyCandidateEntity.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/loader/ManyToManyCandidateEntity.java b/cayenne-server/src/main/java/org/apache/cayenne/access/loader/ManyToManyCandidateEntity.java
index b1d96f9..6b93f19 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/loader/ManyToManyCandidateEntity.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/loader/ManyToManyCandidateEntity.java
@@ -90,7 +90,7 @@ public class ManyToManyCandidateEntity {
         return isNotHaveAttributes
                 && reverseRelationship1 != null && reverseRelationship1.isToDependentPK()
                 && reverseRelationship2 != null && reverseRelationship2.isToDependentPK()
-                && entity1 != null && entity2 != null && !entity1.equals(entity2);
+                && entity1 != null && entity2 != null;
     }
 
     private void addFlattenedRelationship(ObjectNameGenerator nameGenerator, ObjEntity srcEntity, ObjEntity dstEntity,

http://git-wip-us.apache.org/repos/asf/cayenne/blob/1196d0bf/plugins/maven-cayenne-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoTest.java
----------------------------------------------------------------------
diff --git a/plugins/maven-cayenne-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoTest.java b/plugins/maven-cayenne-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoTest.java
index d64fa47..ff19dcb 100644
--- a/plugins/maven-cayenne-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoTest.java
+++ b/plugins/maven-cayenne-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoTest.java
@@ -33,6 +33,7 @@ import org.custommonkey.xmlunit.ElementNameAndAttributeQualifier;
 import org.custommonkey.xmlunit.XMLUnit;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.xml.sax.SAXException;
 
@@ -154,6 +155,7 @@ public class DbImporterMojoTest extends AbstractMojoTestCase {
 		test("testSkipPrimaryKeyLoading");
 	}
 
+    @Test
 	public void testOneToOne() throws Exception {
 		test("testOneToOne");
 	}
@@ -180,6 +182,32 @@ public class DbImporterMojoTest extends AbstractMojoTestCase {
 		test("testUnFlattensManyToMany");
 	}
 
+    /**
+     * CREATE TABLE APP.A (
+     *      id INTEGER NOT NULL,
+     *
+     *      PRIMARY KEY (id)
+     * );
+     *
+     * CREATE TABLE APP.A_A (
+     *      A1_ID INTEGER NOT NULL,
+     *      A2_ID INTEGER NOT NULL,
+     *
+     *      PRIMARY KEY (A1_ID, A2_ID),
+     *      CONSTRAINT A_A1 FOREIGN KEY (A1_ID) REFERENCES APP.A (ID),
+     *      CONSTRAINT A_A2 FOREIGN KEY (A2_ID) REFERENCES APP.A (ID)
+     * );
+     *
+     * If one table has many-to-many relationship with it self ObjEntity should have two
+     *  collection attributes in both directions
+     *
+     * @throws Exception
+     */
+    @Test
+	public void testFlattensManyToManyWithRecursiveLink() throws Exception {
+		test("testFlattensManyToManyWithRecursiveLink");
+	}
+
     @Test
     public void testFilteringConfig() throws Exception {
         DbImporterMojo cdbImport = getCdbImport("config/pom-01.xml");

http://git-wip-us.apache.org/repos/asf/cayenne/blob/1196d0bf/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testFlattensManyToManyWithRecursiveLink-pom.xml
----------------------------------------------------------------------
diff --git a/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testFlattensManyToManyWithRecursiveLink-pom.xml b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testFlattensManyToManyWithRecursiveLink-pom.xml
new file mode 100644
index 0000000..4e5b10b
--- /dev/null
+++ b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testFlattensManyToManyWithRecursiveLink-pom.xml
@@ -0,0 +1,40 @@
+<?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>maven-cayenne-plugin</artifactId>
+				<configuration>
+					<map>target/test-classes/org/apache/cayenne/tools/dbimport/testFlattensManyToManyWithRecursiveLink.map.xml</map>
+                    <driver>org.apache.derby.jdbc.EmbeddedDriver</driver>
+                    <url>jdbc:derby:memory:DbImporterMojoTest;create=true</url>
+                    <defaultPackage>org.not.my.home</defaultPackage>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+
+</project>

http://git-wip-us.apache.org/repos/asf/cayenne/blob/1196d0bf/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testFlattensManyToManyWithRecursiveLink.map.xml-result
----------------------------------------------------------------------
diff --git a/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testFlattensManyToManyWithRecursiveLink.map.xml-result b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testFlattensManyToManyWithRecursiveLink.map.xml-result
new file mode 100644
index 0000000..8480317
--- /dev/null
+++ b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testFlattensManyToManyWithRecursiveLink.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/7/modelMap"
+          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+          xsi:schemaLocation="http://cayenne.apache.org/schema/7/modelMap http://cayenne.apache.org/schema/7/modelMap.xsd"
+          project-version="7">
+    <property name="defaultPackage" value="org.not.my.home"/>
+    <db-entity name="A" schema="APP">
+        <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/>
+    </db-entity>
+    <db-entity name="A_A" schema="APP">
+        <db-attribute name="A1_ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/>
+        <db-attribute name="A2_ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/>
+    </db-entity>
+    <obj-entity name="A" className="org.not.my.home.A" dbEntityName="A">
+    </obj-entity>
+    <db-relationship name="aAArray" source="A" target="A_A" toDependentPK="true" toMany="true">
+        <db-attribute-pair source="ID" target="A2_ID"/>
+    </db-relationship>
+    <db-relationship name="aAArray1" source="A" target="A_A" toDependentPK="true" toMany="true">
+        <db-attribute-pair source="ID" target="A1_ID"/>
+    </db-relationship>
+    <db-relationship name="toA" source="A_A" target="A" toMany="false">
+        <db-attribute-pair source="A2_ID" target="ID"/>
+    </db-relationship>
+    <db-relationship name="toA1" source="A_A" target="A" toMany="false">
+        <db-attribute-pair source="A1_ID" target="ID"/>
+    </db-relationship>
+    <obj-relationship name="aArray" source="A" target="A" db-relationship-path="aAArray.toA1"/>
+    <obj-relationship name="aArray1" source="A" target="A" db-relationship-path="aAArray1.toA"/>
+</data-map>

http://git-wip-us.apache.org/repos/asf/cayenne/blob/1196d0bf/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testFlattensManyToManyWithRecursiveLink.sql
----------------------------------------------------------------------
diff --git a/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testFlattensManyToManyWithRecursiveLink.sql b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testFlattensManyToManyWithRecursiveLink.sql
new file mode 100644
index 0000000..9df54ab
--- /dev/null
+++ b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testFlattensManyToManyWithRecursiveLink.sql
@@ -0,0 +1,31 @@
+--  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 TABLE APP.A (
+  id INTEGER NOT NULL,
+
+  PRIMARY KEY (id)
+);
+
+CREATE TABLE APP.A_A (
+  A1_ID INTEGER NOT NULL,
+  A2_ID INTEGER NOT NULL,
+
+  PRIMARY KEY (A1_ID, A2_ID),
+  CONSTRAINT A_A1 FOREIGN KEY (A1_ID) REFERENCES APP.A (ID),
+  CONSTRAINT A_A2 FOREIGN KEY (A2_ID) REFERENCES APP.A (ID)
+);
\ No newline at end of file


[2/2] cayenne git commit: Merge branch 'master' of alex:apache/cayenne

Posted by ko...@apache.org.
Merge branch 'master' of alex:apache/cayenne


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

Branch: refs/heads/master
Commit: 727f9de4d60f3a0fdf103d4a47d6abc70a6c31b1
Parents: 1196d0b 3a412a4
Author: kolonitsky <Al...@gmail.com>
Authored: Mon Oct 12 22:21:21 2015 +0300
Committer: kolonitsky <Al...@gmail.com>
Committed: Mon Oct 12 22:21:21 2015 +0300

----------------------------------------------------------------------
 .../lifecycle/changemap/AttributeChange.java    |  2 +-
 .../changemap/MutableAttributeChange.java       |  5 ++++
 .../changemap/MutableObjectChange.java          | 21 ++++++++++++-
 .../MutableToManyRelationshipChange.java        |  5 ++++
 .../MutableToOneRelationshipChange.java         |  5 ++++
 .../lifecycle/changemap/ObjectChange.java       |  2 ++
 .../lifecycle/changemap/PropertyChange.java     | 29 ++++++++++++++++++
 .../changemap/PropertyChangeVisitor.java        | 31 ++++++++++++++++++++
 .../changemap/ToManyRelationshipChange.java     |  2 +-
 .../changemap/ToOneRelationshipChange.java      |  2 +-
 10 files changed, 100 insertions(+), 4 deletions(-)
----------------------------------------------------------------------