You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by nt...@apache.org on 2017/02/01 09:29:29 UTC
[2/4] cayenne git commit: CAY-2215 move all DbImport code from
cayenne-tools and cayenne-server modules to cayenne-dbsync module
http://git-wip-us.apache.org/repos/asf/cayenne/blob/660dd4b2/cayenne-server/src/main/java/org/apache/cayenne/dbimport/ReverseEngineering.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/dbimport/ReverseEngineering.java b/cayenne-server/src/main/java/org/apache/cayenne/dbimport/ReverseEngineering.java
deleted file mode 100644
index dd24211..0000000
--- a/cayenne-server/src/main/java/org/apache/cayenne/dbimport/ReverseEngineering.java
+++ /dev/null
@@ -1,210 +0,0 @@
-/*****************************************************************
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.dbimport;
-
-import java.io.Serializable;
-import java.util.Collection;
-import java.util.LinkedList;
-
-/**
- * @since 4.0
- */
-public class ReverseEngineering extends SchemaContainer implements Serializable {
-
- private Boolean skipRelationshipsLoading;
-
- private Boolean skipPrimaryKeyLoading;
-
- /*
- * <p>
- * A default package for ObjEntity Java classes.
- * </p>
- * <p>
- * If not specified, and the existing DataMap already has the default package,
- * the existing package will be used.
- * </p>
- */
- private String defaultPackage;
-
- /**
- * <p>
- * Automatically tagging each DbEntity with the actual DB catalog/schema (default behavior) may sometimes be undesirable.
- * If this is the case then setting forceDataMapCatalog to true will set DbEntity catalog to one in the DataMap.
- * </p>
- * <p>
- * Default value is <b>false</b>.
- * </p>
- */
- private boolean forceDataMapCatalog;
-
- /**
- * <p>
- * Automatically tagging each DbEntity with the actual DB catalog/schema (default behavior) may sometimes be undesirable.
- * If this is the case then setting forceDataMapSchema to true will set DbEntity schema to one in the DataMap.
- * </p>
- * <p>
- * Default value is <b>false</b>.
- * </p>
- */
- private boolean forceDataMapSchema;
-
- /**
- * <p>
- * A comma-separated list of Perl5 patterns that defines which imported tables should have their primary key columns
- * mapped as ObjAttributes.
- * </p>
- * <p><b>"*"</b> would indicate all tables.</p>
- */
- private String meaningfulPkTables;
-
- /**
- * <p>
- * Object layer naming generator implementation.
- * Should be fully qualified Java class name implementing "org.apache.cayenne.dbsync.naming.ObjectNameGenerator".
- * </p>
- * <p>
- * The default is "org.apache.cayenne.dbsync.naming.DefaultObjectNameGenerator".
- * </p>
- */
- private String namingStrategy = "org.apache.cayenne.dbsync.naming.DefaultObjectNameGenerator";
-
- /**
- * A regular expression that should match the part of the table name to strip before generating DB names.
- */
- private String stripFromTableNames = "";
-
- /**
- * <p>If true, would use primitives instead of numeric and boolean classes.</p>
- * <p>Default is <b>"true"</b>, i.e. primitives will be used.</p>
- */
- private boolean usePrimitives = true;
-
- /**
- * Typical types are: <ul>
- * <li> "TABLE"
- * <li> "VIEW"
- * <li> "SYSTEM TABLE"
- * <li> "GLOBAL TEMPORARY",
- * <li> "LOCAL TEMPORARY"
- * <li> "ALIAS"
- * <li> "SYNONYM"
- * </ul>
- */
- private final Collection<String> tableTypes = new LinkedList<>();
-
- private final Collection<Catalog> catalogCollection = new LinkedList<>();
-
- public ReverseEngineering() {
- }
-
- public Boolean getSkipRelationshipsLoading() {
- return skipRelationshipsLoading;
- }
-
- public void setSkipRelationshipsLoading(Boolean skipRelationshipsLoading) {
- this.skipRelationshipsLoading = skipRelationshipsLoading;
- }
-
- public Boolean getSkipPrimaryKeyLoading() {
- return skipPrimaryKeyLoading;
- }
-
- public void setSkipPrimaryKeyLoading(Boolean skipPrimaryKeyLoading) {
- this.skipPrimaryKeyLoading = skipPrimaryKeyLoading;
- }
-
- public Collection<Catalog> getCatalogs() {
- return catalogCollection;
- }
-
- public String[] getTableTypes() {
- return tableTypes.toArray(new String[tableTypes.size()]);
- }
-
- /*
- * Typical types are "TABLE",
- * "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY",
- * "LOCAL TEMPORARY", "ALIAS", "SYNONYM"., etc.
- */
- public void setTableTypes(Collection<String> tableTypes) {
- this.tableTypes.addAll(tableTypes);
- }
-
- /*
- * Typical types are "TABLE",
- * "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY",
- * "LOCAL TEMPORARY", "ALIAS", "SYNONYM"., etc.
- */
- public void addTableType(String type) {
- this.tableTypes.add(type);
- }
-
- public void addCatalog(Catalog catalog) {
- this.catalogCollection.add(catalog);
- }
-
- @Override
- public String toString() {
- StringBuilder res = new StringBuilder();
- res.append("ReverseEngineering: ").append("\n");
-
- if (!isBlank(catalogCollection)) {
- for (Catalog catalog : catalogCollection) {
- catalog.toString(res, " ");
- }
- }
-
- if (skipRelationshipsLoading != null && skipRelationshipsLoading) {
- res.append("\n Skip Relationships Loading");
- }
- if (skipPrimaryKeyLoading != null && skipPrimaryKeyLoading) {
- res.append("\n Skip PrimaryKey Loading");
- }
-
- return super.toString(res, " ").toString();
- }
-
- public String getDefaultPackage() {
- return defaultPackage;
- }
-
- public boolean isForceDataMapCatalog() {
- return forceDataMapCatalog;
- }
-
- public boolean isForceDataMapSchema() {
- return forceDataMapSchema;
- }
-
- public String getMeaningfulPkTables() {
- return meaningfulPkTables;
- }
-
- public String getNamingStrategy() {
- return namingStrategy;
- }
-
- public String getStripFromTableNames() {
- return stripFromTableNames;
- }
-
- public boolean isUsePrimitives() {
- return usePrimitives;
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/660dd4b2/cayenne-server/src/main/java/org/apache/cayenne/dbimport/Schema.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/dbimport/Schema.java b/cayenne-server/src/main/java/org/apache/cayenne/dbimport/Schema.java
deleted file mode 100644
index 5c3592b..0000000
--- a/cayenne-server/src/main/java/org/apache/cayenne/dbimport/Schema.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*****************************************************************
- * 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.dbimport;
-
-/**
- * @since 4.0.
- */
-public class Schema extends FilterContainer {
-
- public Schema() {
- }
-
- public Schema(String name) {
- setName(name);
- }
-
- @Override
- public StringBuilder toString(StringBuilder res, String prefix) {
- res.append(prefix).append("Schema: ").append(getName()).append("\n");
- return super.toString(res, prefix + " ");
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/660dd4b2/cayenne-server/src/main/java/org/apache/cayenne/dbimport/SchemaContainer.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/dbimport/SchemaContainer.java b/cayenne-server/src/main/java/org/apache/cayenne/dbimport/SchemaContainer.java
deleted file mode 100644
index 935d1e8..0000000
--- a/cayenne-server/src/main/java/org/apache/cayenne/dbimport/SchemaContainer.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*****************************************************************
- * 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.dbimport;
-
-import java.util.Collection;
-import java.util.LinkedList;
-
-/**
- * @since 4.0
- */
-abstract class SchemaContainer extends FilterContainer {
-
- private final Collection<Schema> schemaCollection = new LinkedList<>();
-
- public Collection<Schema> getSchemas() {
- return schemaCollection;
- }
-
- public void addSchema(Schema schema) {
- this.schemaCollection.add(schema);
- }
-
- @Override
- public boolean isEmptyContainer() {
- if (!super.isEmptyContainer()) {
- return false;
- }
-
- if (schemaCollection.isEmpty()) {
- return true;
- }
-
- for (Schema schema : schemaCollection) {
- if (!schema.isEmptyContainer()) {
- return false;
- }
- }
- return true;
- }
-
- public StringBuilder toString(StringBuilder res, String prefix) {
- if (!isBlank(schemaCollection)) {
- for (Schema schema : schemaCollection) {
- schema.toString(res, prefix);
- }
- }
-
- return super.toString(res, prefix + " ");
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/660dd4b2/cayenne-server/src/main/java/org/apache/cayenne/dbimport/package-info.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/dbimport/package-info.java b/cayenne-server/src/main/java/org/apache/cayenne/dbimport/package-info.java
deleted file mode 100644
index fba062c..0000000
--- a/cayenne-server/src/main/java/org/apache/cayenne/dbimport/package-info.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*****************************************************************
- * 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.
- ****************************************************************/
-
-@XmlSchema(namespace="http://cayenne.apache.org/schema/8/reverseEngineering", elementFormDefault= XmlNsForm.QUALIFIED)
-package org.apache.cayenne.dbimport;
-
-import javax.xml.bind.annotation.XmlNsForm;
-import javax.xml.bind.annotation.XmlSchema;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cayenne/blob/660dd4b2/cayenne-server/src/test/java/org/apache/cayenne/dbimport/ReverseEngineeringUtils.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/dbimport/ReverseEngineeringUtils.java b/cayenne-server/src/test/java/org/apache/cayenne/dbimport/ReverseEngineeringUtils.java
deleted file mode 100644
index 627ae0f..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/dbimport/ReverseEngineeringUtils.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*****************************************************************
- * 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.dbimport;
-
-import java.util.Iterator;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-public class ReverseEngineeringUtils {
-
- public static void assertCatalog(ReverseEngineering engineering) {
- Iterator<Catalog> catalogs = engineering.getCatalogs().iterator();
- assertEquals("catalog-name-01", catalogs.next().getName());
- assertEquals("catalog-name-02", catalogs.next().getName());
-
- assertCatalog(catalogs.next());
- }
-
- public static void assertCatalog(Catalog catalog ) {
- assertEquals("catalog-name-03", catalog.getName());
-
- Iterator<IncludeTable> includeTables = catalog.getIncludeTables().iterator();
- assertEquals("includeTable-01", includeTables.next().getPattern());
- assertEquals("includeTable-02", includeTables.next().getPattern());
-
- IncludeTable includeTable = includeTables.next();
- assertEquals("includeTable-03", includeTable.getPattern());
- assertEquals("includeColumn-01", includeTable.getIncludeColumns().iterator().next().getPattern());
- assertEquals("excludeColumn-01", includeTable.getExcludeColumns().iterator().next().getPattern());
-
- Iterator<ExcludeTable> excludeTables = catalog.getExcludeTables().iterator();
- assertEquals("excludeTable-01", excludeTables.next().getPattern());
- assertEquals("excludeTable-02", excludeTables.next().getPattern());
- assertEquals("excludeTable-03", excludeTables.next().getPattern());
-
- Iterator<ExcludeColumn> excludeColumns = catalog.getExcludeColumns().iterator();
- assertEquals("excludeColumn-01", excludeColumns.next().getPattern());
- assertEquals("excludeColumn-02", excludeColumns.next().getPattern());
- assertEquals("excludeColumn-03", excludeColumns.next().getPattern());
- Iterator<IncludeColumn> includeColumns = catalog.getIncludeColumns().iterator();
- assertEquals("includeColumn-01", includeColumns.next().getPattern());
- assertEquals("includeColumn-02", includeColumns.next().getPattern());
- assertEquals("includeColumn-03", includeColumns.next().getPattern());
-
- Iterator<ExcludeProcedure> excludeProcedures = catalog.getExcludeProcedures().iterator();
- assertEquals("excludeProcedure-01", excludeProcedures.next().getPattern());
- assertEquals("excludeProcedure-02", excludeProcedures.next().getPattern());
- assertEquals("excludeProcedure-03", excludeProcedures.next().getPattern());
- Iterator<IncludeProcedure> includeProcedures = catalog.getIncludeProcedures().iterator();
- assertEquals("includeProcedure-01", includeProcedures.next().getPattern());
- assertEquals("includeProcedure-02", includeProcedures.next().getPattern());
- assertEquals("includeProcedure-03", includeProcedures.next().getPattern());
- }
-
- public static void assertSchema(ReverseEngineering engineering) {
- Iterator<Schema> schemas = engineering.getSchemas().iterator();
- assertEquals("schema-name-01", schemas.next().getName());
- assertEquals("schema-name-02", schemas.next().getName());
-
- Schema schema = schemas.next();
- assertEquals("schema-name-03", schema.getName());
-
- assertSchemaContent(schema);
- }
-
- public static void assertSchemaContent(Schema schema) {
- Iterator<IncludeTable> includeTables = schema.getIncludeTables().iterator();
- assertEquals("includeTable-01", includeTables.next().getPattern());
- assertEquals("includeTable-02", includeTables.next().getPattern());
-
- IncludeTable includeTable = includeTables.next();
- assertEquals("includeTable-03", includeTable.getPattern());
- assertEquals("includeColumn-01", includeTable.getIncludeColumns().iterator().next().getPattern());
- assertEquals("excludeColumn-01", includeTable.getExcludeColumns().iterator().next().getPattern());
-
- Iterator<ExcludeTable> excludeTables = schema.getExcludeTables().iterator();
- assertEquals("excludeTable-01", excludeTables.next().getPattern());
- assertEquals("excludeTable-02", excludeTables.next().getPattern());
- assertEquals("excludeTable-03", excludeTables.next().getPattern());
-
- Iterator<ExcludeColumn> excludeColumns = schema.getExcludeColumns().iterator();
- assertEquals("excludeColumn-01", excludeColumns.next().getPattern());
- assertEquals("excludeColumn-02", excludeColumns.next().getPattern());
- assertEquals("excludeColumn-03", excludeColumns.next().getPattern());
- Iterator<IncludeColumn> includeColumns = schema.getIncludeColumns().iterator();
- assertEquals("includeColumn-01", includeColumns.next().getPattern());
- assertEquals("includeColumn-02", includeColumns.next().getPattern());
- assertEquals("includeColumn-03", includeColumns.next().getPattern());
-
- Iterator<ExcludeProcedure> excludeProcedures = schema.getExcludeProcedures().iterator();
- assertEquals("excludeProcedure-01", excludeProcedures.next().getPattern());
- assertEquals("excludeProcedure-02", excludeProcedures.next().getPattern());
- assertEquals("excludeProcedure-03", excludeProcedures.next().getPattern());
- Iterator<IncludeProcedure> includeProcedures = schema.getIncludeProcedures().iterator();
- assertEquals("includeProcedure-01", includeProcedures.next().getPattern());
- assertEquals("includeProcedure-02", includeProcedures.next().getPattern());
- assertEquals("includeProcedure-03", includeProcedures.next().getPattern());
- }
-
- public static void assertCatalogAndSchema(ReverseEngineering engineering) {
- Catalog catalog = engineering.getCatalogs().iterator().next();
- assertEquals("catalog-name", catalog.getName());
-
- Schema schema = catalog.getSchemas().iterator().next();
- assertEquals("schema-name", schema.getName());
-
- assertSchemaContent(schema);
- }
-
- public static void assertFlat(ReverseEngineering engineering) {
- Iterator<IncludeTable> includeTables = engineering.getIncludeTables().iterator();
- assertEquals("includeTable-01", includeTables.next().getPattern());
- assertEquals("includeTable-02", includeTables.next().getPattern());
-
- IncludeTable includeTable = includeTables.next();
- assertEquals("includeTable-03", includeTable.getPattern());
- assertEquals("includeColumn-01", includeTable.getIncludeColumns().iterator().next().getPattern());
- assertEquals("excludeColumn-01", includeTable.getExcludeColumns().iterator().next().getPattern());
-
- Iterator<ExcludeTable> excludeTables = engineering.getExcludeTables().iterator();
- assertEquals("excludeTable-01", excludeTables.next().getPattern());
- assertEquals("excludeTable-02", excludeTables.next().getPattern());
- assertEquals("excludeTable-03", excludeTables.next().getPattern());
-
- Iterator<ExcludeColumn> excludeColumns = engineering.getExcludeColumns().iterator();
- assertEquals("excludeColumn-01", excludeColumns.next().getPattern());
- assertEquals("excludeColumn-02", excludeColumns.next().getPattern());
- assertEquals("excludeColumn-03", excludeColumns.next().getPattern());
- Iterator<IncludeColumn> includeColumns = engineering.getIncludeColumns().iterator();
- assertEquals("includeColumn-01", includeColumns.next().getPattern());
- assertEquals("includeColumn-02", includeColumns.next().getPattern());
- assertEquals("includeColumn-03", includeColumns.next().getPattern());
-
- Iterator<ExcludeProcedure> excludeProcedures = engineering.getExcludeProcedures().iterator();
- assertEquals("excludeProcedure-01", excludeProcedures.next().getPattern());
- assertEquals("excludeProcedure-02", excludeProcedures.next().getPattern());
- assertEquals("excludeProcedure-03", excludeProcedures.next().getPattern());
- Iterator<IncludeProcedure> includeProcedures = engineering.getIncludeProcedures().iterator();
- assertEquals("includeProcedure-01", includeProcedures.next().getPattern());
- assertEquals("includeProcedure-02", includeProcedures.next().getPattern());
- assertEquals("includeProcedure-03", includeProcedures.next().getPattern());
- }
-
- public static void assertSkipRelationshipsLoading(ReverseEngineering engineering) {
- assertTrue(engineering.getSkipRelationshipsLoading());
- }
-
- public static void assertSkipPrimaryKeyLoading(ReverseEngineering engineering) {
- assertTrue(engineering.getSkipPrimaryKeyLoading());
- }
-
- public static void assertTableTypes(ReverseEngineering engineering) {
- assertArrayEquals(new String[]{"type1", "type2", "type3"}, engineering.getTableTypes());
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/660dd4b2/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbGeneratorTask.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbGeneratorTask.java b/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbGeneratorTask.java
index 2319212..ce2e574 100644
--- a/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbGeneratorTask.java
+++ b/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbGeneratorTask.java
@@ -28,7 +28,7 @@ import org.apache.cayenne.di.Injector;
import org.apache.cayenne.log.NoopJdbcEventLogger;
import org.apache.cayenne.map.DataMap;
import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.tools.configuration.ToolsModule;
+import org.apache.cayenne.dbsync.reverse.configuration.ToolsModule;
import org.apache.cayenne.util.Util;
import org.apache.commons.logging.Log;
import org.apache.tools.ant.BuildException;
http://git-wip-us.apache.org/repos/asf/cayenne/blob/660dd4b2/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbImportConfigurationValidator.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbImportConfigurationValidator.java b/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbImportConfigurationValidator.java
deleted file mode 100644
index 8a92705..0000000
--- a/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbImportConfigurationValidator.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*****************************************************************
- * 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.tools;
-
-import org.apache.cayenne.configuration.DataNodeDescriptor;
-import org.apache.cayenne.configuration.server.DataSourceFactory;
-import org.apache.cayenne.configuration.server.DbAdapterFactory;
-import org.apache.cayenne.dba.DbAdapter;
-import org.apache.cayenne.dbimport.Catalog;
-import org.apache.cayenne.dbimport.ReverseEngineering;
-import org.apache.cayenne.di.Injector;
-import org.apache.cayenne.tools.dbimport.DbImportConfiguration;
-
-import java.util.Collection;
-import javax.sql.DataSource;
-
-class DbImportConfigurationValidator implements Cloneable {
- private final ReverseEngineering reverseEngineering;
- private final DbImportConfiguration config;
- private final Injector injector;
-
- DbImportConfigurationValidator(ReverseEngineering reverseEngineering, DbImportConfiguration config, Injector injector) {
- this.reverseEngineering = reverseEngineering;
- this.config = config;
- this.injector = injector;
- }
-
- void validate() throws Exception {
- DataNodeDescriptor dataNodeDescriptor = config.createDataNodeDescriptor();
- DbAdapter adapter;
-
- try {
- DataSource dataSource = injector.getInstance(DataSourceFactory.class).getDataSource(dataNodeDescriptor);
- adapter = injector.getInstance(DbAdapterFactory.class).createAdapter(dataNodeDescriptor, dataSource);
- } catch (Exception ex) {
- throw new Exception("Error creating DataSource or DbAdapter for DataNodeDescriptor (" + dataNodeDescriptor + ")", ex);
- }
-
- if (adapter != null && !adapter.supportsCatalogsOnReverseEngineering() && !isReverseEngineeringCatalogsEmpty()) {
- String message = "Your database does not support catalogs on reverse engineering. " +
- "It allows to connect to only one at the moment. " +
- "Please don't note catalogs in <dbimport> configuration.";
- throw new Exception(message);
- }
- }
-
- private boolean isReverseEngineeringCatalogsEmpty() {
- Collection<Catalog> catalogs = reverseEngineering.getCatalogs();
- if (catalogs == null || catalogs.isEmpty()) {
- return true;
- }
-
- for (Catalog catalog : catalogs) {
- if (catalog.getName() != null) {
- return false;
- }
- }
-
- return true;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cayenne/blob/660dd4b2/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbImporterTask.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbImporterTask.java b/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbImporterTask.java
index aa4b631..6c939c1 100644
--- a/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbImporterTask.java
+++ b/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbImporterTask.java
@@ -19,24 +19,25 @@
package org.apache.cayenne.tools;
import org.apache.cayenne.conn.DataSourceInfo;
-import org.apache.cayenne.dbimport.Catalog;
-import org.apache.cayenne.dbimport.ExcludeColumn;
-import org.apache.cayenne.dbimport.ExcludeProcedure;
-import org.apache.cayenne.dbimport.ExcludeTable;
-import org.apache.cayenne.dbimport.IncludeColumn;
-import org.apache.cayenne.dbimport.IncludeProcedure;
-import org.apache.cayenne.dbimport.IncludeTable;
-import org.apache.cayenne.dbimport.ReverseEngineering;
-import org.apache.cayenne.dbimport.Schema;
import org.apache.cayenne.dbsync.DbSyncModule;
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.DbImportModule;
+import org.apache.cayenne.dbsync.reverse.dbimport.ExcludeColumn;
+import org.apache.cayenne.dbsync.reverse.dbimport.ExcludeProcedure;
+import org.apache.cayenne.dbsync.reverse.dbimport.ExcludeTable;
+import org.apache.cayenne.dbsync.reverse.dbimport.IncludeColumn;
+import org.apache.cayenne.dbsync.reverse.dbimport.IncludeProcedure;
+import org.apache.cayenne.dbsync.reverse.dbimport.IncludeTable;
+import org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering;
+import org.apache.cayenne.dbsync.reverse.dbimport.Schema;
import org.apache.cayenne.dbsync.reverse.filters.FiltersConfigBuilder;
import org.apache.cayenne.di.DIBootstrap;
import org.apache.cayenne.di.Injector;
-import org.apache.cayenne.tools.configuration.ToolsModule;
-import org.apache.cayenne.tools.dbimport.DbImportAction;
-import org.apache.cayenne.tools.dbimport.DbImportConfiguration;
-import org.apache.cayenne.tools.dbimport.DbImportModule;
import org.apache.cayenne.util.Util;
import org.apache.commons.logging.Log;
import org.apache.tools.ant.BuildException;
@@ -114,11 +115,8 @@ public class DbImporterTask extends Task {
config.setSkipPrimaryKeyLoading(reverseEngineering.getSkipPrimaryKeyLoading());
config.setTableTypes(reverseEngineering.getTableTypes());
- Injector injector = DIBootstrap.createInjector(new DbSyncModule(),
- new ToolsModule(logger), new DbImportModule());
-
- DbImportConfigurationValidator validator = new DbImportConfigurationValidator(
- reverseEngineering, config, injector);
+ Injector injector = DIBootstrap.createInjector(new DbSyncModule(), new ToolsModule(logger), new DbImportModule());
+ DbImportConfigurationValidator validator = new DbImportConfigurationValidator(reverseEngineering, config, injector);
try {
validator.validate();
} catch (Exception ex) {
http://git-wip-us.apache.org/repos/asf/cayenne/blob/660dd4b2/cayenne-tools/src/main/java/org/apache/cayenne/tools/configuration/DriverDataSourceFactory.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/tools/configuration/DriverDataSourceFactory.java b/cayenne-tools/src/main/java/org/apache/cayenne/tools/configuration/DriverDataSourceFactory.java
deleted file mode 100644
index c5425d5..0000000
--- a/cayenne-tools/src/main/java/org/apache/cayenne/tools/configuration/DriverDataSourceFactory.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*****************************************************************
- * 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.tools.configuration;
-
-import java.sql.Driver;
-
-import javax.sql.DataSource;
-
-import org.apache.cayenne.configuration.DataNodeDescriptor;
-import org.apache.cayenne.configuration.server.DataSourceFactory;
-import org.apache.cayenne.conn.DataSourceInfo;
-import org.apache.cayenne.datasource.DriverDataSource;
-import org.apache.cayenne.di.AdhocObjectFactory;
-import org.apache.cayenne.di.Inject;
-
-/**
- * @since 4.0
- */
-public class DriverDataSourceFactory implements DataSourceFactory {
-
- private AdhocObjectFactory objectFactory;
-
- public DriverDataSourceFactory(@Inject AdhocObjectFactory objectFactory) {
- this.objectFactory = objectFactory;
- }
-
- public DataSource getDataSource(DataNodeDescriptor nodeDescriptor) throws Exception {
- DataSourceInfo properties = nodeDescriptor.getDataSourceDescriptor();
- if (properties == null) {
- throw new IllegalArgumentException("'nodeDescriptor' contains no datasource descriptor");
- }
-
- Driver driver = objectFactory.newInstance(Driver.class, properties.getJdbcDriver());
- return new DriverDataSource(driver, properties.getDataSourceUrl(), properties.getUserName(),
- properties.getPassword());
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/660dd4b2/cayenne-tools/src/main/java/org/apache/cayenne/tools/configuration/ToolsModule.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/tools/configuration/ToolsModule.java b/cayenne-tools/src/main/java/org/apache/cayenne/tools/configuration/ToolsModule.java
deleted file mode 100644
index 7abe3b0..0000000
--- a/cayenne-tools/src/main/java/org/apache/cayenne/tools/configuration/ToolsModule.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*****************************************************************
- * 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.tools.configuration;
-
-import org.apache.cayenne.access.translator.batch.BatchTranslatorFactory;
-import org.apache.cayenne.access.translator.batch.DefaultBatchTranslatorFactory;
-import org.apache.cayenne.configuration.Constants;
-import org.apache.cayenne.configuration.DefaultRuntimeProperties;
-import org.apache.cayenne.configuration.RuntimeProperties;
-import org.apache.cayenne.configuration.server.DataSourceFactory;
-import org.apache.cayenne.configuration.server.DbAdapterFactory;
-import org.apache.cayenne.configuration.server.DefaultDbAdapterFactory;
-import org.apache.cayenne.configuration.server.ServerModule;
-import org.apache.cayenne.dba.db2.DB2Sniffer;
-import org.apache.cayenne.dba.derby.DerbySniffer;
-import org.apache.cayenne.dba.firebird.FirebirdSniffer;
-import org.apache.cayenne.dba.frontbase.FrontBaseSniffer;
-import org.apache.cayenne.dba.h2.H2Sniffer;
-import org.apache.cayenne.dba.hsqldb.HSQLDBSniffer;
-import org.apache.cayenne.dba.ingres.IngresSniffer;
-import org.apache.cayenne.dba.mysql.MySQLSniffer;
-import org.apache.cayenne.dba.openbase.OpenBaseSniffer;
-import org.apache.cayenne.dba.oracle.OracleSniffer;
-import org.apache.cayenne.dba.postgres.PostgresSniffer;
-import org.apache.cayenne.dba.sqlite.SQLiteSniffer;
-import org.apache.cayenne.dba.sqlserver.SQLServerSniffer;
-import org.apache.cayenne.dba.sybase.SybaseSniffer;
-import org.apache.cayenne.di.AdhocObjectFactory;
-import org.apache.cayenne.di.Binder;
-import org.apache.cayenne.di.ClassLoaderManager;
-import org.apache.cayenne.di.Key;
-import org.apache.cayenne.di.Module;
-import org.apache.cayenne.di.spi.DefaultAdhocObjectFactory;
-import org.apache.cayenne.di.spi.DefaultClassLoaderManager;
-import org.apache.cayenne.log.CommonsJdbcEventLogger;
-import org.apache.cayenne.log.JdbcEventLogger;
-import org.apache.cayenne.resource.ClassLoaderResourceLocator;
-import org.apache.cayenne.resource.ResourceLocator;
-import org.apache.commons.logging.Log;
-
-/**
- * A DI module to bootstrap DI container for Cayenne Ant tasks and Maven
- * plugins.
- *
- * @since 4.0
- */
-public class ToolsModule implements Module {
-
- private Log logger;
-
- public ToolsModule(Log logger) {
-
- if (logger == null) {
- throw new NullPointerException("Null logger");
- }
-
- this.logger = logger;
- }
-
- public void configure(Binder binder) {
-
- binder.bind(Log.class).toInstance(logger);
-
- // configure empty global stack properties
- ServerModule.contributeProperties(binder);
-
- ServerModule.contributeDefaultTypes(binder);
- ServerModule.contributeUserTypes(binder);
- ServerModule.contributeTypeFactories(binder);
-
- binder.bind(ClassLoaderManager.class).to(DefaultClassLoaderManager.class);
- binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class);
- binder.bind(ResourceLocator.class).to(ClassLoaderResourceLocator.class);
- binder.bind(Key.get(ResourceLocator.class, Constants.SERVER_RESOURCE_LOCATOR)).to(ClassLoaderResourceLocator.class);
-
- binder.bind(RuntimeProperties.class).to(DefaultRuntimeProperties.class);
- binder.bind(BatchTranslatorFactory.class).to(DefaultBatchTranslatorFactory.class);
- binder.bind(JdbcEventLogger.class).to(CommonsJdbcEventLogger.class);
-
- ServerModule.contributeAdapterDetectors(binder).add(FirebirdSniffer.class).add(OpenBaseSniffer.class)
- .add(FrontBaseSniffer.class).add(IngresSniffer.class).add(SQLiteSniffer.class).add(DB2Sniffer.class)
- .add(H2Sniffer.class).add(HSQLDBSniffer.class).add(SybaseSniffer.class).add(DerbySniffer.class)
- .add(SQLServerSniffer.class).add(OracleSniffer.class).add(PostgresSniffer.class)
- .add(MySQLSniffer.class);
-
- binder.bind(DbAdapterFactory.class).to(DefaultDbAdapterFactory.class);
- binder.bind(DataSourceFactory.class).to(DriverDataSourceFactory.class);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/660dd4b2/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DbImportAction.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DbImportAction.java b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DbImportAction.java
deleted file mode 100644
index 757d5bf..0000000
--- a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DbImportAction.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.tools.dbimport;
-
-/**
- * An API of a strategy that can load DB schema and merge it to a new or an existing DataMap.
- *
- * @since 4.0
- */
-public interface DbImportAction {
-
- void execute(DbImportConfiguration config) throws Exception;
-
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/660dd4b2/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DbImportConfiguration.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DbImportConfiguration.java b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DbImportConfiguration.java
deleted file mode 100644
index b7e248b..0000000
--- a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DbImportConfiguration.java
+++ /dev/null
@@ -1,302 +0,0 @@
-/*
- * 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.tools.dbimport;
-
-import org.apache.cayenne.CayenneRuntimeException;
-import org.apache.cayenne.configuration.DataNodeDescriptor;
-import org.apache.cayenne.conn.DataSourceInfo;
-import org.apache.cayenne.dba.DbAdapter;
-import org.apache.cayenne.dbsync.filter.NameFilter;
-import org.apache.cayenne.dbsync.filter.NamePatternMatcher;
-import org.apache.cayenne.dbsync.reverse.dbload.DefaultModelMergeDelegate;
-import org.apache.cayenne.dbsync.reverse.dbload.ModelMergeDelegate;
-import org.apache.cayenne.dbsync.naming.DbEntityNameStemmer;
-import org.apache.cayenne.dbsync.naming.DefaultObjectNameGenerator;
-import org.apache.cayenne.dbsync.naming.NoStemStemmer;
-import org.apache.cayenne.dbsync.naming.ObjectNameGenerator;
-import org.apache.cayenne.dbsync.naming.PatternStemmer;
-import org.apache.cayenne.dbsync.reverse.dbload.DbLoaderConfiguration;
-import org.apache.cayenne.dbsync.reverse.dbload.DbLoaderDelegate;
-import org.apache.cayenne.dbsync.reverse.dbload.DefaultDbLoaderDelegate;
-import org.apache.cayenne.dbsync.reverse.dbload.LoggingDbLoaderDelegate;
-import org.apache.cayenne.dbsync.reverse.filters.FiltersConfig;
-import org.apache.commons.logging.Log;
-
-import java.io.File;
-import java.util.regex.Pattern;
-
-/**
- * @since 4.0
- */
-public class DbImportConfiguration {
-
- private static final String DATA_MAP_LOCATION_SUFFIX = ".map.xml";
-
- private final DataSourceInfo dataSourceInfo;
- private final DbLoaderConfiguration dbLoaderConfiguration;
- private File targetDataMap;
- private String defaultPackage;
- private String meaningfulPkTables;
- private String adapter;
- private boolean usePrimitives;
- private Log logger;
- private String namingStrategy;
- private String stripFromTableNames;
- private boolean forceDataMapCatalog;
- private boolean forceDataMapSchema;
-
- public DbImportConfiguration() {
- this.dataSourceInfo = new DataSourceInfo();
- this.dbLoaderConfiguration = new DbLoaderConfiguration();
- }
-
- public String getStripFromTableNames() {
- return stripFromTableNames;
- }
-
- public void setStripFromTableNames(String stripFromTableNames) {
- this.stripFromTableNames = stripFromTableNames;
- }
-
- public Log getLogger() {
- return logger;
- }
-
- public void setLogger(Log logger) {
- this.logger = logger;
- }
-
- /**
- * Returns DataMap XML file representing the target of the DB import operation.
- */
- public File getTargetDataMap() {
- return targetDataMap;
- }
-
- public void setTargetDataMap(File map) {
- this.targetDataMap = map;
- }
-
- /**
- * Returns a default package for ObjEntity Java classes.
- */
- public String getDefaultPackage() {
- return defaultPackage;
- }
-
- public void setDefaultPackage(String defaultPackage) {
- this.defaultPackage = defaultPackage;
- }
-
- public String getNamingStrategy() {
- return namingStrategy;
- }
-
- public void setNamingStrategy(String namingStrategy) {
- this.namingStrategy = namingStrategy;
- }
-
- /**
- * Returns the name of a Java class implementing {@link DbAdapter}. This attribute is optional, the default is
- * {@link org.apache.cayenne.dba.AutoAdapter}, i.e. Cayenne will try to guess the DB type.
- */
- public String getAdapter() {
- return adapter;
- }
-
- public void setAdapter(String adapter) {
- this.adapter = adapter;
- }
-
- /**
- * Returns a comma-separated list of Perl5 regular expressions that match
- * table names for which {@link DbImportAction} should include ObjAttribute
- * for PK.
- */
- public String getMeaningfulPkTables() {
- return meaningfulPkTables;
- }
-
- public void setMeaningfulPkTables(String meaningfulPkTables) {
- this.meaningfulPkTables = meaningfulPkTables;
- }
-
- public boolean isUsePrimitives() {
- return usePrimitives;
- }
-
- public void setUsePrimitives(boolean usePrimitives) {
- this.usePrimitives = usePrimitives;
- }
-
- public NameFilter createMeaningfulPKFilter() {
-
- if (meaningfulPkTables == null) {
- return NamePatternMatcher.EXCLUDE_ALL;
- }
-
- // TODO: this filter can't handle table names with comma in them
- String[] patternStrings = meaningfulPkTables.split(",");
- Pattern[] patterns = new Pattern[patternStrings.length];
- for (int i = 0; i < patterns.length; i++) {
- patterns[i] = Pattern.compile(patternStrings[i]);
- }
-
- return new NamePatternMatcher(patterns, new Pattern[0]);
- }
-
- public ObjectNameGenerator createNameGenerator() {
-
- // TODO: not a singleton; called from different places...
-
- // custom name generator
- // TODO: support stemmer in non-standard generators...
- // TODO: load via DI AdhocObjectFactory
- String namingStrategy = getNamingStrategy();
- if (namingStrategy != null && !namingStrategy.equals(DefaultObjectNameGenerator.class.getName())) {
- try {
- return (ObjectNameGenerator) Class.forName(namingStrategy).newInstance();
- } catch (Exception e) {
- throw new CayenneRuntimeException("Error creating name generator: " + namingStrategy, e);
- }
- }
-
- return new DefaultObjectNameGenerator(createStemmer());
- }
-
- protected DbEntityNameStemmer createStemmer() {
- return (stripFromTableNames == null || stripFromTableNames.length() == 0)
- ? NoStemStemmer.getInstance()
- : new PatternStemmer(stripFromTableNames, false);
- }
-
- public String getDriver() {
- return dataSourceInfo.getJdbcDriver();
- }
-
- public void setDriver(String jdbcDriver) {
- dataSourceInfo.setJdbcDriver(jdbcDriver);
- }
-
- public String getPassword() {
- return dataSourceInfo.getPassword();
- }
-
- public void setPassword(String password) {
- dataSourceInfo.setPassword(password);
- }
-
- public String getUsername() {
- return dataSourceInfo.getUserName();
- }
-
- public void setUsername(String userName) {
- dataSourceInfo.setUserName(userName);
- }
-
- public String getUrl() {
- return dataSourceInfo.getDataSourceUrl();
- }
-
- public void setUrl(String dataSourceUrl) {
- dataSourceInfo.setDataSourceUrl(dataSourceUrl);
- }
-
- public DataNodeDescriptor createDataNodeDescriptor() {
- DataNodeDescriptor nodeDescriptor = new DataNodeDescriptor();
- nodeDescriptor.setAdapterType(getAdapter());
- nodeDescriptor.setDataSourceDescriptor(dataSourceInfo);
-
- return nodeDescriptor;
- }
-
- public String getDataMapName() {
- String name = targetDataMap.getName();
- if (!name.endsWith(DATA_MAP_LOCATION_SUFFIX)) {
- throw new CayenneRuntimeException("DataMap file name must end with '%s': '%s'", DATA_MAP_LOCATION_SUFFIX,
- name);
- }
- return name.substring(0, name.length() - DATA_MAP_LOCATION_SUFFIX.length());
- }
-
- public ModelMergeDelegate createMergeDelegate() {
- return new DefaultModelMergeDelegate();
- }
-
- public DbLoaderDelegate createLoaderDelegate() {
- if (getLogger() != null) {
- return new LoggingDbLoaderDelegate(getLogger());
- } else {
- return new DefaultDbLoaderDelegate();
- }
- }
-
- /**
- * Returns configuration that should be used for DB import stage when the schema is loaded from the database.
- */
- public DbLoaderConfiguration getDbLoaderConfig() {
- return dbLoaderConfiguration;
- }
-
- public void setFiltersConfig(FiltersConfig filtersConfig) {
- dbLoaderConfiguration.setFiltersConfig(filtersConfig);
- }
-
- @Override
- public String toString() {
- StringBuilder res = new StringBuilder("Importer options:");
- for (String line : dbLoaderConfiguration.toString().split("\n")) {
- res.append(" ").append(line).append("\n");
- }
-
- return res.toString();
- }
-
- public DataSourceInfo getDataSourceInfo() {
- return dataSourceInfo;
- }
-
- public void setSkipRelationshipsLoading(Boolean skipRelationshipsLoading) {
- this.dbLoaderConfiguration.setSkipRelationshipsLoading(skipRelationshipsLoading);
- }
-
- public void setSkipPrimaryKeyLoading(Boolean skipPrimaryKeyLoading) {
- this.dbLoaderConfiguration.setSkipPrimaryKeyLoading(skipPrimaryKeyLoading);
- }
-
- public void setTableTypes(String[] tableTypes) {
- dbLoaderConfiguration.setTableTypes(tableTypes);
- }
-
- public void setForceDataMapCatalog(boolean forceDataMapCatalog) {
- this.forceDataMapCatalog = forceDataMapCatalog;
- }
-
- public boolean isForceDataMapCatalog() {
- return forceDataMapCatalog;
- }
-
- public void setForceDataMapSchema(boolean forceDataMapSchema) {
- this.forceDataMapSchema = forceDataMapSchema;
- }
-
- public boolean isForceDataMapSchema() {
- return forceDataMapSchema;
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/660dd4b2/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DbImportModule.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DbImportModule.java b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DbImportModule.java
deleted file mode 100644
index 93b5f6b..0000000
--- a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DbImportModule.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*****************************************************************
- * 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.tools.dbimport;
-
-import org.apache.cayenne.configuration.ConfigurationNameMapper;
-import org.apache.cayenne.configuration.DefaultConfigurationNameMapper;
-import org.apache.cayenne.dbsync.DbSyncModule;
-import org.apache.cayenne.di.Binder;
-import org.apache.cayenne.di.Module;
-import org.apache.cayenne.map.MapLoader;
-import org.apache.cayenne.project.FileProjectSaver;
-import org.apache.cayenne.project.ProjectSaver;
-import org.apache.cayenne.tools.configuration.ToolsModule;
-
-/**
- * A DI module that bootstraps {@link DbImportAction}. Should be used in
- * conjunction with {@link ToolsModule} and {@link DbSyncModule}.
- *
- * @since 4.0
- */
-public class DbImportModule implements Module {
-
- public void configure(Binder binder) {
- binder.bind(DbImportAction.class).to(DefaultDbImportAction.class);
- binder.bind(ProjectSaver.class).to(FileProjectSaver.class);
- binder.bind(ConfigurationNameMapper.class).to(DefaultConfigurationNameMapper.class);
- binder.bind(MapLoader.class).to(MapLoader.class);
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/660dd4b2/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DefaultDbImportAction.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DefaultDbImportAction.java b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DefaultDbImportAction.java
deleted file mode 100644
index 575b0a4..0000000
--- a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DefaultDbImportAction.java
+++ /dev/null
@@ -1,422 +0,0 @@
-/*
- * 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.tools.dbimport;
-
-import org.apache.cayenne.configuration.ConfigurationTree;
-import org.apache.cayenne.configuration.DataNodeDescriptor;
-import org.apache.cayenne.configuration.server.DataSourceFactory;
-import org.apache.cayenne.configuration.server.DbAdapterFactory;
-import org.apache.cayenne.dba.DbAdapter;
-import org.apache.cayenne.dbsync.filter.NameFilter;
-import org.apache.cayenne.dbsync.merge.token.model.AbstractToModelToken;
-import org.apache.cayenne.dbsync.merge.DataMapMerger;
-import org.apache.cayenne.dbsync.merge.context.MergerContext;
-import org.apache.cayenne.dbsync.merge.token.MergerToken;
-import org.apache.cayenne.dbsync.reverse.dbload.ModelMergeDelegate;
-import org.apache.cayenne.dbsync.reverse.dbload.ProxyModelMergeDelegate;
-import org.apache.cayenne.dbsync.merge.factory.MergerTokenFactory;
-import org.apache.cayenne.dbsync.merge.factory.MergerTokenFactoryProvider;
-import org.apache.cayenne.dbsync.naming.ObjectNameGenerator;
-import org.apache.cayenne.dbsync.reverse.dbload.DbLoader;
-import org.apache.cayenne.dbsync.reverse.dbload.DbLoaderConfiguration;
-import org.apache.cayenne.dbsync.reverse.filters.CatalogFilter;
-import org.apache.cayenne.dbsync.reverse.filters.FiltersConfig;
-import org.apache.cayenne.dbsync.reverse.filters.PatternFilter;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.map.DataMap;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.map.EntityResolver;
-import org.apache.cayenne.map.MapLoader;
-import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.map.ObjRelationship;
-import org.apache.cayenne.map.Procedure;
-import org.apache.cayenne.project.Project;
-import org.apache.cayenne.project.ProjectSaver;
-import org.apache.cayenne.resource.URLResource;
-import org.apache.cayenne.validation.SimpleValidationFailure;
-import org.apache.cayenne.validation.ValidationFailure;
-import org.apache.cayenne.validation.ValidationResult;
-import org.apache.commons.logging.Log;
-import org.xml.sax.InputSource;
-
-import javax.sql.DataSource;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.sql.Connection;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * A default implementation of {@link DbImportAction} that can load DB schema and merge it to a new or an existing
- * DataMap.
- *
- * @since 4.0
- */
-public class DefaultDbImportAction implements DbImportAction {
-
- private final ProjectSaver projectSaver;
- private final Log logger;
- private final DataSourceFactory dataSourceFactory;
- private final DbAdapterFactory adapterFactory;
- private final MapLoader mapLoader;
- private final MergerTokenFactoryProvider mergerTokenFactoryProvider;
-
- public DefaultDbImportAction(@Inject Log logger,
- @Inject ProjectSaver projectSaver,
- @Inject DataSourceFactory dataSourceFactory,
- @Inject DbAdapterFactory adapterFactory,
- @Inject MapLoader mapLoader,
- @Inject MergerTokenFactoryProvider mergerTokenFactoryProvider) {
- this.logger = logger;
- this.projectSaver = projectSaver;
- this.dataSourceFactory = dataSourceFactory;
- this.adapterFactory = adapterFactory;
- this.mapLoader = mapLoader;
- this.mergerTokenFactoryProvider = mergerTokenFactoryProvider;
- }
-
- protected static List<MergerToken> sort(List<MergerToken> reverse) {
- Collections.sort(reverse);
- return reverse;
- }
-
- /**
- * Flattens many-to-many relationships in the generated model.
- */
- public static void flattenManyToManyRelationships(DataMap map, Collection<ObjEntity> loadedObjEntities,
- ObjectNameGenerator objectNameGenerator) {
- if (loadedObjEntities.isEmpty()) {
- return;
- }
- Collection<ObjEntity> entitiesForDelete = new LinkedList<>();
-
- for (ObjEntity curEntity : loadedObjEntities) {
- ManyToManyCandidateEntity entity = ManyToManyCandidateEntity.build(curEntity);
-
- if (entity != null) {
- entity.optimizeRelationships(objectNameGenerator);
- entitiesForDelete.add(curEntity);
- }
- }
-
- // remove needed entities
- for (ObjEntity curDeleteEntity : entitiesForDelete) {
- map.removeObjEntity(curDeleteEntity.getName(), true);
- }
- loadedObjEntities.removeAll(entitiesForDelete);
- }
-
- @Override
- public void execute(DbImportConfiguration config) throws Exception {
-
- if (logger.isDebugEnabled()) {
- logger.debug("DB connection: " + config.getDataSourceInfo());
- logger.debug(config);
- }
-
- boolean hasChanges = false;
- DataNodeDescriptor dataNodeDescriptor = config.createDataNodeDescriptor();
- DataSource dataSource = dataSourceFactory.getDataSource(dataNodeDescriptor);
- DbAdapter adapter = adapterFactory.createAdapter(dataNodeDescriptor, dataSource);
- ObjectNameGenerator objectNameGenerator = config.createNameGenerator();
-
- DataMap sourceDataMap;
- try (Connection connection = dataSource.getConnection()) {
- sourceDataMap = load(config, adapter, connection);
- }
-
- DataMap targetDataMap = existingTargetMap(config);
- if (targetDataMap == null) {
-
- String path = config.getTargetDataMap() == null ? "null" : config.getTargetDataMap().getAbsolutePath() + "'";
-
- logger.info("");
- logger.info("Map file does not exist. Loaded db model will be saved into '" + path);
-
- hasChanges = true;
- targetDataMap = newTargetDataMap(config);
- }
-
- // transform source DataMap before merging
- transformSourceBeforeMerge(sourceDataMap, targetDataMap, config);
-
- MergerTokenFactory mergerTokenFactory = mergerTokenFactoryProvider.get(adapter);
-
- DbLoaderConfiguration loaderConfig = config.getDbLoaderConfig();
- List<MergerToken> tokens = DataMapMerger.builder(mergerTokenFactory)
- .filters(loaderConfig.getFiltersConfig())
- .skipPKTokens(loaderConfig.isSkipPrimaryKeyLoading())
- .skipRelationshipsTokens(loaderConfig.isSkipRelationshipsLoading())
- .build()
- .createMergeTokens(targetDataMap, sourceDataMap);
-
- hasChanges |= syncDataMapProperties(targetDataMap, config);
- hasChanges |= applyTokens(config.createMergeDelegate(),
- targetDataMap,
- log(sort(reverse(mergerTokenFactory, tokens))),
- objectNameGenerator,
- config.createMeaningfulPKFilter(),
- config.isUsePrimitives());
- hasChanges |= syncProcedures(targetDataMap, sourceDataMap, loaderConfig.getFiltersConfig());
-
- if (hasChanges) {
- saveLoaded(targetDataMap);
- }
- }
-
-
- protected void transformSourceBeforeMerge(DataMap sourceDataMap,
- DataMap targetDataMap,
- DbImportConfiguration configuration) {
-
- if (configuration.isForceDataMapCatalog()) {
- String catalog = targetDataMap.getDefaultCatalog();
- for (DbEntity e : sourceDataMap.getDbEntities()) {
- e.setCatalog(catalog);
- }
- }
-
- if (configuration.isForceDataMapSchema()) {
- String schema = targetDataMap.getDefaultSchema();
- for (DbEntity e : sourceDataMap.getDbEntities()) {
- e.setSchema(schema);
- }
- }
-
- }
-
- private boolean syncDataMapProperties(DataMap targetDataMap, DbImportConfiguration config) {
-
- String defaultPackage = config.getDefaultPackage();
- if (defaultPackage == null || defaultPackage.trim().length() == 0) {
- return false;
- }
-
- if (defaultPackage.equals(targetDataMap.getDefaultPackage())) {
- return false;
- }
-
- targetDataMap.setDefaultPackage(defaultPackage);
- return true;
- }
-
- private void relationshipsSanity(DataMap executed) {
- for (ObjEntity objEntity : executed.getObjEntities()) {
- List<ObjRelationship> rels = new LinkedList<>(objEntity.getRelationships());
- for (ObjRelationship rel : rels) {
- if (rel.getSourceEntity() == null || rel.getTargetEntity() == null) {
- logger.error("Incorrect obj relationship source or target entity is null: " + rel);
-
- objEntity.removeRelationship(rel.getName());
- }
- }
- }
- }
-
- private Collection<MergerToken> log(List<MergerToken> tokens) {
- logger.info("");
- if (tokens.isEmpty()) {
- logger.info("Detected changes: No changes to import.");
- return tokens;
- }
-
- logger.info("Detected changes: ");
- for (MergerToken token : tokens) {
- logger.info(String.format(" %-20s %s", token.getTokenName(), token.getTokenValue()));
- }
- logger.info("");
-
- return tokens;
- }
-
- protected DataMap existingTargetMap(DbImportConfiguration configuration) throws IOException {
-
- File file = configuration.getTargetDataMap();
- if (file != null && file.exists() && file.canRead()) {
- DataMap dataMap = mapLoader.loadDataMap(new InputSource(file.getCanonicalPath()));
- dataMap.setNamespace(new EntityResolver(Collections.singleton(dataMap)));
- dataMap.setConfigurationSource(new URLResource(file.toURI().toURL()));
-
- return dataMap;
- }
-
- return null;
- }
-
- protected DataMap newTargetDataMap(DbImportConfiguration config) throws IOException {
-
- DataMap dataMap = new DataMap();
-
- dataMap.setName(config.getDataMapName());
- dataMap.setConfigurationSource(new URLResource(config.getTargetDataMap().toURI().toURL()));
- dataMap.setNamespace(new EntityResolver(Collections.singleton(dataMap)));
-
- // update map defaults
-
- // do not override default package of existing DataMap unless it is
- // explicitly requested by the plugin caller
- String defaultPackage = config.getDefaultPackage();
- if (defaultPackage != null && defaultPackage.length() > 0) {
- dataMap.setDefaultPackage(defaultPackage);
- }
-
- CatalogFilter[] catalogs = config.getDbLoaderConfig().getFiltersConfig().getCatalogs();
- if (catalogs.length > 0) {
- // do not override default catalog of existing DataMap unless it is
- // explicitly requested by the plugin caller, and the provided catalog is
- // not a pattern
- String catalog = catalogs[0].name;
- if (catalog != null && catalog.length() > 0 && catalog.indexOf('%') < 0) {
- dataMap.setDefaultCatalog(catalog);
- }
-
- // do not override default schema of existing DataMap unless it is
- // explicitly requested by the plugin caller, and the provided schema is
- // not a pattern
- String schema = catalogs[0].schemas[0].name;
- if (schema != null && schema.length() > 0 && schema.indexOf('%') < 0) {
- dataMap.setDefaultSchema(schema);
- }
- }
-
- return dataMap;
- }
-
- private List<MergerToken> reverse(MergerTokenFactory mergerTokenFactory, Iterable<MergerToken> mergeTokens)
- throws IOException {
-
- List<MergerToken> tokens = new LinkedList<>();
- for (MergerToken token : mergeTokens) {
- if (token instanceof AbstractToModelToken) {
- continue;
- }
- tokens.add(token.createReverse(mergerTokenFactory));
- }
- return tokens;
- }
-
- private boolean applyTokens(ModelMergeDelegate mergeDelegate,
- DataMap targetDataMap,
- Collection<MergerToken> tokens,
- ObjectNameGenerator nameGenerator,
- NameFilter meaningfulPKFilter,
- boolean usingPrimitives) {
-
- if (tokens.isEmpty()) {
- logger.info("");
- logger.info("Detected changes: No changes to import.");
- return false;
- }
-
- final Collection<ObjEntity> loadedObjEntities = new LinkedList<>();
-
- mergeDelegate = new ProxyModelMergeDelegate(mergeDelegate) {
- @Override
- public void objEntityAdded(ObjEntity ent) {
- loadedObjEntities.add(ent);
- super.objEntityAdded(ent);
- }
- };
-
- MergerContext mergerContext = MergerContext.builder(targetDataMap)
- .delegate(mergeDelegate)
- .nameGenerator(nameGenerator)
- .usingPrimitives(usingPrimitives)
- .meaningfulPKFilter(meaningfulPKFilter)
- .build();
-
- for (MergerToken token : tokens) {
- try {
- token.execute(mergerContext);
- } catch (Throwable th) {
- String message = "Migration Error. Can't apply changes from token: " + token.getTokenName()
- + " (" + token.getTokenValue() + ")";
-
- logger.error(message, th);
- mergerContext.getValidationResult().addFailure(new SimpleValidationFailure(th, message));
- }
- }
-
- ValidationResult failures = mergerContext.getValidationResult();
- if (failures.hasFailures()) {
- logger.info("Migration Complete.");
- logger.warn("Migration finished. The following problem(s) were encountered and ignored.");
- for (ValidationFailure failure : failures.getFailures()) {
- logger.warn(failure.toString());
- }
- } else {
- logger.info("Migration Complete Successfully.");
- }
-
- flattenManyToManyRelationships(targetDataMap, loadedObjEntities, nameGenerator);
- relationshipsSanity(targetDataMap);
- return true;
- }
-
- private boolean syncProcedures(DataMap targetDataMap, DataMap loadedDataMap, FiltersConfig filters) {
- Collection<Procedure> procedures = loadedDataMap.getProcedures();
- if (procedures.isEmpty()) {
- return false;
- }
-
- boolean hasChanges = false;
- for (Procedure procedure : procedures) {
- PatternFilter proceduresFilter = filters.proceduresFilter(procedure.getCatalog(), procedure.getSchema());
- if (proceduresFilter == null || !proceduresFilter.isIncluded(procedure.getName())) {
- continue;
- }
-
- Procedure oldProcedure = targetDataMap.getProcedure(procedure.getName());
- // maybe we need to compare oldProcedure's and procedure's fully qualified names?
- if (oldProcedure != null) {
- targetDataMap.removeProcedure(procedure.getName());
- logger.info("Replace procedure " + procedure.getName());
- } else {
- logger.info("Add new procedure " + procedure.getName());
- }
- targetDataMap.addProcedure(procedure);
- hasChanges = true;
- }
- return hasChanges;
- }
-
- protected void saveLoaded(DataMap dataMap) throws FileNotFoundException {
- ConfigurationTree<DataMap> projectRoot = new ConfigurationTree<>(dataMap);
- Project project = new Project(projectRoot);
- projectSaver.save(project);
- }
-
- protected DataMap load(DbImportConfiguration config,
- DbAdapter adapter,
- Connection connection) throws Exception {
- return createDbLoader(adapter, connection, config).load();
- }
-
- protected DbLoader createDbLoader(DbAdapter adapter,
- Connection connection,
- DbImportConfiguration config) {
- return new DbLoader(adapter, connection,
- config.getDbLoaderConfig(),
- config.createLoaderDelegate(),
- config.createNameGenerator());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cayenne/blob/660dd4b2/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/ManyToManyCandidateEntity.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/ManyToManyCandidateEntity.java b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/ManyToManyCandidateEntity.java
deleted file mode 100644
index 7f183cf..0000000
--- a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/ManyToManyCandidateEntity.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*****************************************************************
- * 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.tools.dbimport;
-
-import org.apache.cayenne.dbsync.naming.NameBuilder;
-import org.apache.cayenne.dbsync.naming.ObjectNameGenerator;
-import org.apache.cayenne.map.DbRelationship;
-import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.map.ObjRelationship;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * An ObjEntity that may be removed as a result of flattenning relationships.
- */
-class ManyToManyCandidateEntity {
-
- private static final Log LOG = LogFactory.getLog(ManyToManyCandidateEntity.class);
-
- private final ObjEntity joinEntity;
-
- private final DbRelationship dbRel1;
- private final DbRelationship dbRel2;
-
- private final ObjEntity entity1;
- private final ObjEntity entity2;
-
- private final DbRelationship reverseRelationship1;
- private final DbRelationship reverseRelationship2;
-
- private ManyToManyCandidateEntity(ObjEntity entityValue, List<ObjRelationship> relationships) {
- joinEntity = entityValue;
-
- ObjRelationship rel1 = relationships.get(0);
- ObjRelationship rel2 = relationships.get(1);
-
- dbRel1 = rel1.getDbRelationships().get(0);
- dbRel2 = rel2.getDbRelationships().get(0);
-
- reverseRelationship1 = dbRel1.getReverseRelationship();
- reverseRelationship2 = dbRel2.getReverseRelationship();
-
- entity1 = rel1.getTargetEntity();
- entity2 = rel2.getTargetEntity();
- }
-
- /**
- * Method check - if current entity represent many to many temporary table
- *
- * @return true if current entity is represent many to many table; otherwise returns false
- */
- public static ManyToManyCandidateEntity build(ObjEntity joinEntity) {
- ArrayList<ObjRelationship> relationships = new ArrayList<>(joinEntity.getRelationships());
- if (relationships.size() != 2 || (relationships.get(0).getDbRelationships().isEmpty() || relationships.get(1).getDbRelationships().isEmpty())) {
- return null;
- }
-
- ManyToManyCandidateEntity candidateEntity = new ManyToManyCandidateEntity(joinEntity, relationships);
- if (candidateEntity.isManyToMany()) {
- return candidateEntity;
- }
-
- return null;
- }
-
- private boolean isManyToMany() {
- boolean isNotHaveAttributes = joinEntity.getAttributes().size() == 0;
-
- return isNotHaveAttributes
- && reverseRelationship1 != null && reverseRelationship1.isToDependentPK()
- && reverseRelationship2 != null && reverseRelationship2.isToDependentPK()
- && entity1 != null && entity2 != null;
- }
-
- private void addFlattenedRelationship(ObjectNameGenerator nameGenerator, ObjEntity srcEntity, ObjEntity dstEntity,
- DbRelationship rel1, DbRelationship rel2) {
-
- if (rel1.getSourceAttributes().isEmpty() && rel2.getTargetAttributes().isEmpty()) {
- LOG.warn("Wrong call ManyToManyCandidateEntity.addFlattenedRelationship(... , " + srcEntity.getName()
- + ", " + dstEntity.getName() + ", ...)");
-
- return;
- }
-
- ObjRelationship newRelationship = new ObjRelationship();
- newRelationship.setName(NameBuilder
- .builder(newRelationship, srcEntity)
- .baseName(nameGenerator.relationshipName(rel1, rel2))
- .name());
-
- newRelationship.setSourceEntity(srcEntity);
- newRelationship.setTargetEntityName(dstEntity);
-
- newRelationship.addDbRelationship(rel1);
- newRelationship.addDbRelationship(rel2);
-
- srcEntity.addRelationship(newRelationship);
- }
-
- /**
- * Method make direct relationships between 2 entities and remove relationships to
- * many to many entity
- *
- * @param nameGenerator
- */
- public void optimizeRelationships(ObjectNameGenerator nameGenerator) {
- entity1.removeRelationship(reverseRelationship1.getName());
- entity2.removeRelationship(reverseRelationship2.getName());
-
- addFlattenedRelationship(nameGenerator, entity1, entity2, reverseRelationship1, dbRel2);
- addFlattenedRelationship(nameGenerator, entity2, entity1, reverseRelationship2, dbRel1);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/660dd4b2/cayenne-tools/src/test/java/org/apache/cayenne/tools/DbGeneratorTaskTest.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/java/org/apache/cayenne/tools/DbGeneratorTaskTest.java b/cayenne-tools/src/test/java/org/apache/cayenne/tools/DbGeneratorTaskTest.java
index 12af0fd..bd02e12 100644
--- a/cayenne-tools/src/test/java/org/apache/cayenne/tools/DbGeneratorTaskTest.java
+++ b/cayenne-tools/src/test/java/org/apache/cayenne/tools/DbGeneratorTaskTest.java
@@ -22,9 +22,9 @@ package org.apache.cayenne.tools;
import org.apache.cayenne.dba.AutoAdapter;
import org.apache.cayenne.dba.DbAdapter;
import org.apache.cayenne.dba.sqlserver.SQLServerAdapter;
+import org.apache.cayenne.dbsync.reverse.configuration.ToolsModule;
import org.apache.cayenne.di.DIBootstrap;
import org.apache.cayenne.di.Injector;
-import org.apache.cayenne.tools.configuration.ToolsModule;
import org.apache.commons.logging.Log;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/cayenne/blob/660dd4b2/cayenne-tools/src/test/java/org/apache/cayenne/tools/DbImporterTaskTest.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/java/org/apache/cayenne/tools/DbImporterTaskTest.java b/cayenne-tools/src/test/java/org/apache/cayenne/tools/DbImporterTaskTest.java
index 3d898fc..df746c2 100644
--- a/cayenne-tools/src/test/java/org/apache/cayenne/tools/DbImporterTaskTest.java
+++ b/cayenne-tools/src/test/java/org/apache/cayenne/tools/DbImporterTaskTest.java
@@ -18,10 +18,10 @@
****************************************************************/
package org.apache.cayenne.tools;
+import org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration;
import org.apache.cayenne.test.file.FileUtil;
import org.apache.cayenne.test.jdbc.SQLReader;
import org.apache.cayenne.test.resource.ResourceUtil;
-import org.apache.cayenne.tools.dbimport.DbImportConfiguration;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectHelper;
import org.apache.tools.ant.UnknownElement;
@@ -44,7 +44,7 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
-import static org.apache.cayenne.dbimport.ReverseEngineeringUtils.*;
+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;
http://git-wip-us.apache.org/repos/asf/cayenne/blob/660dd4b2/cayenne-tools/src/test/java/org/apache/cayenne/tools/configuration/ToolsModuleTest.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/java/org/apache/cayenne/tools/configuration/ToolsModuleTest.java b/cayenne-tools/src/test/java/org/apache/cayenne/tools/configuration/ToolsModuleTest.java
deleted file mode 100644
index ae22f25..0000000
--- a/cayenne-tools/src/test/java/org/apache/cayenne/tools/configuration/ToolsModuleTest.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*****************************************************************
- * 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.tools.configuration;
-
-import org.apache.cayenne.configuration.DataNodeDescriptor;
-import org.apache.cayenne.configuration.server.DataSourceFactory;
-import org.apache.cayenne.configuration.server.DbAdapterFactory;
-import org.apache.cayenne.configuration.server.DefaultDbAdapterFactory;
-import org.apache.cayenne.dba.AutoAdapter;
-import org.apache.cayenne.di.AdhocObjectFactory;
-import org.apache.cayenne.di.DIBootstrap;
-import org.apache.cayenne.di.Injector;
-import org.apache.cayenne.di.spi.DefaultAdhocObjectFactory;
-import org.apache.commons.logging.Log;
-import org.junit.Test;
-
-import javax.sql.DataSource;
-
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-
-public class ToolsModuleTest {
-
- @Test
- public void testModuleContents() {
-
- Log log = mock(Log.class);
- Injector i = DIBootstrap.createInjector(new ToolsModule(log));
-
- assertSame(log, i.getInstance(Log.class));
- assertTrue(i.getInstance(DataSourceFactory.class) instanceof DriverDataSourceFactory);
- assertTrue(i.getInstance(AdhocObjectFactory.class) instanceof DefaultAdhocObjectFactory);
- assertTrue(i.getInstance(DbAdapterFactory.class) instanceof DefaultDbAdapterFactory);
- }
-
- @Test
- public void testDbApdater() throws Exception {
- Log log = mock(Log.class);
- Injector i = DIBootstrap.createInjector(new ToolsModule(log));
-
- DbAdapterFactory factory = i.getInstance(DbAdapterFactory.class);
-
- DataNodeDescriptor nodeDescriptor = mock(DataNodeDescriptor.class);
- DataSource dataSource = mock(DataSource.class);
-
- assertTrue(factory.createAdapter(nodeDescriptor, dataSource) instanceof AutoAdapter);
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/660dd4b2/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/DbImportModuleTest.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/DbImportModuleTest.java b/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/DbImportModuleTest.java
deleted file mode 100644
index 5e3e36a..0000000
--- a/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/DbImportModuleTest.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*****************************************************************
- * 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.tools.dbimport;
-
-import org.apache.cayenne.dbsync.DbSyncModule;
-import org.apache.cayenne.di.DIBootstrap;
-import org.apache.cayenne.di.Injector;
-import org.apache.cayenne.tools.configuration.ToolsModule;
-import org.apache.commons.logging.Log;
-import org.junit.Test;
-
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-
-public class DbImportModuleTest {
-
- @Test
- public void testModuleContents() {
-
- Log log = mock(Log.class);
- Injector i = DIBootstrap.createInjector(new DbSyncModule(), new ToolsModule(log), new DbImportModule());
- assertTrue(i.getInstance(DbImportAction.class) instanceof DbImportAction);
- }
-}