Q: what happens if a relationship existed over a column that was later deleted? and âskipRelLoadingâ is true A: it should remove relationship and column
Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/3eaed4ae Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/3eaed4ae Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/3eaed4ae Branch: refs/heads/master Commit: 3eaed4ae6a89d17f9f3df61d6e9b141a37e48002 Parents: 3037c5e Author: alexkolonitsky <alex.kolonit...@gmail.com> Authored: Wed Dec 10 14:41:02 2014 +0300 Committer: alexkolonitsky <alex.kolonit...@gmail.com> Committed: Wed Dec 10 14:41:02 2014 +0300 ---------------------------------------------------------------------- .../cayenne/tools/DbImporterMojoTest.java | 9 ++++ .../dbimport/testPreserveRelationships-pom.xml | 44 ++++++++++++++++++++ .../dbimport/testPreserveRelationships.map.xml | 44 ++++++++++++++++++++ .../testPreserveRelationships.map.xml-result | 34 +++++++++++++++ .../dbimport/testPreserveRelationships.sql | 28 +++++++++++++ 5 files changed, 159 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cayenne/blob/3eaed4ae/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 9066150..0f5b6f6 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 @@ -116,6 +116,15 @@ public class DbImporterMojoTest extends AbstractMojoTestCase { test("testSkipRelationshipsLoading"); } + /** + * what happens if a relationship existed over a column that was later deleted? and âskipRelLoadingâ is true + * + * @throws Exception + */ + public void testPreserveRelationships() throws Exception { + test("testPreserveRelationships"); + } + private void test(String name) throws Exception { DbImporterMojo cdbImport = getCdbImport("dbimport/" + name + "-pom.xml"); File mapFile = cdbImport.getMap(); http://git-wip-us.apache.org/repos/asf/cayenne/blob/3eaed4ae/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveRelationships-pom.xml ---------------------------------------------------------------------- diff --git a/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveRelationships-pom.xml b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveRelationships-pom.xml new file mode 100644 index 0000000..038044a --- /dev/null +++ b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveRelationships-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>maven-cayenne-plugin</artifactId> + <configuration> + <map>target/test-classes/org/apache/cayenne/tools/dbimport/testPreserveRelationships.map.xml</map> + <driver>org.apache.derby.jdbc.EmbeddedDriver</driver> + <url>jdbc:derby:memory:DbImporterMojoTest;create=true</url> + + <reverseEngineering> + <!-- it doesn't matter true or false, but initial question was about this flag --> + <skipRelationshipsLoading>true</skipRelationshipsLoading> + </reverseEngineering> + </configuration> + </plugin> + </plugins> + </build> + +</project> http://git-wip-us.apache.org/repos/asf/cayenne/blob/3eaed4ae/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveRelationships.map.xml ---------------------------------------------------------------------- diff --git a/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveRelationships.map.xml b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveRelationships.map.xml new file mode 100644 index 0000000..4ca0886 --- /dev/null +++ b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveRelationships.map.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. + --> +<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"> + <db-entity name="CHILD" schema="APP"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + <db-attribute name="PARENT_ID" type="INTEGER" length="10"/> + </db-entity> + <db-entity name="PARENT" schema="APP"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + </db-entity> + <obj-entity name="Child" className="Child" dbEntityName="CHILD"> + <obj-attribute name="parentId" type="java.lang.Integer" db-attribute-path="PARENT_ID"/> + </obj-entity> + <obj-entity name="Parent" className="Parent" dbEntityName="PARENT"> + </obj-entity> + <db-relationship name="toParent" source="CHILD" target="PARENT" toMany="false"> + <db-attribute-pair source="PARENT_ID" target="ID"/> + </db-relationship> + <db-relationship name="toParent" source="PARENT" target="CHILD" toMany="false"> + <db-attribute-pair source="ID" target="PARENT_ID"/> + </db-relationship> + <obj-relationship name="toParent" source="Child" target="Parent" deleteRule="Nullify" db-relationship-path="toParent"/> + <obj-relationship name="toParent" source="Parent" target="Child" deleteRule="Nullify" db-relationship-path="toParent"/> +</data-map> http://git-wip-us.apache.org/repos/asf/cayenne/blob/3eaed4ae/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveRelationships.map.xml-result ---------------------------------------------------------------------- diff --git a/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveRelationships.map.xml-result b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveRelationships.map.xml-result new file mode 100644 index 0000000..aad5d5b --- /dev/null +++ b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveRelationships.map.xml-result @@ -0,0 +1,34 @@ +<?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"> + <db-entity name="CHILD" schema="APP"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + </db-entity> + <db-entity name="PARENT" schema="APP"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + </db-entity> + <obj-entity name="Child" className="Child" dbEntityName="CHILD"> + </obj-entity> + <obj-entity name="Parent" className="Parent" dbEntityName="PARENT"> + </obj-entity> +</data-map> http://git-wip-us.apache.org/repos/asf/cayenne/blob/3eaed4ae/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveRelationships.sql ---------------------------------------------------------------------- diff --git a/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveRelationships.sql b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveRelationships.sql new file mode 100644 index 0000000..86b26bc --- /dev/null +++ b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveRelationships.sql @@ -0,0 +1,28 @@ +-- 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.Parent ( + id INTEGER NOT NULL, + + PRIMARY KEY (id) +); + +CREATE TABLE APP.Child ( + id INTEGER NOT NULL, + + PRIMARY KEY (id) +); \ No newline at end of file