Repository: cayenne Updated Branches: refs/heads/master 88613547f -> 2b7a21b5b
CAY-2135 cdbimport: reset DbEntity catalogs / schemas to DataMap defaults Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/2b7a21b5 Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/2b7a21b5 Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/2b7a21b5 Branch: refs/heads/master Commit: 2b7a21b5b94826dc53ec2748929508086df42dd0 Parents: 8861354 Author: Andrus Adamchik <[email protected]> Authored: Tue Nov 8 14:15:39 2016 +0300 Committer: Andrus Adamchik <[email protected]> Committed: Tue Nov 8 14:32:01 2016 +0300 ---------------------------------------------------------------------- .../apache/cayenne/tools/DbImporterTask.java | 12 +++++ .../tools/dbimport/DbImportConfiguration.java | 18 +++++++ .../tools/dbimport/DefaultDbImportAction.java | 25 ++++++++++ docs/doc/src/main/resources/RELEASE-NOTES.txt | 1 + .../apache/cayenne/tools/DbImporterMojo.java | 26 +++++++--- .../cayenne/tools/DbImporterMojoTest.java | 15 ++++-- .../dbimport/testForceDataMapSchema-pom.xml | 46 +++++++++++++++++ .../dbimport/testForceDataMapSchema.map.xml | 26 ++++++++++ .../testForceDataMapSchema.map.xml-result | 52 ++++++++++++++++++++ .../tools/dbimport/testForceDataMapSchema.sql | 40 +++++++++++++++ 10 files changed, 249 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cayenne/blob/2b7a21b5/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbImporterTask.java ---------------------------------------------------------------------- diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbImporterTask.java b/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbImporterTask.java index d9bdd5e..c8484f7 100644 --- a/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbImporterTask.java +++ b/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbImporterTask.java @@ -224,6 +224,18 @@ public class DbImporterTask extends Task { config.setUsername(username); } + public void setUsePrimitives(boolean flag) { + config.setUsePrimitives(flag); + } + + public void setForceDataMapCatalog(boolean flag) { + config.setForceDataMapCatalog(flag); + } + + public void setForceDataMapSchema(boolean flag) { + config.setForceDataMapSchema(flag); + } + public ReverseEngineering getReverseEngineering() { return reverseEngineering; } http://git-wip-us.apache.org/repos/asf/cayenne/blob/2b7a21b5/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DbImportConfiguration.java ---------------------------------------------------------------------- diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DbImportConfiguration.java b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DbImportConfiguration.java index 9bf4ed1..681d353 100644 --- a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DbImportConfiguration.java +++ b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DbImportConfiguration.java @@ -58,6 +58,8 @@ public class DbImportConfiguration { private Log logger; private String namingStrategy; private String stripFromTableNames; + private boolean forceDataMapCatalog; + private boolean forceDataMapSchema; public DbImportConfiguration() { this.dataSourceInfo = new DataSourceInfo(); @@ -281,4 +283,20 @@ public class DbImportConfiguration { public void setTableTypes(String[] tableTypes) { dbLoaderConfiguration.setTableTypes(tableTypes); } + + public void setForceDataMapCatalog(boolean forceDataMapCatalog) { + this.forceDataMapCatalog = forceDataMapCatalog; + } + + public boolean isForceDataMapCatalog() { + return forceDataMapCatalog; + } + + public void setForceDataMapSchema(boolean forceDataMapSchema) { + this.forceDataMapSchema = forceDataMapSchema; + } + + public boolean isForceDataMapSchema() { + return forceDataMapSchema; + } } http://git-wip-us.apache.org/repos/asf/cayenne/blob/2b7a21b5/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DefaultDbImportAction.java ---------------------------------------------------------------------- diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DefaultDbImportAction.java b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DefaultDbImportAction.java index 1ae9533..bdf6e8d 100644 --- a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DefaultDbImportAction.java +++ b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DefaultDbImportAction.java @@ -42,6 +42,7 @@ import org.apache.cayenne.dbsync.reverse.filters.FiltersConfig; import org.apache.cayenne.dbsync.reverse.filters.PatternFilter; import org.apache.cayenne.di.Inject; import org.apache.cayenne.map.DataMap; +import org.apache.cayenne.map.DbEntity; import org.apache.cayenne.map.EntityResolver; import org.apache.cayenne.map.MapLoader; import org.apache.cayenne.map.ObjEntity; @@ -172,6 +173,9 @@ public class DefaultDbImportAction implements DbImportAction { targetDataMap = newTargetDataMap(config); } + // transform source DataMap before merging + transformSourceBeforeMerge(sourceDataMap, targetDataMap, config); + MergerTokenFactory mergerTokenFactory = mergerTokenFactoryProvider.get(adapter); DbLoaderConfiguration loaderConfig = config.getDbLoaderConfig(); @@ -196,6 +200,27 @@ public class DefaultDbImportAction implements DbImportAction { } } + + protected void transformSourceBeforeMerge(DataMap sourceDataMap, + DataMap targetDataMap, + DbImportConfiguration configuration) { + + if (configuration.isForceDataMapCatalog()) { + String catalog = targetDataMap.getDefaultCatalog(); + for (DbEntity e : sourceDataMap.getDbEntities()) { + e.setCatalog(catalog); + } + } + + if (configuration.isForceDataMapSchema()) { + String schema = targetDataMap.getDefaultSchema(); + for (DbEntity e : sourceDataMap.getDbEntities()) { + e.setSchema(schema); + } + } + + } + private boolean syncDataMapProperties(DataMap targetDataMap, DbImportConfiguration config) { String defaultPackage = config.getDefaultPackage(); http://git-wip-us.apache.org/repos/asf/cayenne/blob/2b7a21b5/docs/doc/src/main/resources/RELEASE-NOTES.txt ---------------------------------------------------------------------- diff --git a/docs/doc/src/main/resources/RELEASE-NOTES.txt b/docs/doc/src/main/resources/RELEASE-NOTES.txt index bb9c6f3..db5c839 100644 --- a/docs/doc/src/main/resources/RELEASE-NOTES.txt +++ b/docs/doc/src/main/resources/RELEASE-NOTES.txt @@ -40,6 +40,7 @@ CAY-2129 Modeler: reengineer dialog improvements CAY-2130 Stripping common name prefixes on reverse engineering CAY-2132 Adding SybaseSelectTranslator to support TOP/DISTINCT TOP in limited queries CAY-2133 ObjectNameGenerator refactoring - unifying relationship name generation +CAY-2135 cdbimport: reset DbEntity catalogs / schemas to DataMap defaults Bug Fixes: http://git-wip-us.apache.org/repos/asf/cayenne/blob/2b7a21b5/plugins/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java ---------------------------------------------------------------------- diff --git a/plugins/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java b/plugins/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java index 3ba39f3..bf0252b 100644 --- a/plugins/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java +++ b/plugins/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java @@ -78,6 +78,16 @@ public class DbImporterMojo extends AbstractMojo { private String driver; /** + * @parameter forceDataMapCatalog="forceDataMapCatalog" default-value="false" + */ + private boolean forceDataMapCatalog; + + /** + * @parameter forceDataMapSchema="forceDataMapSchema" default-value="false" + */ + private boolean forceDataMapSchema; + + /** * DataMap XML file to use as a base for DB importing. * * @parameter map="map" @@ -200,19 +210,21 @@ public class DbImporterMojo extends AbstractMojo { config.setAdapter(adapter); config.setDefaultPackage(defaultPackage); config.setDriver(driver); - config.setTargetDataMap(map); + config.setFiltersConfig(new FiltersConfigBuilder(reverseEngineering).build()); + config.setForceDataMapCatalog(forceDataMapCatalog); + config.setForceDataMapSchema(forceDataMapSchema); + config.setLogger(logger); config.setMeaningfulPkTables(meaningfulPkTables); config.setNamingStrategy(namingStrategy); - config.setStripFromTableNames(stripFromTableNames); config.setPassword(password); - config.setUrl(url); - config.setUsername(username); - config.setUsePrimitives(usePrimitives); - config.setFiltersConfig(new FiltersConfigBuilder(reverseEngineering).build()); config.setSkipRelationshipsLoading(reverseEngineering.getSkipRelationshipsLoading()); config.setSkipPrimaryKeyLoading(reverseEngineering.getSkipPrimaryKeyLoading()); + config.setStripFromTableNames(stripFromTableNames); config.setTableTypes(reverseEngineering.getTableTypes()); - config.setLogger(logger); + config.setTargetDataMap(map); + config.setUrl(url); + config.setUsername(username); + config.setUsePrimitives(usePrimitives); return config; } http://git-wip-us.apache.org/repos/asf/cayenne/blob/2b7a21b5/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 94d16fe..bbe88cd 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 @@ -192,12 +192,17 @@ public class DbImporterMojoTest extends AbstractMojoTestCase { test("testUnFlattensManyToMany"); } - /** - * Make sure any merges preserve custom object layer settings, like "usePrimitives", PK mapping as attribute, etc. - */ + /** + * Make sure any merges preserve custom object layer settings, like "usePrimitives", PK mapping as attribute, etc. + */ + @Test + public void testCustomObjectLayerSettings() throws Exception { + test("testCustomObjectLayerSettings"); + } + @Test - public void testCustomObjectLayerSettings() throws Exception { - test("testCustomObjectLayerSettings"); + public void testForceDataMapSchema() throws Exception { + test("testForceDataMapSchema"); } /** http://git-wip-us.apache.org/repos/asf/cayenne/blob/2b7a21b5/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testForceDataMapSchema-pom.xml ---------------------------------------------------------------------- diff --git a/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testForceDataMapSchema-pom.xml b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testForceDataMapSchema-pom.xml new file mode 100644 index 0000000..ca3d419 --- /dev/null +++ b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testForceDataMapSchema-pom.xml @@ -0,0 +1,46 @@ +<?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/testForceDataMapSchema.map.xml</map> + <defaultPackage>com.example.test</defaultPackage> + <driver>org.apache.derby.jdbc.EmbeddedDriver</driver> + <url>jdbc:derby:memory:DbImporterMojoTest;create=true</url> + <forceDataMapCatalog>true</forceDataMapCatalog> + <forceDataMapSchema>true</forceDataMapSchema> + + <reverseEngineering> + <schema>SCHEMA_01</schema> + </reverseEngineering> + </configuration> + </plugin> + </plugins> + </build> + +</project> http://git-wip-us.apache.org/repos/asf/cayenne/blob/2b7a21b5/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testForceDataMapSchema.map.xml ---------------------------------------------------------------------- diff --git a/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testForceDataMapSchema.map.xml b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testForceDataMapSchema.map.xml new file mode 100644 index 0000000..1d9dea0 --- /dev/null +++ b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testForceDataMapSchema.map.xml @@ -0,0 +1,26 @@ +<?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="defaultPackage" value="com.example.test"/> + <property name="defaultCatalog" value="XCATALOG"/> +</data-map> http://git-wip-us.apache.org/repos/asf/cayenne/blob/2b7a21b5/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testForceDataMapSchema.map.xml-result ---------------------------------------------------------------------- diff --git a/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testForceDataMapSchema.map.xml-result b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testForceDataMapSchema.map.xml-result new file mode 100644 index 0000000..0eaaffd --- /dev/null +++ b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testForceDataMapSchema.map.xml-result @@ -0,0 +1,52 @@ +<?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="defaultPackage" value="com.example.test"/> + <property name="defaultCatalog" value="XCATALOG"/> + <db-entity name="CHILD" catalog="XCATALOG"> + <db-attribute name="COL3" type="DECIMAL" length="10" scale="2"/> + <db-attribute name="COL4" type="VARCHAR" length="25"/> + <db-attribute name="COL5" type="DATE" length="10"/> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + <db-attribute name="PARENT_ID" type="CHAR" length="25"/> + </db-entity> + <db-entity name="PARENT" catalog="XCATALOG"> + <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="COL5" type="DATE" length="10"/> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + </db-entity> + <obj-entity name="Child" className="com.example.test.Child" dbEntityName="CHILD"> + <obj-attribute name="col3" type="java.math.BigDecimal" db-attribute-path="COL3"/> + <obj-attribute name="col4" type="java.lang.String" db-attribute-path="COL4"/> + <obj-attribute name="col5" type="java.util.Date" db-attribute-path="COL5"/> + <obj-attribute name="parentId" type="java.lang.String" db-attribute-path="PARENT_ID"/> + </obj-entity> + <obj-entity name="Parent" className="com.example.test.Parent" dbEntityName="PARENT"> + <obj-attribute name="col2" type="java.lang.String" db-attribute-path="COL2"/> + <obj-attribute name="col3" type="java.math.BigDecimal" db-attribute-path="COL3"/> + <obj-attribute name="col4" type="java.lang.String" db-attribute-path="COL4"/> + <obj-attribute name="col5" type="java.util.Date" db-attribute-path="COL5"/> + </obj-entity> +</data-map> http://git-wip-us.apache.org/repos/asf/cayenne/blob/2b7a21b5/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testForceDataMapSchema.sql ---------------------------------------------------------------------- diff --git a/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testForceDataMapSchema.sql b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testForceDataMapSchema.sql new file mode 100644 index 0000000..279065c --- /dev/null +++ b/plugins/maven-cayenne-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testForceDataMapSchema.sql @@ -0,0 +1,40 @@ +-- 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), + COL5 DATE, + + PRIMARY KEY (id), + UNIQUE (COL3) +); + +CREATE TABLE schema_01.Child ( + id INTEGER NOT NULL, + Parent_id CHAR(25), + COL3 DECIMAL(10,2), + COL4 VARCHAR(25), + COL5 DATE, + + PRIMARY KEY (id) +);
