This is an automated email from the ASF dual-hosted git repository. abulatski pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/cayenne.git
commit 3de516755efe436577db2882a3cb8cdc080b5900 Author: Arseni Bulatski <ancars...@gmail.com> AuthorDate: Thu Jul 11 16:07:58 2019 +0300 CAY-2596 DbImport xml config changes after dbImport plugin task execution --- RELEASE-NOTES.txt | 3 +- .../reverse/dbimport/DefaultDbImportAction.java | 24 ++++++----- .../org/apache/cayenne/tools/DbImporterMojo.java | 13 +++--- .../apache/cayenne/tools/DbImporterMojoTest.java | 23 ++++++----- .../tools/dbimport/testConfigFromDataMap-pom.xml | 47 ++++++++++++++++++++++ .../tools/dbimport/testConfigFromDataMap.map.xml | 38 +++++++++++++++++ .../dbimport/testConfigFromDataMap.map.xml-result | 30 ++++++++++++++ .../tools/dbimport/testConfigFromDataMap.sql | 29 +++++++++++++ .../tools/dbimport/testImportNewDataMap-pom.xml | 6 +-- 9 files changed, 184 insertions(+), 29 deletions(-) diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 2c34fda..ba72e05 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -1,7 +1,7 @@ Apache Cayenne Release Notes ============================ -For the latest information visit project web site: +For the latest information visit project web site: https://cayenne.apache.org/ To browse individual bug reports check out project issue tracker: @@ -72,6 +72,7 @@ CAY-2588 IdRowReader: ArrayIndexOutOfBoundsException CAY-2591 Modeler: project becomes dirty after click on dbImport or cgen tab CAY-2594 DbImport: AutoAdapter resolving inside an import operation hangs up the op on Hana DB CAY-2595 ObjAttributes are not sorted in alphabetical ordering on save +CAY-2596 DbImport xml config changes after dbImport plugin task execution ---------------------------------- Release: 4.1.B1 diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/DefaultDbImportAction.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/DefaultDbImportAction.java index 74a39c4..49833ea 100644 --- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/DefaultDbImportAction.java +++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/DefaultDbImportAction.java @@ -19,6 +19,16 @@ package org.apache.cayenne.dbsync.reverse.dbimport; +import javax.sql.DataSource; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.sql.Connection; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + import org.apache.cayenne.CayenneRuntimeException; import org.apache.cayenne.configuration.ConfigurationNode; import org.apache.cayenne.configuration.ConfigurationTree; @@ -57,16 +67,6 @@ import org.apache.cayenne.validation.ValidationFailure; import org.apache.cayenne.validation.ValidationResult; import org.slf4j.Logger; -import javax.sql.DataSource; -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.sql.Connection; -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; - import static org.apache.cayenne.util.Util.isBlank; /** @@ -235,7 +235,9 @@ public class DefaultDbImportAction implements DbImportAction { config.setTableTypes(reverseEngineering.getTableTypes()); config.setMeaningfulPkTables(reverseEngineering.getMeaningfulPkTables()); config.setNamingStrategy(reverseEngineering.getNamingStrategy()); - config.setFiltersConfig(new FiltersConfigBuilder(reverseEngineering).build()); + config.setFiltersConfig(new FiltersConfigBuilder( + new ReverseEngineering(reverseEngineering)) + .build()); config.setForceDataMapCatalog(reverseEngineering.isForceDataMapCatalog()); config.setForceDataMapSchema(reverseEngineering.isForceDataMapSchema()); config.setDefaultPackage(reverseEngineering.getDefaultPackage()); diff --git a/maven-plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java b/maven-plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java index 6915264..c1c77b8 100644 --- a/maven-plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java +++ b/maven-plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java @@ -18,6 +18,8 @@ ****************************************************************/ package org.apache.cayenne.tools; +import java.io.File; + import org.apache.cayenne.dbsync.DbSyncModule; import org.apache.cayenne.dbsync.reverse.configuration.ToolsModule; import org.apache.cayenne.dbsync.reverse.dbimport.DbImportAction; @@ -30,17 +32,15 @@ import org.apache.cayenne.di.ClassLoaderManager; import org.apache.cayenne.di.DIBootstrap; import org.apache.cayenne.di.Injector; import org.apache.cayenne.util.Util; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.project.MavenProject; import org.slf4j.Logger; -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; - -import java.io.File; /** * Maven mojo to reverse engineer datamap from DB. @@ -192,6 +192,9 @@ public class DbImporterMojo extends AbstractMojo { return dbImportConfig; } + public DbImportDataSourceConfig getDataSource() { + return dataSource; + } } 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 8dc70ee..1ab2cb5 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 @@ -239,6 +239,11 @@ public class DbImporterMojoTest extends AbstractMojoTestCase { test("testComplexChangeOrder"); } + @Test + public void testConfigFromDataMap() throws Exception { + test("testConfigFromDataMap"); + } + /** * CREATE TABLE APP.A ( * id INTEGER NOT NULL, @@ -390,25 +395,25 @@ public class DbImporterMojoTest extends AbstractMojoTestCase { mapFileCopy = mapFile; } - DbImportConfiguration parameters = cdbImport.createConfig(mock(Logger.class)); - prepareDatabase(name, parameters); + DbImportDataSourceConfig dataSource = cdbImport.getDataSource(); + prepareDatabase(name, dataSource); try { cdbImport.execute(); verifyResult(mapFile, mapFileCopy); } finally { - cleanDb(parameters); + cleanDb(dataSource); } } - private void cleanDb(DbImportConfiguration dbImportConfiguration) throws Exception { + private void cleanDb(DbImportDataSourceConfig dataSource) throws Exception { // TODO: refactor to common DB management code... E.g. bootique-jdbc-test? // TODO: with in-memory Derby, it is easier to just stop and delete the database.. again see bootique-jdbc-test - Class.forName(dbImportConfiguration.getDriver()).newInstance(); + Class.forName(dataSource.getDriver()).newInstance(); - try (Connection connection = DriverManager.getConnection(dbImportConfiguration.getUrl())) { + try (Connection connection = DriverManager.getConnection(dataSource.getUrl())) { try (Statement stmt = connection.createStatement()) { @@ -481,15 +486,15 @@ public class DbImporterMojoTest extends AbstractMojoTestCase { } } - private void prepareDatabase(String sqlFile, DbImportConfiguration dbImportConfiguration) throws Exception { + private void prepareDatabase(String sqlFile, DbImportDataSourceConfig dataSource) throws Exception { URL sqlUrl = Objects.requireNonNull(ResourceUtil.getResource(getClass(), "dbimport/" + sqlFile + ".sql")); // TODO: refactor to common DB management code... E.g. bootique-jdbc-test? - Class.forName(dbImportConfiguration.getDriver()).newInstance(); + Class.forName(dataSource.getDriver()).newInstance(); - try (Connection connection = DriverManager.getConnection(dbImportConfiguration.getUrl())) { + try (Connection connection = DriverManager.getConnection(dataSource.getUrl())) { try (Statement stmt = connection.createStatement();) { for (String sql : SQLReader.statements(sqlUrl, ";")) { stmt.execute(sql); diff --git a/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testConfigFromDataMap-pom.xml b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testConfigFromDataMap-pom.xml new file mode 100644 index 0000000..7c37f93 --- /dev/null +++ b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testConfigFromDataMap-pom.xml @@ -0,0 +1,47 @@ +<?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 + + https://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> + <groupId>org.apache.maven.plugin-testing</groupId> + <artifactId>maven-plugin-testing</artifactId> + <version>1.0-SNAPSHOT</version> + + <modelVersion>4.0.0</modelVersion> + <build> + <plugins> + <plugin> + <artifactId>cayenne-maven-plugin</artifactId> + <configuration> + <map>target/test-classes/org/apache/cayenne/tools/dbimport/testConfigFromDataMap.map.xml</map> + <dataSource> + <driver>org.apache.derby.jdbc.EmbeddedDriver</driver> + <url>jdbc:derby:memory:DbImporterMojoTest;create=true</url> + </dataSource> + <project implementation="org.apache.cayenne.stubs.CayenneProjectStub"/> + + </configuration> + </plugin> + </plugins> + </build> + +</project> diff --git a/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testConfigFromDataMap.map.xml b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testConfigFromDataMap.map.xml new file mode 100644 index 0000000..bdad503 --- /dev/null +++ b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testConfigFromDataMap.map.xml @@ -0,0 +1,38 @@ +<?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 + ~ + ~ https://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/10/modelMap" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://cayenne.apache.org/schema/10/modelMap http://cayenne.apache.org/schema/10/modelMap.xsd" + project-version="10"> + + <dbImport xmlns="http://cayenne.apache.org/schema/10/dbimport"> + <schema> + <name>SCHEMA_01</name> + <excludeColumn>COL5</excludeColumn> + </schema> + <forceDataMapCatalog>false</forceDataMapCatalog> + <forceDataMapSchema>true</forceDataMapSchema> + <namingStrategy>org.apache.cayenne.dbsync.naming.DefaultObjectNameGenerator</namingStrategy> + <skipPrimaryKeyLoading>false</skipPrimaryKeyLoading> + <skipRelationshipsLoading>false</skipRelationshipsLoading> + <useJava7Types>false</useJava7Types> + <usePrimitives>true</usePrimitives> + </dbImport> +</data-map> \ No newline at end of file diff --git a/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testConfigFromDataMap.map.xml-result b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testConfigFromDataMap.map.xml-result new file mode 100644 index 0000000..ba8368a --- /dev/null +++ b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testConfigFromDataMap.map.xml-result @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="utf-8"?> +<data-map xmlns="http://cayenne.apache.org/schema/10/modelMap" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://cayenne.apache.org/schema/10/modelMap https://cayenne.apache.org/schema/10/modelMap.xsd" + project-version="10"> + <db-entity name="PARENT"> + <db-attribute name="COL2" type="CHAR" length="20"/> + <db-attribute name="COL3" type="DECIMAL" length="10" scale="2"/> + <db-attribute name="COL4" type="VARCHAR" length="50"/> + <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="col3" type="java.math.BigDecimal" db-attribute-path="COL3"/> + <obj-attribute name="col4" type="java.lang.String" db-attribute-path="COL4"/> + </obj-entity> + <dbImport xmlns="http://cayenne.apache.org/schema/10/dbimport"> + <schema> + <name>SCHEMA_01</name> + <excludeColumn>COL5</excludeColumn> + </schema> + <forceDataMapCatalog>false</forceDataMapCatalog> + <forceDataMapSchema>true</forceDataMapSchema> + <namingStrategy>org.apache.cayenne.dbsync.naming.DefaultObjectNameGenerator</namingStrategy> + <skipPrimaryKeyLoading>false</skipPrimaryKeyLoading> + <skipRelationshipsLoading>false</skipRelationshipsLoading> + <useJava7Types>false</useJava7Types> + <usePrimitives>true</usePrimitives> + </dbImport> +</data-map> diff --git a/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testConfigFromDataMap.sql b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testConfigFromDataMap.sql new file mode 100644 index 0000000..5c87429 --- /dev/null +++ b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testConfigFromDataMap.sql @@ -0,0 +1,29 @@ +-- 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 +-- +-- https://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(20), + COL3 DECIMAL(10,2), + COL4 VARCHAR(50), + COL5 TIME, + + PRIMARY KEY (id) +); \ No newline at end of file diff --git a/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewDataMap-pom.xml b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewDataMap-pom.xml index a4f1713..0ea4ee7 100644 --- a/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewDataMap-pom.xml +++ b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testImportNewDataMap-pom.xml @@ -7,15 +7,15 @@ 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 - + https://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. + 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