Repository: cayenne Updated Branches: refs/heads/master 1e8ed89f9 -> 84687a787
CAY-2391 add excludeRelationship to dbImport Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/66af8b36 Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/66af8b36 Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/66af8b36 Branch: refs/heads/master Commit: 66af8b36f9a4881ecf6b5896e7ce862cccd365db Parents: e0b9ebe Author: Arseni Bulatski <ancars...@gmail.com> Authored: Fri Jan 12 12:10:27 2018 +0300 Committer: Arseni Bulatski <ancars...@gmail.com> Committed: Mon Jan 15 14:01:52 2018 +0300 ---------------------------------------------------------------------- .../apache/cayenne/tools/DbImporterTask.java | 10 +- .../cayenne/tools/DbImporterTaskTest.java | 39 ++--- .../testExcludeRelationshipFirst.map.xml-result | 40 ++++++ .../tools/testExcludeRelationshipFirst.xml | 38 +++++ .../tools/testExcludeRelationshipFirst.xml.sql | 37 +++++ .../cayenne/dbsync/merge/DataMapMerger.java | 2 +- .../dbsync/merge/DbRelationshipDictionary.java | 31 +++- .../dbsync/merge/DbRelationshipMerger.java | 9 +- .../reverse/dbimport/ExcludeRelationship.java | 34 +++++ .../reverse/dbimport/FilterContainer.java | 26 +++- .../dbsync/reverse/dbimport/IncludeTable.java | 29 ++++ .../reverse/dbload/RelationshipLoader.java | 39 ++--- .../reverse/filters/FiltersConfigBuilder.java | 63 +++++++- .../cayenne/tools/model/FilterContainer.java | 20 +++ .../cayenne/tools/model/IncludeTable.java | 21 +++ .../cayenne/tools/model/PatternParam.java | 7 + .../org/apache/cayenne/tools/DbImportIT.java | 20 +++ .../cayenne/tools/model/IncludeTableTest.java | 12 ++ .../cayenne/tools/dbimport_excludeRel.gradle | 43 ++++++ .../apache/cayenne/tools/exclude_Table.map.xml | 44 ++++++ .../org/apache/cayenne/tools/exclude_Table.sql | 40 ++++++ docs/doc/src/main/resources/RELEASE-NOTES.txt | 1 + docs/doc/src/main/resources/UPGRADE.txt | 2 + .../cayenne/tools/DbImporterMojoTest.java | 10 ++ .../dbimport/testExcludeRelationship-pom.xml | 55 +++++++ .../dbimport/testExcludeRelationship.map.xml | 142 +++++++++++++++++++ .../testExcludeRelationship.map.xml-result | 138 ++++++++++++++++++ .../tools/dbimport/testExcludeRelationship.sql | 105 ++++++++++++++ .../testExcludeRelationshipFirst-pom.xml | 49 +++++++ .../testExcludeRelationshipFirst.map.xml-result | 40 ++++++ .../dbimport/testExcludeRelationshipFirst.sql | 37 +++++ 31 files changed, 1127 insertions(+), 56 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/cayenne-ant/src/main/java/org/apache/cayenne/tools/DbImporterTask.java ---------------------------------------------------------------------- diff --git a/cayenne-ant/src/main/java/org/apache/cayenne/tools/DbImporterTask.java b/cayenne-ant/src/main/java/org/apache/cayenne/tools/DbImporterTask.java index 8ab949f..5d22173 100644 --- a/cayenne-ant/src/main/java/org/apache/cayenne/tools/DbImporterTask.java +++ b/cayenne-ant/src/main/java/org/apache/cayenne/tools/DbImporterTask.java @@ -24,11 +24,12 @@ import org.apache.cayenne.dbsync.naming.DefaultObjectNameGenerator; import org.apache.cayenne.dbsync.reverse.configuration.ToolsModule; import org.apache.cayenne.dbsync.reverse.dbimport.Catalog; import org.apache.cayenne.dbsync.reverse.dbimport.DbImportAction; -import org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfigurationValidator; import org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration; +import org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfigurationValidator; import org.apache.cayenne.dbsync.reverse.dbimport.DbImportModule; import org.apache.cayenne.dbsync.reverse.dbimport.ExcludeColumn; import org.apache.cayenne.dbsync.reverse.dbimport.ExcludeProcedure; +import org.apache.cayenne.dbsync.reverse.dbimport.ExcludeRelationship; import org.apache.cayenne.dbsync.reverse.dbimport.ExcludeTable; import org.apache.cayenne.dbsync.reverse.dbimport.IncludeColumn; import org.apache.cayenne.dbsync.reverse.dbimport.IncludeProcedure; @@ -77,6 +78,13 @@ public class DbImporterTask extends Task { reverseEngineering.addExcludeTable(excludeTable); } + /** + * @since 4.1 + */ + public void addExcludeRelationship(ExcludeRelationship excludeRelationship){ + reverseEngineering.addExcludeRelationship(excludeRelationship); + } + public void addIncludeProcedure(IncludeProcedure includeProcedure) { reverseEngineering.addIncludeProcedure(includeProcedure); } http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/cayenne-ant/src/test/java/org/apache/cayenne/tools/DbImporterTaskTest.java ---------------------------------------------------------------------- diff --git a/cayenne-ant/src/test/java/org/apache/cayenne/tools/DbImporterTaskTest.java b/cayenne-ant/src/test/java/org/apache/cayenne/tools/DbImporterTaskTest.java index df746c2..71ae4e3 100644 --- a/cayenne-ant/src/test/java/org/apache/cayenne/tools/DbImporterTaskTest.java +++ b/cayenne-ant/src/test/java/org/apache/cayenne/tools/DbImporterTaskTest.java @@ -39,16 +39,11 @@ import java.io.IOException; import java.net.URL; import java.sql.Connection; import java.sql.DriverManager; -import java.sql.ResultSet; -import java.sql.SQLException; import java.sql.Statement; import java.util.List; import static org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineeringUtils.*; -import static org.apache.commons.lang.StringUtils.isBlank; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; // TODO: we are only testing on Derby. We may need to dynamically switch between DBs // based on "cayenneTestConnection", like we do in cayenne-server, etc. @@ -104,6 +99,11 @@ public class DbImporterTaskTest { test("build-include-table.xml"); } + @Test + public void testExcludeRelationshipFirst() throws Exception { + test("testExcludeRelationshipFirst.xml"); + } + private DbImporterTask getCdbImport(String buildFile) { Project project = new Project(); @@ -144,32 +144,9 @@ public class DbImporterTaskTest { try { cdbImport.execute(); verifyResult(mapFile, mapFileCopy); - } finally { - cleanDb(cdbImport.toParameters()); - } - } - - private void cleanDb(DbImportConfiguration dbImportConfiguration) throws ClassNotFoundException, - IllegalAccessException, InstantiationException, SQLException { - Class.forName(dbImportConfiguration.getDriver()).newInstance(); - // Get a connection - Connection connection = DriverManager.getConnection(dbImportConfiguration.getUrl()); - Statement stmt = connection.createStatement(); - - ResultSet tables = connection.getMetaData().getTables(null, null, null, new String[]{"TABLE"}); - while (tables.next()) { - String schema = tables.getString("TABLE_SCHEM"); - System.out.println("DROP TABLE " + (isBlank(schema) ? "" : schema + ".") + tables.getString("TABLE_NAME")); - stmt.execute("DROP TABLE " + (isBlank(schema) ? "" : schema + ".") + tables.getString("TABLE_NAME")); } - - ResultSet schemas = connection.getMetaData().getSchemas(); - while (schemas.next()) { - String schem = schemas.getString("TABLE_SCHEM"); - if (schem.startsWith("SCHEMA")) { - System.out.println("DROP SCHEMA " + schem); - stmt.execute("DROP SCHEMA " + schem + " RESTRICT"); - } + catch (Exception ex){ + fail(); } } http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/cayenne-ant/src/test/resources/org/apache/cayenne/tools/testExcludeRelationshipFirst.map.xml-result ---------------------------------------------------------------------- diff --git a/cayenne-ant/src/test/resources/org/apache/cayenne/tools/testExcludeRelationshipFirst.map.xml-result b/cayenne-ant/src/test/resources/org/apache/cayenne/tools/testExcludeRelationshipFirst.map.xml-result new file mode 100644 index 0000000..15cadd2 --- /dev/null +++ b/cayenne-ant/src/test/resources/org/apache/cayenne/tools/testExcludeRelationshipFirst.map.xml-result @@ -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. +--> +<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"> + <property name="defaultSchema" value="SCHEMA_01"/> + + <db-entity name="TEST1" schema="SCHEMA_01"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + </db-entity> + <db-entity name="TEST2" schema="SCHEMA_01"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + <db-attribute name="TEST1_ID" type="INTEGER" length="10"/> + </db-entity> + + <obj-entity name="Test1" className="Test1" dbEntityName="TEST1"/> + <obj-entity name="Test2" className="Test2" dbEntityName="TEST2"> + <obj-attribute name="test1Id" type="int" db-attribute-path="TEST1_ID"/> + </obj-entity> + + +</data-map> http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/cayenne-ant/src/test/resources/org/apache/cayenne/tools/testExcludeRelationshipFirst.xml ---------------------------------------------------------------------- diff --git a/cayenne-ant/src/test/resources/org/apache/cayenne/tools/testExcludeRelationshipFirst.xml b/cayenne-ant/src/test/resources/org/apache/cayenne/tools/testExcludeRelationshipFirst.xml new file mode 100644 index 0000000..a13cf96 --- /dev/null +++ b/cayenne-ant/src/test/resources/org/apache/cayenne/tools/testExcludeRelationshipFirst.xml @@ -0,0 +1,38 @@ +<!-- + ~ 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 name="MyProject" default="dist" basedir="../"> + + <taskdef name="cdbimport" classname="org.apache.cayenne.tools.DbImporterTask" taskname="cdbimport" + classpath="${basedir}"/> + + <target name="dist"> + <cdbimport map="testExcludeRelationshipFirst.map.xml" + driver="org.apache.derby.jdbc.EmbeddedDriver" + url="jdbc:derby:memory:DbImporterMojoTest;create=true"> + <schema> + <name>SCHEMA_01</name> + <excludeRelationship>test1</excludeRelationship> + <excludeRelationship>test2s</excludeRelationship> + </schema> + </cdbimport> + </target> + + +</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/cayenne-ant/src/test/resources/org/apache/cayenne/tools/testExcludeRelationshipFirst.xml.sql ---------------------------------------------------------------------- diff --git a/cayenne-ant/src/test/resources/org/apache/cayenne/tools/testExcludeRelationshipFirst.xml.sql b/cayenne-ant/src/test/resources/org/apache/cayenne/tools/testExcludeRelationshipFirst.xml.sql new file mode 100644 index 0000000..140b9ca --- /dev/null +++ b/cayenne-ant/src/test/resources/org/apache/cayenne/tools/testExcludeRelationshipFirst.xml.sql @@ -0,0 +1,37 @@ +-- 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.TEST1( + ID INTEGER NOT NULL, + PRIMARY KEY (ID) +); + +CREATE TABLE schema_01.TEST2( + ID INTEGER NOT NULL, + TEST1_ID INTEGER, + PRIMARY KEY (ID) +); + +ALTER TABLE schema_01.TEST2 +ADD FOREIGN KEY (TEST1_ID) +REFERENCES schema_01.TEST1 (ID) +; + + http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DataMapMerger.java ---------------------------------------------------------------------- diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DataMapMerger.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DataMapMerger.java index 80c9134..2079c48 100644 --- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DataMapMerger.java +++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DataMapMerger.java @@ -96,7 +96,7 @@ public class DataMapMerger implements Merger<DataMap> { private void createRelationshipMerger() { ChainMerger<DbEntity, DbRelationship> dbRelationshipMerger = new ChainMerger<>( tokenFactory, - new DbRelationshipMerger(tokenFactory, skipRelationshipsTokens), + new DbRelationshipMerger(tokenFactory, skipRelationshipsTokens, filters), dbEntityMerger ); mergerList.add(dbRelationshipMerger); http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbRelationshipDictionary.java ---------------------------------------------------------------------- diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbRelationshipDictionary.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbRelationshipDictionary.java index 4d5d74c..80424db 100644 --- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbRelationshipDictionary.java +++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbRelationshipDictionary.java @@ -20,8 +20,12 @@ package org.apache.cayenne.dbsync.merge; import java.util.Collection; +import java.util.LinkedList; import java.util.TreeSet; +import org.apache.cayenne.dbsync.reverse.filters.FiltersConfig; +import org.apache.cayenne.dbsync.reverse.filters.PatternFilter; +import org.apache.cayenne.dbsync.reverse.filters.TableFilter; import org.apache.cayenne.map.DbEntity; import org.apache.cayenne.map.DbJoin; import org.apache.cayenne.map.DbRelationship; @@ -30,8 +34,11 @@ class DbRelationshipDictionary extends MergerDictionary<DbRelationship> { private final DbEntity container; - DbRelationshipDictionary(DbEntity container) { + private final FiltersConfig filtersConfig; + + DbRelationshipDictionary(DbEntity container, FiltersConfig filtersConfig) { this.container = container; + this.filtersConfig = filtersConfig; } @Override @@ -41,10 +48,30 @@ class DbRelationshipDictionary extends MergerDictionary<DbRelationship> { @Override Collection<DbRelationship> getAll() { - return container.getRelationships(); + return filter(); } /** + * @since 4.1 + */ + private Collection<DbRelationship> filter() { + if(filtersConfig == null) { + return container.getRelationships(); + } + + Collection<DbRelationship> existingFiltered = new LinkedList<>(); + TableFilter tableFilter = filtersConfig.tableFilter(container.getCatalog(), container.getSchema()); + if(tableFilter != null && tableFilter.isIncludeTable(container.getName())){ + PatternFilter patternFilter = tableFilter.getIncludeTableColumnFilter(container.getName()); + for(DbRelationship rel : container.getRelationships()){ + if(patternFilter.isIncluded(rel.getName())){ + existingFiltered.add(rel); + } + } + } + return existingFiltered; + } + /** * Signature of DbRelationship is sorted strings generated from its DbJoins */ private static class Signature { http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbRelationshipMerger.java ---------------------------------------------------------------------- diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbRelationshipMerger.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbRelationshipMerger.java index 73644b4..715507d 100644 --- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbRelationshipMerger.java +++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbRelationshipMerger.java @@ -25,6 +25,7 @@ import java.util.List; import org.apache.cayenne.dbsync.merge.factory.MergerTokenFactory; import org.apache.cayenne.dbsync.merge.token.MergerToken; +import org.apache.cayenne.dbsync.reverse.filters.FiltersConfig; import org.apache.cayenne.map.DbAttribute; import org.apache.cayenne.map.DbEntity; import org.apache.cayenne.map.DbJoin; @@ -37,17 +38,19 @@ import org.apache.cayenne.map.DbRelationship; public class DbRelationshipMerger extends AbstractMerger<DbEntity, DbRelationship> { private final boolean skipRelationshipsTokens; + private final FiltersConfig filtersConfig; - DbRelationshipMerger(MergerTokenFactory tokenFactory, boolean skipRelationshipsTokens) { + DbRelationshipMerger(MergerTokenFactory tokenFactory, boolean skipRelationshipsTokens, FiltersConfig filtersConfig) { super(tokenFactory); this.skipRelationshipsTokens = skipRelationshipsTokens; + this.filtersConfig = filtersConfig; } @Override MergerDictionaryDiff<DbRelationship> createDiff(DbEntity original, DbEntity imported) { return new MergerDictionaryDiff.Builder<DbRelationship>() - .originalDictionary(new DbRelationshipDictionary(original)) - .importedDictionary(new DbRelationshipDictionary(imported)) + .originalDictionary(new DbRelationshipDictionary(original, filtersConfig)) + .importedDictionary(new DbRelationshipDictionary(imported, filtersConfig)) .build(); } http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/ExcludeRelationship.java ---------------------------------------------------------------------- diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/ExcludeRelationship.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/ExcludeRelationship.java new file mode 100644 index 0000000..19a08fe --- /dev/null +++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/ExcludeRelationship.java @@ -0,0 +1,34 @@ +/***************************************************************** + * 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. + ****************************************************************/ + +package org.apache.cayenne.dbsync.reverse.dbimport; + +/** + * @since 4.1. + */ +public class ExcludeRelationship extends PatternParam{ + + public ExcludeRelationship(){ + + } + + public ExcludeRelationship(String pattern){ + super(pattern); + } +} http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/FilterContainer.java ---------------------------------------------------------------------- diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/FilterContainer.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/FilterContainer.java index 03c4dee..f548863 100644 --- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/FilterContainer.java +++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/FilterContainer.java @@ -41,6 +41,8 @@ public abstract class FilterContainer { private final Collection<ExcludeProcedure> excludeProcedureCollection = new LinkedList<>(); + private final Collection<ExcludeRelationship> excludeRelationshipCollection = new LinkedList<>(); + public Collection<IncludeTable> getIncludeTables() { return includeTableCollection; } @@ -65,6 +67,13 @@ public abstract class FilterContainer { return excludeProcedureCollection; } + /** + * @since 4.1 + */ + public Collection<ExcludeRelationship> getExcludeRelationship() { + return excludeRelationshipCollection; + } + public void addIncludeColumn(IncludeColumn includeColumn) { this.includeColumnCollection.add(includeColumn); } @@ -89,6 +98,13 @@ public abstract class FilterContainer { this.excludeProcedureCollection.add(excludeProcedure); } + /** + * @since 4.1 + */ + public void addExcludeRelationship(ExcludeRelationship excludeRelationship) { + this.excludeRelationshipCollection.add(excludeRelationship); + } + public void clearIncludeTables() { includeTableCollection.clear(); } @@ -113,6 +129,13 @@ public abstract class FilterContainer { excludeColumnCollection.clear(); } + /** + * @since 4.1 + */ + public void clearExcludeRelationship() { + excludeRelationshipCollection.clear(); + } + public String getName() { return name; } @@ -139,7 +162,7 @@ public abstract class FilterContainer { public boolean isEmptyContainer() { return includeColumnCollection.isEmpty() && excludeColumnCollection.isEmpty() && includeTableCollection.isEmpty() && excludeTableCollection.isEmpty() - && includeProcedureCollection.isEmpty() && excludeProcedureCollection.isEmpty(); + && includeProcedureCollection.isEmpty() && excludeProcedureCollection.isEmpty() && excludeRelationshipCollection.isEmpty(); } static boolean isBlank(Collection<?> collection) { @@ -158,6 +181,7 @@ public abstract class FilterContainer { appendCollection(res, prefix, excludeColumnCollection); appendCollection(res, prefix, includeProcedureCollection); appendCollection(res, prefix, excludeProcedureCollection); + appendCollection(res, prefix, excludeRelationshipCollection); return res; } http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/IncludeTable.java ---------------------------------------------------------------------- diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/IncludeTable.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/IncludeTable.java index b57e782..defa595 100644 --- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/IncludeTable.java +++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/IncludeTable.java @@ -31,6 +31,8 @@ public class IncludeTable extends PatternParam { private final Collection<ExcludeColumn> excludeColumns = new LinkedList<>(); + private final Collection<ExcludeRelationship> excludeRelationship = new LinkedList<>(); + public IncludeTable() { } @@ -54,6 +56,20 @@ public class IncludeTable extends PatternParam { this.excludeColumns.addAll(excludeColumns); } + /** + * @since 4.1 + */ + public Collection<ExcludeRelationship> getExcludeRelationship() { + return excludeRelationship; + } + + /** + * @since 4.1 + */ + public void setExcludeRelationship (Collection<ExcludeRelationship> excludeRelationship) { + this.excludeRelationship.addAll(excludeRelationship); + } + public void addIncludeColumn(IncludeColumn includeColumn) { this.includeColumns.add(includeColumn); } @@ -62,6 +78,13 @@ public class IncludeTable extends PatternParam { this.excludeColumns.add(excludeColumn); } + /** + * @since 4.1 + */ + public void addExcludeRelationship(ExcludeRelationship excludeRelationship){ + this.excludeRelationship.add(excludeRelationship); + } + @Override public StringBuilder toString(StringBuilder res, String s) { super.toString(res, s); @@ -79,6 +102,12 @@ public class IncludeTable extends PatternParam { } } + if(excludeRelationship != null && !excludeColumns.isEmpty()) { + for(ExcludeRelationship excludeRelationship : excludeRelationship) { + excludeRelationship.toString(res, prefix); + } + } + return res; } } http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbload/RelationshipLoader.java ---------------------------------------------------------------------- diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbload/RelationshipLoader.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbload/RelationshipLoader.java index 46a1aa0..d51db9d 100644 --- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbload/RelationshipLoader.java +++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbload/RelationshipLoader.java @@ -108,22 +108,29 @@ public class RelationshipLoader extends AbstractLoader { // set relationship names only after their joins are ready ... // generator logic is based on relationship state... - forwardRelationship.setName(NameBuilder - .builder(forwardRelationship, pkEntity) - .baseName(nameGenerator.relationshipName(forwardRelationship)) - .name()); - - reverseRelationship.setName(NameBuilder - .builder(reverseRelationship, fkEntity) - .baseName(nameGenerator.relationshipName(reverseRelationship)) - .name()); - - if (delegate.dbRelationshipLoaded(fkEntity, reverseRelationship)) { - fkEntity.addRelationship(reverseRelationship); - } - if (delegate.dbRelationshipLoaded(pkEntity, forwardRelationship)) { - pkEntity.addRelationship(forwardRelationship); - } + + setRelationshipName(pkEntity, forwardRelationship); + setRelationshipName(fkEntity, reverseRelationship); + + checkAndAddRelationship(pkEntity, forwardRelationship); + checkAndAddRelationship(fkEntity, reverseRelationship); + } + } + + private void setRelationshipName(DbEntity entity, DbRelationship relationship) { + relationship.setName(NameBuilder + .builder(relationship, entity) + .baseName(nameGenerator.relationshipName(relationship)) + .name()); + } + + private void checkAndAddRelationship(DbEntity entity, DbRelationship relationship){ + boolean isIncluded = config.getFiltersConfig() + .tableFilter(entity.getCatalog(), entity.getSchema()) + .getIncludeTableColumnFilter(entity.getName()) + .isIncluded(relationship.getName()); + if (isIncluded && delegate.dbRelationshipLoaded(entity, relationship)) { + entity.addRelationship(relationship); } } http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/filters/FiltersConfigBuilder.java ---------------------------------------------------------------------- diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/filters/FiltersConfigBuilder.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/filters/FiltersConfigBuilder.java index a93681f..73e938a 100644 --- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/filters/FiltersConfigBuilder.java +++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/filters/FiltersConfigBuilder.java @@ -21,6 +21,7 @@ package org.apache.cayenne.dbsync.reverse.filters; import org.apache.cayenne.dbsync.reverse.dbimport.Catalog; import org.apache.cayenne.dbsync.reverse.dbimport.ExcludeColumn; import org.apache.cayenne.dbsync.reverse.dbimport.ExcludeProcedure; +import org.apache.cayenne.dbsync.reverse.dbimport.ExcludeRelationship; import org.apache.cayenne.dbsync.reverse.dbimport.ExcludeTable; import org.apache.cayenne.dbsync.reverse.dbimport.IncludeColumn; import org.apache.cayenne.dbsync.reverse.dbimport.IncludeProcedure; @@ -88,7 +89,8 @@ public final class FiltersConfigBuilder { SortedSet<IncludeTableFilter> includeTableFilters = new TreeSet<>(); for (IncludeTable includeTable : includeTables) { includeTableFilters.add(new IncludeTableFilter(includeTable.getPattern(), - transform(includeTable.getIncludeColumns(), includeTable.getExcludeColumns()))); + transform(includeTable.getIncludeColumns(), includeTable.getExcludeColumns(), includeTable.getExcludeRelationship()))); + } return includeTableFilters; @@ -109,6 +111,25 @@ public final class FiltersConfigBuilder { } + private PatternFilter transform(Collection<? extends PatternParam> include, Collection<? extends PatternParam> exclude, Collection<? extends PatternParam> excludeRel) { + PatternFilter filter = new PatternFilter(); + + for (PatternParam patternParam : include) { + filter.include(patternParam.getPattern()); + } + + for (PatternParam patternParam : exclude) { + filter.exclude(patternParam.getPattern()); + } + + for(PatternParam patternParam : excludeRel){ + filter.exclude(patternParam.getPattern()); + } + + return filter; + + } + /** * Goal of this method transform ReverseEngineering config into more regular form * From @@ -167,6 +188,7 @@ public final class FiltersConfigBuilder { addEmptyElements(); compactColumnFilters(); + compactRelationshipFilters(); compactTableFilter(); compactProcedureFilter(); compactSchemas(); @@ -226,6 +248,42 @@ public final class FiltersConfigBuilder { } } + private void compactRelationshipFilters() { + Collection<ExcludeRelationship> engExcludeRelationship = engineering.getExcludeRelationship(); + + for(Catalog catalog : engineering.getCatalogs()){ + Collection<ExcludeRelationship> catalogExcludeRelationship = catalog.getExcludeRelationship(); + + for(Schema schema : catalog.getSchemas()){ + Collection<ExcludeRelationship> schemaExcludeRelationship = schema.getExcludeRelationship(); + + for(IncludeTable includeTable : schema.getIncludeTables()) { + includeTable.getExcludeRelationship().addAll(engExcludeRelationship); + includeTable.getExcludeRelationship().addAll(catalogExcludeRelationship); + includeTable.getExcludeRelationship().addAll(schemaExcludeRelationship); + } + } + + for(IncludeTable includeTable : catalog.getIncludeTables()) { + includeTable.getExcludeRelationship().addAll(engExcludeRelationship); + includeTable.getExcludeRelationship().addAll(catalogExcludeRelationship); + } + } + + for (Schema schema : engineering.getSchemas()) { + Collection<ExcludeRelationship> schemaExcludeRelationship = schema.getExcludeRelationship(); + + for (IncludeTable includeTable : schema.getIncludeTables()) { + includeTable.getExcludeRelationship().addAll(engExcludeRelationship); + includeTable.getExcludeRelationship().addAll(schemaExcludeRelationship); + } + } + + for (IncludeTable includeTable : engineering.getIncludeTables()) { + includeTable.getExcludeRelationship().addAll(engExcludeRelationship); + } + } + private void compactColumnFilters() { Collection<IncludeColumn> engIncludeColumns = engineering.getIncludeColumns(); Collection<ExcludeColumn> engExcludeColumns = engineering.getExcludeColumns(); @@ -285,10 +343,12 @@ public final class FiltersConfigBuilder { catalog.clearExcludeProcedures(); catalog.clearIncludeColumns(); catalog.clearExcludeColumns(); + catalog.clearExcludeRelationship(); for (Schema schema : catalog.getSchemas()) { schema.clearIncludeColumns(); schema.clearExcludeColumns(); + schema.clearExcludeRelationship(); } } @@ -298,6 +358,7 @@ public final class FiltersConfigBuilder { engineering.clearExcludeProcedures(); engineering.clearIncludeColumns(); engineering.clearExcludeColumns(); + engineering.clearExcludeRelationship(); engineering.getSchemas().clear(); } http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/cayenne-gradle-plugin/src/main/java/org/apache/cayenne/tools/model/FilterContainer.java ---------------------------------------------------------------------- diff --git a/cayenne-gradle-plugin/src/main/java/org/apache/cayenne/tools/model/FilterContainer.java b/cayenne-gradle-plugin/src/main/java/org/apache/cayenne/tools/model/FilterContainer.java index 734ca70..f34be96 100644 --- a/cayenne-gradle-plugin/src/main/java/org/apache/cayenne/tools/model/FilterContainer.java +++ b/cayenne-gradle-plugin/src/main/java/org/apache/cayenne/tools/model/FilterContainer.java @@ -37,6 +37,7 @@ public class FilterContainer { private Collection<PatternParam> excludeColumns = new LinkedList<>(); private Collection<PatternParam> includeProcedures = new LinkedList<>(); private Collection<PatternParam> excludeProcedures = new LinkedList<>(); + private Collection<PatternParam> excludeRelationships = new LinkedList<>(); FilterContainer() { } @@ -97,6 +98,22 @@ public class FilterContainer { } } + /** + * @since 4.1 + */ + public void excludeRelationship(String pattern) { + addToCollection(excludeRelationships, pattern); + } + + /** + * @since 4.1 + */ + public void excludeRelationships(String... patterns) { + for(String pattern : patterns) { + excludeRelationship(pattern); + } + } + public void includeProcedure(String pattern) { addToCollection(includeProcedures, pattern); } @@ -143,6 +160,9 @@ public class FilterContainer { for(PatternParam procedure : excludeProcedures) { container.addExcludeProcedure(procedure.toExcludeProcedure()); } + for(PatternParam rel : excludeRelationships) { + container.addExcludeRelationship(rel.toExcludeRelationship()); + } return container; } http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/cayenne-gradle-plugin/src/main/java/org/apache/cayenne/tools/model/IncludeTable.java ---------------------------------------------------------------------- diff --git a/cayenne-gradle-plugin/src/main/java/org/apache/cayenne/tools/model/IncludeTable.java b/cayenne-gradle-plugin/src/main/java/org/apache/cayenne/tools/model/IncludeTable.java index 5bd12b7..5d590fd 100644 --- a/cayenne-gradle-plugin/src/main/java/org/apache/cayenne/tools/model/IncludeTable.java +++ b/cayenne-gradle-plugin/src/main/java/org/apache/cayenne/tools/model/IncludeTable.java @@ -29,6 +29,7 @@ public class IncludeTable extends PatternParam { private Collection<PatternParam> includeColumns = new LinkedList<>(); private Collection<PatternParam> excludeColumns = new LinkedList<>(); + private Collection<PatternParam> excludeRelationships = new LinkedList<>(); IncludeTable() { } @@ -65,6 +66,22 @@ public class IncludeTable extends PatternParam { } } + /** + * @since 4.1 + */ + public void excludeRelationship(String pattern){ + excludeRelationships.add(new PatternParam(pattern)); + } + + /** + * @since 4.1 + */ + public void excludeRelationships(String... patterns){ + for(String pattern : patterns) { + excludeRelationship(pattern); + } + } + org.apache.cayenne.dbsync.reverse.dbimport.IncludeTable toIncludeTable() { org.apache.cayenne.dbsync.reverse.dbimport.IncludeTable table = new org.apache.cayenne.dbsync.reverse.dbimport.IncludeTable(); @@ -77,6 +94,10 @@ public class IncludeTable extends PatternParam { table.addExcludeColumn(excludeColumn.toExcludeColumn()); } + for(PatternParam excludeRelationship : excludeRelationships){ + table.addExcludeRelationship(excludeRelationship.toExcludeRelationship()); + } + return table; } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/cayenne-gradle-plugin/src/main/java/org/apache/cayenne/tools/model/PatternParam.java ---------------------------------------------------------------------- diff --git a/cayenne-gradle-plugin/src/main/java/org/apache/cayenne/tools/model/PatternParam.java b/cayenne-gradle-plugin/src/main/java/org/apache/cayenne/tools/model/PatternParam.java index d6f7dfb..5d852b8 100644 --- a/cayenne-gradle-plugin/src/main/java/org/apache/cayenne/tools/model/PatternParam.java +++ b/cayenne-gradle-plugin/src/main/java/org/apache/cayenne/tools/model/PatternParam.java @@ -21,6 +21,7 @@ package org.apache.cayenne.tools.model; import org.apache.cayenne.dbsync.reverse.dbimport.ExcludeColumn; import org.apache.cayenne.dbsync.reverse.dbimport.ExcludeProcedure; +import org.apache.cayenne.dbsync.reverse.dbimport.ExcludeRelationship; import org.apache.cayenne.dbsync.reverse.dbimport.ExcludeTable; import org.apache.cayenne.dbsync.reverse.dbimport.IncludeColumn; import org.apache.cayenne.dbsync.reverse.dbimport.IncludeProcedure; @@ -73,6 +74,12 @@ public class PatternParam { return procedure; } + ExcludeRelationship toExcludeRelationship(){ + ExcludeRelationship excludeRelationship = new ExcludeRelationship(); + excludeRelationship.setPattern(pattern); + return excludeRelationship; + } + public String getPattern() { return pattern; } http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/cayenne-gradle-plugin/src/test/java/org/apache/cayenne/tools/DbImportIT.java ---------------------------------------------------------------------- diff --git a/cayenne-gradle-plugin/src/test/java/org/apache/cayenne/tools/DbImportIT.java b/cayenne-gradle-plugin/src/test/java/org/apache/cayenne/tools/DbImportIT.java index 283796e..00ecbe5 100644 --- a/cayenne-gradle-plugin/src/test/java/org/apache/cayenne/tools/DbImportIT.java +++ b/cayenne-gradle-plugin/src/test/java/org/apache/cayenne/tools/DbImportIT.java @@ -94,6 +94,26 @@ public class DbImportIT extends BaseTaskIT { assertTrue(result.getOutput().contains("Migration Complete Successfully.")); } + @Test + public void excludeRelDbTaskSuccess() throws Exception { + String dbUrl = prepareDerbyDatabase("exclude_Table"); + File dataMap = new File(projectDir.getAbsolutePath() + "/datamap.map.xml"); + assertFalse(dataMap.exists()); + + GradleRunner runner = createRunner("dbimport_excludeRel", "cdbimport", "--info", "-PdbUrl=" + dbUrl); + + BuildResult result = runner.build(); + + assertNotNull(result.task(":cdbimport")); + assertEquals(TaskOutcome.SUCCESS, result.task(":cdbimport").getOutcome()); + + assertTrue(dataMap.exists()); + + // Check few lines from reverse engineering output + assertTrue(result.getOutput().contains("Table: SCHEMA_01.TEST1")); + assertTrue(result.getOutput().contains("Table: SCHEMA_01.TEST2")); + } + private String prepareDerbyDatabase(String sqlFile) throws Exception { URL sqlUrl = Objects.requireNonNull(ResourceUtil.getResource(getClass(), sqlFile + ".sql")); String dbUrl = "jdbc:derby:" + projectDir.getAbsolutePath() + "/build/" + sqlFile; http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/cayenne-gradle-plugin/src/test/java/org/apache/cayenne/tools/model/IncludeTableTest.java ---------------------------------------------------------------------- diff --git a/cayenne-gradle-plugin/src/test/java/org/apache/cayenne/tools/model/IncludeTableTest.java b/cayenne-gradle-plugin/src/test/java/org/apache/cayenne/tools/model/IncludeTableTest.java index 2d95cf9..e618bde 100644 --- a/cayenne-gradle-plugin/src/test/java/org/apache/cayenne/tools/model/IncludeTableTest.java +++ b/cayenne-gradle-plugin/src/test/java/org/apache/cayenne/tools/model/IncludeTableTest.java @@ -22,6 +22,7 @@ package org.apache.cayenne.tools.model; import java.util.Collection; import org.apache.cayenne.dbsync.reverse.dbimport.ExcludeColumn; +import org.apache.cayenne.dbsync.reverse.dbimport.ExcludeRelationship; import org.apache.cayenne.dbsync.reverse.dbimport.IncludeColumn; import org.junit.Test; @@ -81,6 +82,17 @@ public class IncludeTableTest { } @Test + public void excludeRelationship() throws Exception { + IncludeTable table = new IncludeTable("name"); + table.excludeRelationship("rel1"); + + Collection<ExcludeRelationship> rel = table.toIncludeTable().getExcludeRelationship(); + assertNotNull(rel); + assertEquals(1, rel.size()); + assertEquals("rel1", rel.iterator().next().getPattern()); + } + + @Test public void toIncludeTable() throws Exception { IncludeTable table = new IncludeTable("name"); table.includeColumns("column1", "column2"); http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/cayenne-gradle-plugin/src/test/resources/org/apache/cayenne/tools/dbimport_excludeRel.gradle ---------------------------------------------------------------------- diff --git a/cayenne-gradle-plugin/src/test/resources/org/apache/cayenne/tools/dbimport_excludeRel.gradle b/cayenne-gradle-plugin/src/test/resources/org/apache/cayenne/tools/dbimport_excludeRel.gradle new file mode 100644 index 0000000..79b41db --- /dev/null +++ b/cayenne-gradle-plugin/src/test/resources/org/apache/cayenne/tools/dbimport_excludeRel.gradle @@ -0,0 +1,43 @@ +/***************************************************************** + * 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. + ****************************************************************/ + +plugins { + id 'org.apache.cayenne' +} + +cdbimport { + map 'datamap.map.xml' + + adapter 'org.apache.cayenne.dba.derby.DerbyAdapter' + + dataSource { + username 'sa' + password '' + url dbUrl + driver 'org.apache.derby.jdbc.EmbeddedDriver' + } + dbImport { + schema{ + name 'SCHEMA_01' + excludeRelationship 'test2s' + excludeRelationship 'test1' + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/cayenne-gradle-plugin/src/test/resources/org/apache/cayenne/tools/exclude_Table.map.xml ---------------------------------------------------------------------- diff --git a/cayenne-gradle-plugin/src/test/resources/org/apache/cayenne/tools/exclude_Table.map.xml b/cayenne-gradle-plugin/src/test/resources/org/apache/cayenne/tools/exclude_Table.map.xml new file mode 100644 index 0000000..1fc3742 --- /dev/null +++ b/cayenne-gradle-plugin/src/test/resources/org/apache/cayenne/tools/exclude_Table.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/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"> + + <property name="defaultPackage" value="org.example.cayenne.persistent"/> + <property name="defaultClientPackage" value="tmp"/> + <db-entity name="City"> + <db-attribute name="id" type="INTEGER" isPrimaryKey="true" isMandatory="true"/> + <db-attribute name="name" type="VARCHAR" length="255"/> + </db-entity> + <db-entity name="artist"> + <db-attribute name="birth_date" type="DATE"/> + <db-attribute name="id" type="INTEGER" isPrimaryKey="true" isMandatory="true"/> + <db-attribute name="name" type="VARCHAR" length="255"/> + </db-entity> + <obj-entity name="City" className="org.example.cayenne.persistent.City" dbEntityName="City"> + <obj-attribute name="name" type="java.lang.String" db-attribute-path="name"/> + </obj-entity> + <obj-entity name="Artist" className="org.example.cayenne.persistent.Artist" clientClassName="tmp.Artist" dbEntityName="artist"> + <obj-attribute name="birthDate" type="java.util.Date" db-attribute-path="birth_date"/> + <obj-attribute name="name" type="java.lang.String" db-attribute-path="name"/> + </obj-entity> + +</data-map> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/cayenne-gradle-plugin/src/test/resources/org/apache/cayenne/tools/exclude_Table.sql ---------------------------------------------------------------------- diff --git a/cayenne-gradle-plugin/src/test/resources/org/apache/cayenne/tools/exclude_Table.sql b/cayenne-gradle-plugin/src/test/resources/org/apache/cayenne/tools/exclude_Table.sql new file mode 100644 index 0000000..cca377e --- /dev/null +++ b/cayenne-gradle-plugin/src/test/resources/org/apache/cayenne/tools/exclude_Table.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. + +-- Test Schema for dbimport task test + + +CREATE SCHEMA schema_01; +SET SCHEMA schema_01; + +CREATE TABLE schema_01.TEST1( + ID INTEGER NOT NULL, + PRIMARY KEY (ID) +); + +CREATE TABLE schema_01.TEST2( + ID INTEGER NOT NULL, + TEST1_ID INTEGER, + PRIMARY KEY (ID) +); + +ALTER TABLE schema_01.TEST2 +ADD FOREIGN KEY (TEST1_ID) +REFERENCES schema_01.TEST1 (ID) +; + + http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/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 5a32f7a..67e3e02 100644 --- a/docs/doc/src/main/resources/RELEASE-NOTES.txt +++ b/docs/doc/src/main/resources/RELEASE-NOTES.txt @@ -15,6 +15,7 @@ Changes/New Features: CAY-2372 Extract new modules from cayenne-server CAY-2377 Cleanup deprecated code. +CAY-2391 Add excludeRelationship in dbImport Bug Fixes: http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/docs/doc/src/main/resources/UPGRADE.txt ---------------------------------------------------------------------- diff --git a/docs/doc/src/main/resources/UPGRADE.txt b/docs/doc/src/main/resources/UPGRADE.txt index 0c9fc00..3086988 100644 --- a/docs/doc/src/main/resources/UPGRADE.txt +++ b/docs/doc/src/main/resources/UPGRADE.txt @@ -16,6 +16,8 @@ UPGRADING TO 4.1.M2 - cayenne-osgi module contains OSGi related functionality. - cayenne-rop-server ROP server part. +* Per CAY-2391 added new excludeRelationship option in dbImport. + UPGRADING TO 4.1.M1 * Per CAY-2351 Minimum supported Java version is now Java 8. There is no options to use Cayenne 4.1 with earlier http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/maven-plugins/cayenne-maven-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoTest.java ---------------------------------------------------------------------- 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 1f3a29a..6b541ec 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 @@ -163,6 +163,16 @@ public class DbImporterMojoTest extends AbstractMojoTestCase { test("testOneToOne"); } + @Test + public void testExcludeRelationship() throws Exception { + test("testExcludeRelationship"); + } + + @Test + public void testExcludeRelationshipFirst() throws Exception { + test("testExcludeRelationshipFirst"); + } + /** * Q: what happens if an attribute or relationship is unmapped in the object layer, but then the underlying table * changes. http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testExcludeRelationship-pom.xml ---------------------------------------------------------------------- diff --git a/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testExcludeRelationship-pom.xml b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testExcludeRelationship-pom.xml new file mode 100644 index 0000000..590676f --- /dev/null +++ b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testExcludeRelationship-pom.xml @@ -0,0 +1,55 @@ +<!-- + ~ 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>cayenne-maven-plugin</artifactId> + <configuration> + <map>target/test-classes/org/apache/cayenne/tools/dbimport/testExcludeRelationship.map.xml</map> + + <dataSource> + <driver>org.apache.derby.jdbc.EmbeddedDriver</driver> + <url>jdbc:derby:memory:DbImporterMojoTest;create=true</url> + </dataSource> + + <dbimport> + <schema> + <name>SCHEMA_01</name> + <excludeRelationship>TEST1_TO_TEST2</excludeRelationship> + <excludeRelationship>TEST2_TO_TEST1</excludeRelationship> + + <excludeRelationship>test6s</excludeRelationship> + <excludeRelationship>test5</excludeRelationship> + + <excludeRelationship>test12s</excludeRelationship> + <excludeRelationship>test11</excludeRelationship> + </schema> + </dbimport> + </configuration> + </plugin> + </plugins> + </build> + +</project> http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testExcludeRelationship.map.xml ---------------------------------------------------------------------- diff --git a/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testExcludeRelationship.map.xml b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testExcludeRelationship.map.xml new file mode 100644 index 0000000..1a35987 --- /dev/null +++ b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testExcludeRelationship.map.xml @@ -0,0 +1,142 @@ +<?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/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"> + <property name="defaultSchema" value="SCHEMA_01"/> + <db-entity name="TEST1" schema="SCHEMA_01"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + </db-entity> + <db-entity name="TEST2" schema="SCHEMA_01"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + <db-attribute name="TEST1_ID" type="INTEGER"/> + </db-entity> + + <db-entity name="TEST3" schema="SCHEMA_01"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + </db-entity> + <db-entity name="TEST4" schema="SCHEMA_01"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + <db-attribute name="TEST3_ID" type="INTEGER"/> + </db-entity> + + <db-entity name="TEST5" schema="SCHEMA_01"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + </db-entity> + <db-entity name="TEST6" schema="SCHEMA_01"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + <db-attribute name="TEST5_ID" type="INTEGER"/> + </db-entity> + + <db-entity name="TEST7" schema="SCHEMA_01"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + </db-entity> + <db-entity name="TEST8" schema="SCHEMA_01"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + <db-attribute name="TEST7_ID" type="INTEGER"/> + </db-entity> + + <db-entity name="TEST9" schema="SCHEMA_01"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + </db-entity> + <db-entity name="TEST10" schema="SCHEMA_01"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + <db-attribute name="TEST9_ID" type="INTEGER"/> + </db-entity> + + <db-entity name="TEST11" schema="SCHEMA_01"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + </db-entity> + <db-entity name="TEST12" schema="SCHEMA_01"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + <db-attribute name="TEST11_ID" type="INTEGER"/> + </db-entity> + + <obj-entity name="Test1" className="Test1" dbEntityName="TEST1"> + </obj-entity> + <obj-entity name="Test2" className="Test2" dbEntityName="TEST2"> + </obj-entity> + + <obj-entity name="Test3" className="Test3" dbEntityName="TEST3"> + </obj-entity> + <obj-entity name="Test4" className="Test4" dbEntityName="TEST4"> + </obj-entity> + + <obj-entity name="Test5" className="Test5" dbEntityName="TEST5"> + </obj-entity> + <obj-entity name="Test6" className="Test6" dbEntityName="TEST6"> + </obj-entity> + + <obj-entity name="Test7" className="Test7" dbEntityName="TEST7"> + </obj-entity> + <obj-entity name="Test8" className="Test8" dbEntityName="TEST8"> + </obj-entity> + + <obj-entity name="Test9" className="Test9" dbEntityName="TEST9"> + </obj-entity> + <obj-entity name="Test10" className="Test10" dbEntityName="TEST10"> + </obj-entity> + + <obj-entity name="Test11" className="Test11" dbEntityName="TEST11"> + </obj-entity> + <obj-entity name="Test12" className="Test12" dbEntityName="TEST12"> + </obj-entity> + + <db-relationship name="TEST1_TO_TEST2" source="TEST1" target="TEST2" toMany="true"> + <db-attribute-pair source="ID" target="TEST1_ID"/> + </db-relationship> + <db-relationship name="TEST2_TO_TEST1" source="TEST2" target="TEST1"> + <db-attribute-pair source="TEST1_ID" target="ID"/> + </db-relationship> + + <db-relationship name="test8s" source="TEST7" target="TEST8" toMany="true"> + <db-attribute-pair source="ID" target="TEST7_ID"/> + </db-relationship> + <db-relationship name="test7" source="TEST8" target="TEST7"> + <db-attribute-pair source="TEST7_ID" target="ID"/> + </db-relationship> + + <db-relationship name="test10s" source="TEST9" target="TEST10" toMany="true"> + <db-attribute-pair source="ID" target="TEST9_ID"/> + </db-relationship> + <db-relationship name="test9" source="TEST10" target="TEST9"> + <db-attribute-pair source="TEST9_ID" target="ID"/> + </db-relationship> + + <db-relationship name="test12s" source="TEST11" target="TEST12" toMany="true"> + <db-attribute-pair source="ID" target="TEST11_ID"/> + </db-relationship> + <db-relationship name="test11" source="TEST12" target="TEST11"> + <db-attribute-pair source="TEST11_ID" target="ID"/> + </db-relationship> + + <obj-relationship name="test1ToTest2" source="Test1" target="Test2" deleteRule="Deny" db-relationship-path="TEST1_TO_TEST2"/> + <obj-relationship name="test2ToTest1" source="Test2" target="Test1" deleteRule="Nullify" db-relationship-path="TEST2_TO_TEST1"/> + + <obj-relationship name="test8s" source="Test7" target="Test8" deleteRule="Deny" db-relationship-path="test8s"/> + <obj-relationship name="test7" source="Test8" target="Test7" deleteRule="Nullify" db-relationship-path="test7"/> + + <obj-relationship name="test10s" source="Test9" target="Test10" deleteRule="Deny" db-relationship-path="test10s"/> + <obj-relationship name="test9" source="Test10" target="Test9" deleteRule="Nullify" db-relationship-path="test9"/> + + <obj-relationship name="test12s" source="Test11" target="Test12" deleteRule="Deny" db-relationship-path="test12s"/> + <obj-relationship name="test1" source="Test12" target="Test11" deleteRule="Nullify" db-relationship-path="test11"/> +</data-map> http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testExcludeRelationship.map.xml-result ---------------------------------------------------------------------- diff --git a/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testExcludeRelationship.map.xml-result b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testExcludeRelationship.map.xml-result new file mode 100644 index 0000000..b65be2b --- /dev/null +++ b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testExcludeRelationship.map.xml-result @@ -0,0 +1,138 @@ +<?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/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"> + <property name="defaultSchema" value="SCHEMA_01"/> + <db-entity name="TEST1" schema="SCHEMA_01"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + </db-entity> + <db-entity name="TEST2" schema="SCHEMA_01"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + <db-attribute name="TEST1_ID" type="INTEGER"/> + </db-entity> + + <db-entity name="TEST3" schema="SCHEMA_01"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + </db-entity> + <db-entity name="TEST4" schema="SCHEMA_01"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + <db-attribute name="TEST3_ID" type="INTEGER"/> + </db-entity> + + <db-entity name="TEST5" schema="SCHEMA_01"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + </db-entity> + <db-entity name="TEST6" schema="SCHEMA_01"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + <db-attribute name="TEST5_ID" type="INTEGER"/> + </db-entity> + + <db-entity name="TEST7" schema="SCHEMA_01"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + </db-entity> + <db-entity name="TEST8" schema="SCHEMA_01"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + <db-attribute name="TEST7_ID" type="INTEGER"/> + </db-entity> + + <db-entity name="TEST9" schema="SCHEMA_01"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + </db-entity> + <db-entity name="TEST10" schema="SCHEMA_01"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + <db-attribute name="TEST9_ID" type="INTEGER"/> + </db-entity> + + <db-entity name="TEST11" schema="SCHEMA_01"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + </db-entity> + <db-entity name="TEST12" schema="SCHEMA_01"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + <db-attribute name="TEST11_ID" type="INTEGER"/> + </db-entity> + + <obj-entity name="Test1" className="Test1" dbEntityName="TEST1"> + </obj-entity> + <obj-entity name="Test2" className="Test2" dbEntityName="TEST2"> + </obj-entity> + + <obj-entity name="Test3" className="Test3" dbEntityName="TEST3"> + </obj-entity> + <obj-entity name="Test4" className="Test4" dbEntityName="TEST4"> + </obj-entity> + + <obj-entity name="Test5" className="Test5" dbEntityName="TEST5"> + </obj-entity> + <obj-entity name="Test6" className="Test6" dbEntityName="TEST6"> + </obj-entity> + + <obj-entity name="Test7" className="Test7" dbEntityName="TEST7"> + </obj-entity> + <obj-entity name="Test8" className="Test8" dbEntityName="TEST8"> + </obj-entity> + + <obj-entity name="Test9" className="Test9" dbEntityName="TEST9"> + </obj-entity> + <obj-entity name="Test10" className="Test10" dbEntityName="TEST10"> + </obj-entity> + + <obj-entity name="Test11" className="Test11" dbEntityName="TEST11"> + </obj-entity> + <obj-entity name="Test12" className="Test12" dbEntityName="TEST12"> + </obj-entity> + + <db-relationship name="TEST1_TO_TEST2" source="TEST1" target="TEST2" toMany="true"> + <db-attribute-pair source="ID" target="TEST1_ID"/> + </db-relationship> + <db-relationship name="TEST2_TO_TEST1" source="TEST2" target="TEST1"> + <db-attribute-pair source="TEST1_ID" target="ID"/> + </db-relationship> + <obj-relationship name="test1ToTest2" source="Test1" target="Test2" deleteRule="Deny" db-relationship-path="TEST1_TO_TEST2"/> + <obj-relationship name="test2ToTest1" source="Test2" target="Test1" deleteRule="Nullify" db-relationship-path="TEST2_TO_TEST1"/> + + <db-relationship name="test4s" source="TEST3" target="TEST4" toMany="true"> + <db-attribute-pair source="ID" target="TEST3_ID"/> + </db-relationship> + <db-relationship name="test3" source="TEST4" target="TEST3"> + <db-attribute-pair source="TEST3_ID" target="ID"/> + </db-relationship> + <obj-relationship name="test4s" source="Test3" target="Test4" deleteRule="Deny" db-relationship-path="test4s"/> + <obj-relationship name="test3" source="Test4" target="Test3" deleteRule="Nullify" db-relationship-path="test3"/> + + <db-relationship name="test8s" source="TEST7" target="TEST8" toMany="true"> + <db-attribute-pair source="ID" target="TEST7_ID"/> + </db-relationship> + <db-relationship name="test7" source="TEST8" target="TEST7"> + <db-attribute-pair source="TEST7_ID" target="ID"/> + </db-relationship> + <obj-relationship name="test8s" source="Test7" target="Test8" deleteRule="Deny" db-relationship-path="test8s"/> + <obj-relationship name="test7" source="Test8" target="Test7" deleteRule="Nullify" db-relationship-path="test7"/> + + <db-relationship name="test12s" source="TEST11" target="TEST12" toMany="true"> + <db-attribute-pair source="ID" target="TEST11_ID"/> + </db-relationship> + <db-relationship name="test11" source="TEST12" target="TEST11"> + <db-attribute-pair source="TEST11_ID" target="ID"/> + </db-relationship> + <obj-relationship name="test12s" source="Test11" target="Test12" deleteRule="Deny" db-relationship-path="test12s"/> + <obj-relationship name="test1" source="Test12" target="Test11" deleteRule="Nullify" db-relationship-path="test11"/> +</data-map> http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testExcludeRelationship.sql ---------------------------------------------------------------------- diff --git a/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testExcludeRelationship.sql b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testExcludeRelationship.sql new file mode 100644 index 0000000..6f7a7fa --- /dev/null +++ b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testExcludeRelationship.sql @@ -0,0 +1,105 @@ +-- 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.TEST1( + ID INTEGER NOT NULL, + PRIMARY KEY (ID) +); + +CREATE TABLE schema_01.TEST2( + ID INTEGER NOT NULL, + TEST1_ID INTEGER, + PRIMARY KEY (ID) +); + +CREATE TABLE schema_01.TEST3( + ID INTEGER NOT NULL, + PRIMARY KEY (ID) +); + +CREATE TABLE schema_01.TEST4( + ID INTEGER NOT NULL, + TEST3_ID INTEGER, + PRIMARY KEY (ID) +); + +ALTER TABLE schema_01.TEST4 +ADD FOREIGN KEY (TEST3_ID) +REFERENCES schema_01.TEST3 (ID) +; + +CREATE TABLE schema_01.TEST5( + ID INTEGER NOT NULL, + PRIMARY KEY (ID) +); + +CREATE TABLE schema_01.TEST6( + ID INTEGER NOT NULL, + TEST5_ID INTEGER, + PRIMARY KEY (ID) +); + +ALTER TABLE schema_01.TEST6 +ADD FOREIGN KEY (TEST5_ID) +REFERENCES schema_01.TEST5 (ID) +; + +CREATE TABLE schema_01.TEST7( + ID INTEGER NOT NULL, + PRIMARY KEY (ID) +); + +CREATE TABLE schema_01.TEST8( + ID INTEGER NOT NULL, + TEST7_ID INTEGER, + PRIMARY KEY (ID) +); + +ALTER TABLE schema_01.TEST8 +ADD FOREIGN KEY (TEST7_ID) +REFERENCES schema_01.TEST7 (ID) +; + +CREATE TABLE schema_01.TEST9( + ID INTEGER NOT NULL, + PRIMARY KEY (ID) +); + +CREATE TABLE schema_01.TEST10( + ID INTEGER NOT NULL, + TEST9_ID INTEGER, + PRIMARY KEY (ID) +); + +CREATE TABLE schema_01.TEST11( + ID INTEGER NOT NULL, + PRIMARY KEY (ID) +); + +CREATE TABLE schema_01.TEST12( + ID INTEGER NOT NULL, + TEST11_ID INTEGER, + PRIMARY KEY (ID) +); + +ALTER TABLE schema_01.TEST12 +ADD FOREIGN KEY (TEST11_ID) +REFERENCES schema_01.TEST11 (ID) +; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testExcludeRelationshipFirst-pom.xml ---------------------------------------------------------------------- diff --git a/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testExcludeRelationshipFirst-pom.xml b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testExcludeRelationshipFirst-pom.xml new file mode 100644 index 0000000..5501d70 --- /dev/null +++ b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testExcludeRelationshipFirst-pom.xml @@ -0,0 +1,49 @@ +<!-- + ~ 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>cayenne-maven-plugin</artifactId> + <configuration> + <map>target/test-classes/org/apache/cayenne/tools/dbimport/testExcludeRelationshipFirst.map.xml</map> + + <dataSource> + <driver>org.apache.derby.jdbc.EmbeddedDriver</driver> + <url>jdbc:derby:memory:DbImporterMojoTest;create=true</url> + </dataSource> + + <dbimport> + <schema> + <name>SCHEMA_01</name> + <excludeRelationship>test2s</excludeRelationship> + <excludeRelationship>test1</excludeRelationship> + </schema> + </dbimport> + </configuration> + </plugin> + </plugins> + </build> + +</project> http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testExcludeRelationshipFirst.map.xml-result ---------------------------------------------------------------------- diff --git a/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testExcludeRelationshipFirst.map.xml-result b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testExcludeRelationshipFirst.map.xml-result new file mode 100644 index 0000000..15cadd2 --- /dev/null +++ b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testExcludeRelationshipFirst.map.xml-result @@ -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. +--> +<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"> + <property name="defaultSchema" value="SCHEMA_01"/> + + <db-entity name="TEST1" schema="SCHEMA_01"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + </db-entity> + <db-entity name="TEST2" schema="SCHEMA_01"> + <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/> + <db-attribute name="TEST1_ID" type="INTEGER" length="10"/> + </db-entity> + + <obj-entity name="Test1" className="Test1" dbEntityName="TEST1"/> + <obj-entity name="Test2" className="Test2" dbEntityName="TEST2"> + <obj-attribute name="test1Id" type="int" db-attribute-path="TEST1_ID"/> + </obj-entity> + + +</data-map> http://git-wip-us.apache.org/repos/asf/cayenne/blob/66af8b36/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testExcludeRelationshipFirst.sql ---------------------------------------------------------------------- diff --git a/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testExcludeRelationshipFirst.sql b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testExcludeRelationshipFirst.sql new file mode 100644 index 0000000..140b9ca --- /dev/null +++ b/maven-plugins/cayenne-maven-plugin/src/test/resources/org/apache/cayenne/tools/dbimport/testExcludeRelationshipFirst.sql @@ -0,0 +1,37 @@ +-- 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.TEST1( + ID INTEGER NOT NULL, + PRIMARY KEY (ID) +); + +CREATE TABLE schema_01.TEST2( + ID INTEGER NOT NULL, + TEST1_ID INTEGER, + PRIMARY KEY (ID) +); + +ALTER TABLE schema_01.TEST2 +ADD FOREIGN KEY (TEST1_ID) +REFERENCES schema_01.TEST1 (ID) +; + +