Repository: cayenne Updated Branches: refs/heads/master 43978ffcc -> f7f33b557
CAY-2113 cdbimport: Reverse-engineering reinstates previously ignored columns * unit test to reproduce Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/d58f7221 Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/d58f7221 Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/d58f7221 Branch: refs/heads/master Commit: d58f7221f54fd4ec4b692e8172ebad700df6e66d Parents: 43978ff Author: Andrus Adamchik <and...@objectstyle.com> Authored: Wed Sep 28 16:45:56 2016 +0300 Committer: Andrus Adamchik <and...@objectstyle.com> Committed: Wed Sep 28 17:12:10 2016 +0300 ---------------------------------------------------------------------- .../cayenne/tools/DbImporterMojoTest.java | 12 ++++++ .../testPreserveCustomObjMappings-pom.xml | 43 ++++++++++++++++++++ .../testPreserveCustomObjMappings.map.xml | 33 +++++++++++++++ ...testPreserveCustomObjMappings.map.xml-result | 35 ++++++++++++++++ .../dbimport/testPreserveCustomObjMappings.sql | 28 +++++++++++++ 5 files changed, 151 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cayenne/blob/d58f7221/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 7f60aa1..1f0ed60 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 @@ -160,6 +160,18 @@ public class DbImporterMojoTest extends AbstractMojoTestCase { test("testOneToOne"); } + /** + * Q: what happens if an attribute or relationship is unmapped in the object layer, but then the underlying table + * changes. + * A: it should not recreate unmapped attributes/relationships. Only add an attribute for the new column. + * + * @throws Exception + */ + @Test + public void testPreserveCustomObjMappings() throws Exception { + test("testPreserveCustomObjMappings"); + } + /** * 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 http://git-wip-us.apache.org/repos/asf/cayenne/blob/d58f7221/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveCustomObjMappings-pom.xml ---------------------------------------------------------------------- diff --git a/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveCustomObjMappings-pom.xml b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveCustomObjMappings-pom.xml new file mode 100644 index 0000000..1dc63ea --- /dev/null +++ b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveCustomObjMappings-pom.xml @@ -0,0 +1,43 @@ +<?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/testPreserveCustomObjMappings.map.xml</map> + <driver>org.apache.derby.jdbc.EmbeddedDriver</driver> + <url>jdbc:derby:memory:DbImporterMojoTest;create=true</url> + + <schema> + <name>SCHEMA_01</name> + </schema> + </configuration> + </plugin> + </plugins> + </build> + +</project> http://git-wip-us.apache.org/repos/asf/cayenne/blob/d58f7221/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveCustomObjMappings.map.xml ---------------------------------------------------------------------- diff --git a/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveCustomObjMappings.map.xml b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveCustomObjMappings.map.xml new file mode 100644 index 0000000..93f6b27 --- /dev/null +++ b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveCustomObjMappings.map.xml @@ -0,0 +1,33 @@ +<?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/8/modelMap" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://cayenne.apache.org/schema/8/modelMap http://cayenne.apache.org/schema/8/modelMap.xsd" + project-version="8"> + <property name="defaultSchema" value="SCHEMA_01"/> + <db-entity name="PARENT" schema="SCHEMA_01"> + <db-attribute name="COL2" type="CHAR" length="25"/> + <db-attribute name="COL3" type="DECIMAL" length="10" scale="2"/> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + </db-entity> + <obj-entity name="Parent" className="Parent" dbEntityName="PARENT"> + <obj-attribute name="col2" type="java.lang.String" db-attribute-path="COL2"/> + </obj-entity> +</data-map> http://git-wip-us.apache.org/repos/asf/cayenne/blob/d58f7221/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveCustomObjMappings.map.xml-result ---------------------------------------------------------------------- diff --git a/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveCustomObjMappings.map.xml-result b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveCustomObjMappings.map.xml-result new file mode 100644 index 0000000..7c8036d --- /dev/null +++ b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveCustomObjMappings.map.xml-result @@ -0,0 +1,35 @@ +<?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/8/modelMap" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://cayenne.apache.org/schema/8/modelMap http://cayenne.apache.org/schema/8/modelMap.xsd" + project-version="8"> + <property name="defaultSchema" value="SCHEMA_01"/> + <db-entity name="PARENT" schema="SCHEMA_01"> + <db-attribute name="COL2" type="CHAR" length="25"/> + <db-attribute name="COL3" type="DECIMAL" length="10" scale="2"/> + <db-attribute name="COL4" type="VARCHAR" length="25"/> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + </db-entity> + <obj-entity name="Parent" className="Parent" dbEntityName="PARENT"> + <obj-attribute name="col2" type="java.lang.String" db-attribute-path="COL2"/> + <obj-attribute name="col4" type="java.lang.String" db-attribute-path="COL4"/> + </obj-entity> +</data-map> http://git-wip-us.apache.org/repos/asf/cayenne/blob/d58f7221/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveCustomObjMappings.sql ---------------------------------------------------------------------- diff --git a/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveCustomObjMappings.sql b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveCustomObjMappings.sql new file mode 100644 index 0000000..32be3a5 --- /dev/null +++ b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testPreserveCustomObjMappings.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 SCHEMA schema_01; +SET SCHEMA schema_01; + +CREATE TABLE schema_01.Parent ( + id INTEGER NOT NULL, + COL2 CHAR(25), + COL3 DECIMAL(10,2), + COL4 VARCHAR(25), + + PRIMARY KEY (id) + ); \ No newline at end of file