cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1407633 - in /cayenne/main/trunk/framework: cayenne-tools/src/main/java/org/apache/cayenne/dbimport/ cayenne-tools/src/main/java/org/apache/cayenne/tools/ cayenne-tools/src/main/java/org/apache/cayenne/tools/configuration/ cayenne-tools/sr...
Date Fri, 09 Nov 2012 21:03:50 GMT
Author: aadamchik
Date: Fri Nov  9 21:03:49 2012
New Revision: 1407633

URL: http://svn.apache.org/viewvc?rev=1407633&view=rev
Log:
CAY-1758 cdbimport improvements

taking a step back to refactor the tools infrastructure
* creating a DI action for DB import reused by ant and maven

Added:
    cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/dbimport/DbImportAction.java
    cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/dbimport/DbImportModule.java
    cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/dbimport/DbImportParameters.java
    cayenne/main/trunk/framework/cayenne-tools/src/test/java/org/apache/cayenne/dbimport/DbImportActionTest.java
      - copied, changed from r1407613, cayenne/main/trunk/framework/maven-cayenne-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoTest.java
Removed:
    cayenne/main/trunk/framework/maven-cayenne-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoTest.java
Modified:
    cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/dbimport/ImportDbLoaderDelegate.java
    cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbGeneratorTask.java
    cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbImporterTask.java
    cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/configuration/ToolsModule.java
    cayenne/main/trunk/framework/cayenne-tools/src/test/java/org/apache/cayenne/tools/DbGeneratorTaskTest.java
    cayenne/main/trunk/framework/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbGeneratorMojo.java
    cayenne/main/trunk/framework/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java

Added: cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/dbimport/DbImportAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/dbimport/DbImportAction.java?rev=1407633&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/dbimport/DbImportAction.java (added)
+++ cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/dbimport/DbImportAction.java Fri Nov  9 21:03:49 2012
@@ -0,0 +1,169 @@
+/*****************************************************************
+ *   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.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.sql.Driver;
+
+import javax.sql.DataSource;
+
+import org.apache.cayenne.access.DbLoader;
+import org.apache.cayenne.configuration.DataNodeDescriptor;
+import org.apache.cayenne.configuration.server.DbAdapterFactory;
+import org.apache.cayenne.conn.DriverDataSource;
+import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.map.MapLoader;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.map.naming.NamingStrategy;
+import org.apache.cayenne.util.DeleteRuleUpdater;
+import org.apache.cayenne.util.XMLEncoder;
+import org.apache.commons.logging.Log;
+import org.xml.sax.InputSource;
+
+/**
+ * A thin wrapper around {@link DbLoader} that encapsulates DB import logic for
+ * the benefit of Ant and Maven db importers.
+ * 
+ * @since 3.2
+ */
+public class DbImportAction {
+
+    private DbAdapterFactory adapterFactory;
+    private Log logger;
+
+    public DbImportAction(Log logger, DbAdapterFactory adapterFactory) {
+        this.logger = logger;
+        this.adapterFactory = adapterFactory;
+    }
+
+    public void execute(DbImportParameters parameters) throws Exception {
+
+        if (logger.isInfoEnabled()) {
+            logger.debug(String.format("DB connection - [driver: %s, url: %s, username: %s, password: %s]",
+                    parameters.getDriver(), parameters.getUrl(), parameters.getUsername(), "XXXXX"));
+        }
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("Importer options - map: " + parameters.getMap());
+            logger.debug("Importer options - overwrite: " + parameters.isOverwrite());
+            logger.debug("Importer options - adapter: " + parameters.getAdapter());
+            logger.debug("Importer options - catalog: " + parameters.getCatalog());
+            logger.debug("Importer options - schema: " + parameters.getSchema());
+            logger.debug("Importer options - defaultPackage: " + parameters.getDefaultPackage());
+            logger.debug("Importer options - tablePattern: " + parameters.getTablePattern());
+            logger.debug("Importer options - importProcedures: " + parameters.isImportProcedures());
+            logger.debug("Importer options - procedurePattern: " + parameters.getProcedurePattern());
+            logger.debug("Importer options - meaningfulPk: " + parameters.isMeaningfulPk());
+            logger.debug("Importer options - namingStrategy: " + parameters.getNamingStrategy());
+        }
+
+        // TODO: load via DI
+        DriverDataSource dataSource = new DriverDataSource(
+                (Driver) Class.forName(parameters.getDriver()).newInstance(), parameters.getUrl(),
+                parameters.getUsername(), parameters.getPassword());
+
+        DbAdapter adapter = getAdapter(parameters.getAdapter(), dataSource);
+        DataMap dataMap = getDataMap(parameters);
+
+        ImportDbLoaderDelegate loaderDelegate = new ImportDbLoaderDelegate();
+        DbLoader loader = new DbLoader(dataSource.getConnection(), adapter, loaderDelegate);
+        loader.setCreatingMeaningfulPK(parameters.isMeaningfulPk());
+
+        // TODO: load via DI AdhocObjectFactory
+        String namingStrategy = parameters.getNamingStrategy();
+        if (namingStrategy != null) {
+            NamingStrategy namingStrategyInst = (NamingStrategy) Class.forName(namingStrategy).newInstance();
+            loader.setNamingStrategy(namingStrategyInst);
+        }
+
+        String[] types = loader.getDefaultTableTypes();
+        loader.load(dataMap, parameters.getCatalog(), parameters.getSchema(), parameters.getTablePattern(), types);
+
+        for (ObjEntity addedObjEntity : loaderDelegate.getAddedObjEntities()) {
+            DeleteRuleUpdater.updateObjEntity(addedObjEntity);
+        }
+
+        if (parameters.isImportProcedures()) {
+            loader.loadProcedures(dataMap, parameters.getCatalog(), parameters.getSchema(),
+                    parameters.getProcedurePattern());
+        }
+
+        parameters.getMap().delete();
+
+        PrintWriter pw = new PrintWriter(parameters.getMap());
+        XMLEncoder encoder = new XMLEncoder(pw, "\t");
+
+        encoder.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
+        dataMap.encodeAsXML(encoder);
+
+        pw.close();
+    }
+
+    DbAdapter getAdapter(String adapter, DataSource dataSource) throws Exception {
+
+        DataNodeDescriptor nodeDescriptor = new DataNodeDescriptor();
+        nodeDescriptor.setAdapterType(adapter);
+
+        return adapterFactory.createAdapter(nodeDescriptor, dataSource);
+    }
+
+    DataMap getDataMap(DbImportParameters parameters) throws IOException {
+
+        File dataMapFile = parameters.getMap();
+        DataMap dataMap;
+
+        if (dataMapFile.exists()) {
+            InputSource in = new InputSource(dataMapFile.getCanonicalPath());
+            dataMap = new MapLoader().loadDataMap(in);
+
+            if (parameters.isOverwrite()) {
+                dataMap.clearObjEntities();
+                dataMap.clearEmbeddables();
+                dataMap.clearProcedures();
+                dataMap.clearDbEntities();
+                dataMap.clearQueries();
+                dataMap.clearResultSets();
+            }
+        } else {
+            dataMap = new DataMap();
+        }
+
+        // update map defaults
+
+        // do not override default package of existing DataMap unless it is
+        // explicitly requested by the plugin caller
+        String defaultPackage = parameters.getDefaultPackage();
+        if (defaultPackage != null && defaultPackage.length() > 0) {
+            dataMap.setDefaultPackage(defaultPackage);
+        }
+
+        // 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 = parameters.getSchema();
+        if (schema != null && schema.length() > 0 && schema.indexOf('%') >= 0) {
+            dataMap.setDefaultSchema(schema);
+        }
+
+        return dataMap;
+    }
+}

Added: cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/dbimport/DbImportModule.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/dbimport/DbImportModule.java?rev=1407633&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/dbimport/DbImportModule.java (added)
+++ cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/dbimport/DbImportModule.java Fri Nov  9 21:03:49 2012
@@ -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.
+ ****************************************************************/
+package org.apache.cayenne.dbimport;
+
+import org.apache.cayenne.di.Binder;
+import org.apache.cayenne.di.Module;
+import org.apache.cayenne.tools.configuration.ToolsModule;
+
+/**
+ * A DI module that bootstraps {@link DbImportAction}. Should be used in
+ * conjunction with {@link ToolsModule}.
+ * 
+ * @since 3.2
+ */
+public class DbImportModule implements Module {
+
+    public void configure(Binder binder) {
+
+        binder.bind(DbImportAction.class);
+    }
+}

Added: cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/dbimport/DbImportParameters.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/dbimport/DbImportParameters.java?rev=1407633&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/dbimport/DbImportParameters.java (added)
+++ cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/dbimport/DbImportParameters.java Fri Nov  9 21:03:49 2012
@@ -0,0 +1,229 @@
+/*****************************************************************
+ *   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.io.File;
+
+/**
+ * @since 3.2
+ */
+public class DbImportParameters {
+
+    /**
+     * DataMap XML file to use as a base for DB importing.
+     */
+    private File map;
+
+    /**
+     * A default package for ObjEntity Java classes.
+     */
+    private String defaultPackage;
+
+    /**
+     * Indicates that the old mapping should be completely removed and replaced
+     * with the new data based on reverse engineering.
+     */
+    private boolean overwrite;
+
+    /**
+     * DB schema to use for DB importing.
+     */
+    private String catalog;
+
+    /**
+     * DB schema to use for DB importing.
+     */
+    private String schema;
+
+    /**
+     * Pattern for tables to import from DB
+     */
+    private String tablePattern;
+
+    /**
+     * Indicates whether stored procedures should be imported.
+     */
+    private boolean importProcedures;
+
+    /**
+     * Pattern for stored procedures to import from DB. This is only meaningful
+     * if <code>importProcedures</code> is set to <code>true</code>.
+     */
+    private String procedurePattern;
+
+    /**
+     * Indicates whether primary keys should be mapped as meaningful attributes
+     * in the object entities.
+     */
+    private boolean meaningfulPk;
+
+    /**
+     * Java class implementing org.apache.cayenne.map.naming.NamingStrategy.
+     * This is used to specify how ObjEntities will be mapped from the imported
+     * DB schema.
+     */
+    private String namingStrategy;
+
+    /**
+     * Java class implementing org.apache.cayenne.dba.DbAdapter. This attribute
+     * is optional, the default is AutoAdapter, i.e. Cayenne would try to guess
+     * the DB type.
+     */
+    private String adapter;
+
+    /**
+     * A class of JDBC driver to use for the target database.
+     */
+    private String driver;
+
+    /**
+     * JDBC connection URL of a target database.
+     */
+    private String url;
+
+    /**
+     * Database user name.
+     */
+    private String username;
+
+    /**
+     * Database user password.
+     */
+    private String password;
+
+    public File getMap() {
+        return map;
+    }
+
+    public void setMap(File map) {
+        this.map = map;
+    }
+
+    public String getDefaultPackage() {
+        return defaultPackage;
+    }
+
+    public void setDefaultPackage(String defaultPackage) {
+        this.defaultPackage = defaultPackage;
+    }
+
+    public boolean isOverwrite() {
+        return overwrite;
+    }
+
+    public void setOverwrite(boolean overwrite) {
+        this.overwrite = overwrite;
+    }
+
+    public String getCatalog() {
+        return catalog;
+    }
+
+    public void setCatalog(String catalog) {
+        this.catalog = catalog;
+    }
+
+    public String getSchema() {
+        return schema;
+    }
+
+    public void setSchema(String schema) {
+        this.schema = schema;
+    }
+
+    public String getTablePattern() {
+        return tablePattern;
+    }
+
+    public void setTablePattern(String tablePattern) {
+        this.tablePattern = tablePattern;
+    }
+
+    public boolean isImportProcedures() {
+        return importProcedures;
+    }
+
+    public void setImportProcedures(boolean importProcedures) {
+        this.importProcedures = importProcedures;
+    }
+
+    public String getProcedurePattern() {
+        return procedurePattern;
+    }
+
+    public void setProcedurePattern(String procedurePattern) {
+        this.procedurePattern = procedurePattern;
+    }
+
+    public boolean isMeaningfulPk() {
+        return meaningfulPk;
+    }
+
+    public void setMeaningfulPk(boolean meaningfulPk) {
+        this.meaningfulPk = meaningfulPk;
+    }
+
+    public String getNamingStrategy() {
+        return namingStrategy;
+    }
+
+    public void setNamingStrategy(String namingStrategy) {
+        this.namingStrategy = namingStrategy;
+    }
+
+    public String getAdapter() {
+        return adapter;
+    }
+
+    public void setAdapter(String adapter) {
+        this.adapter = adapter;
+    }
+
+    public String getDriver() {
+        return driver;
+    }
+
+    public void setDriver(String driver) {
+        this.driver = driver;
+    }
+
+    public String getUrl() {
+        return url;
+    }
+
+    public void setUrl(String url) {
+        this.url = url;
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+}

Modified: cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/dbimport/ImportDbLoaderDelegate.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/dbimport/ImportDbLoaderDelegate.java?rev=1407633&r1=1407632&r2=1407633&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/dbimport/ImportDbLoaderDelegate.java (original)
+++ cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/dbimport/ImportDbLoaderDelegate.java Fri Nov  9 21:03:49 2012
@@ -31,22 +31,21 @@ import org.apache.cayenne.map.ObjEntity;
 /**
  * @since 3.2
  */
-public class ImportDbLoaderDelegate implements DbLoaderDelegate {
+class ImportDbLoaderDelegate implements DbLoaderDelegate {
 
     private List<DbEntity> addedDbEntities;
     private List<DbEntity> removedDbEntities;
     private List<ObjEntity> addedObjEntities;
     private List<ObjEntity> removedObjEntities;
 
-    public ImportDbLoaderDelegate() {
+    ImportDbLoaderDelegate() {
         addedDbEntities = new ArrayList<DbEntity>();
         removedDbEntities = new ArrayList<DbEntity>();
         addedObjEntities = new ArrayList<ObjEntity>();
         removedObjEntities = new ArrayList<ObjEntity>();
     }
 
-    public boolean overwriteDbEntity(final DbEntity ent)
-            throws CayenneException {
+    public boolean overwriteDbEntity(final DbEntity ent) throws CayenneException {
         return false;
     }
 

Modified: cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbGeneratorTask.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbGeneratorTask.java?rev=1407633&r1=1407632&r2=1407633&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbGeneratorTask.java (original)
+++ cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbGeneratorTask.java Fri Nov  9 21:03:49 2012
@@ -32,6 +32,7 @@ import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.tools.configuration.ToolsModule;
 import org.apache.cayenne.util.Util;
+import org.apache.commons.logging.Log;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
 
@@ -55,7 +56,8 @@ public class DbGeneratorTask extends Cay
     @Override
     public void execute() {
 
-        Injector injector = DIBootstrap.createInjector(new ToolsModule());
+        Log logger = new AntLogger(this);
+        Injector injector = DIBootstrap.createInjector(new ToolsModule(logger));
 
         log(String.format(
                 "connection settings - [driver: %s, url: %s, username: %s]",

Modified: cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbImporterTask.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbImporterTask.java?rev=1407633&r1=1407632&r2=1407633&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbImporterTask.java (original)
+++ cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DbImporterTask.java Fri Nov  9 21:03:49 2012
@@ -19,117 +19,55 @@
 
 package org.apache.cayenne.tools;
 
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.sql.Driver;
-
-import org.apache.cayenne.access.DbLoader;
-import org.apache.cayenne.conn.DriverDataSource;
-import org.apache.cayenne.dba.DbAdapter;
-import org.apache.cayenne.dbimport.ImportDbLoaderDelegate;
+import java.io.File;
+
+import org.apache.cayenne.dbimport.DbImportAction;
+import org.apache.cayenne.dbimport.DbImportModule;
+import org.apache.cayenne.dbimport.DbImportParameters;
 import org.apache.cayenne.di.DIBootstrap;
 import org.apache.cayenne.di.Injector;
-import org.apache.cayenne.map.DataMap;
-import org.apache.cayenne.map.MapLoader;
-import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.map.naming.NamingStrategy;
 import org.apache.cayenne.tools.configuration.ToolsModule;
-import org.apache.cayenne.util.DeleteRuleUpdater;
 import org.apache.cayenne.util.Util;
-import org.apache.cayenne.util.XMLEncoder;
+import org.apache.commons.logging.Log;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
-import org.xml.sax.InputSource;
+import org.apache.tools.ant.Task;
 
-public class DbImporterTask extends CayenneTask {
+public class DbImporterTask extends Task {
 
-    private boolean overwrite = true;
+    private DbImportParameters parameters;
 
     /**
      * @deprecated since 3.2 in favor of "schema"
      */
     private String schemaName;
 
-    private String schema;
-
-    /**
-     * A default package for ObjEntity Java classes. If not specified, and the
-     * existing DataMap already has the default package, the existing package
-     * will be used.
-     * 
-     * @since 3.2
-     */
-    private String defaultPackage;
-
-    private String catalog;
-    private String tablePattern;
-    private boolean importProcedures = false;
-    private String procedurePattern;
-    private boolean meaningfulPk = false;
-    private String namingStrategy = "org.apache.cayenne.map.naming.SmartNamingStrategy";
+    public DbImporterTask() {
+        parameters = new DbImportParameters();
+        parameters.setOverwrite(true);
+        parameters.setImportProcedures(false);
+        parameters.setMeaningfulPk(false);
+        parameters.setNamingStrategy("org.apache.cayenne.map.naming.SmartNamingStrategy");
+    }
 
     @Override
     public void execute() {
 
-        log(String.format(
-                "connection settings - [driver: %s, url: %s, username: %s, password: %s]",
-                driver, url, userName, password), Project.MSG_VERBOSE);
-
-        log(String.format(
-                "importer options - [map: %s, overwrite: %s, schema: %s, tablePattern: %s, importProcedures: %s, procedurePattern: %s, meaningfulPk: %s, namingStrategy: %s]",
-                map, overwrite, getSchema(), tablePattern, importProcedures,
-                procedurePattern, meaningfulPk, namingStrategy),
-                Project.MSG_VERBOSE);
-
-        validateAttributes();
-
-        try {
-
-            // load driver taking custom CLASSPATH into account...
-            DriverDataSource dataSource = new DriverDataSource((Driver) Class
-                    .forName(driver).newInstance(), url, userName, password);
-
-            Injector injector = DIBootstrap.createInjector(new ToolsModule());
-            DbAdapter adapter = getAdapter(injector, dataSource);
-
-            // Load the data map and run the db importer.
-            ImportDbLoaderDelegate loaderDelegate = new ImportDbLoaderDelegate();
-            DbLoader loader = new DbLoader(dataSource.getConnection(), adapter,
-                    loaderDelegate);
-            loader.setCreatingMeaningfulPK(meaningfulPk);
-
-            if (namingStrategy != null) {
-                final NamingStrategy namingStrategyInst = (NamingStrategy) Class
-                        .forName(namingStrategy).newInstance();
-                loader.setNamingStrategy(namingStrategyInst);
-            }
-
-            String schema = getSchema();
-
-            DataMap dataMap = getDataMap();
-
-            String[] types = loader.getDefaultTableTypes();
-            loader.load(dataMap, catalog, schema, tablePattern, types);
+        if (schemaName != null) {
+            log("'schemaName' property is deprecated. Use 'schema' instead", Project.MSG_WARN);
+        }
 
-            for (ObjEntity addedObjEntity : loaderDelegate
-                    .getAddedObjEntities()) {
-                DeleteRuleUpdater.updateObjEntity(addedObjEntity);
-            }
+        if (parameters.getSchema() == null) {
+            parameters.setSchema(schemaName);
+        }
 
-            if (importProcedures) {
-                loader.loadProcedures(dataMap, catalog, schema,
-                        procedurePattern);
-            }
+        validateAttributes();
 
-            // Write the new DataMap out to disk.
-            map.delete();
-            PrintWriter pw = new PrintWriter(map);
-
-            XMLEncoder encoder = new XMLEncoder(pw, "\t");
-            encoder.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
-            dataMap.encodeAsXML(encoder);
+        Log logger = new AntLogger(this);
+        Injector injector = DIBootstrap.createInjector(new ToolsModule(logger), new DbImportModule());
 
-            pw.close();
+        try {
+            injector.getInstance(DbImportAction.class).execute(parameters);
         } catch (final Exception ex) {
             final Throwable th = Util.unwindException(ex);
 
@@ -144,45 +82,6 @@ public class DbImporterTask extends Caye
         }
     }
 
-    DataMap getDataMap() throws IOException {
-
-        DataMap dataMap;
-
-        if (map.exists()) {
-            InputSource in = new InputSource(map.getCanonicalPath());
-            dataMap = new MapLoader().loadDataMap(in);
-
-            if (overwrite) {
-                dataMap.clearObjEntities();
-                dataMap.clearEmbeddables();
-                dataMap.clearProcedures();
-                dataMap.clearDbEntities();
-                dataMap.clearQueries();
-                dataMap.clearResultSets();
-            }
-
-        } else {
-            dataMap = new DataMap();
-        }
-
-        // update map defaults
-
-        // do not override default package of existing DataMap unless it is
-        // explicitly requested by the plugin caller
-        if (defaultPackage != null && defaultPackage.length() > 0) {
-            dataMap.setDefaultPackage(defaultPackage);
-        }
-
-        // 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
-        if (schema != null && schema.length() > 0 && schema.indexOf('%') >= 0) {
-            dataMap.setDefaultSchema(schema);
-        }
-
-        return dataMap;
-    }
-
     /**
      * Validates attributes that are not related to internal
      * DefaultClassGenerator. Throws BuildException if attributes are invalid.
@@ -190,15 +89,15 @@ public class DbImporterTask extends Caye
     protected void validateAttributes() throws BuildException {
         StringBuilder error = new StringBuilder("");
 
-        if (map == null) {
+        if (parameters.getMap() == null) {
             error.append("The 'map' attribute must be set.\n");
         }
 
-        if (driver == null) {
+        if (parameters.getDriver() == null) {
             error.append("The 'driver' attribute must be set.\n");
         }
 
-        if (url == null) {
+        if (parameters.getUrl() == null) {
             error.append("The 'adapter' attribute must be set.\n");
         }
 
@@ -211,7 +110,7 @@ public class DbImporterTask extends Caye
      * @since 3.2
      */
     public void setOverwrite(boolean overwrite) {
-        this.overwrite = overwrite;
+        parameters.setOverwrite(overwrite);
     }
 
     /**
@@ -225,39 +124,57 @@ public class DbImporterTask extends Caye
      * @since 3.2
      */
     public void setSchema(String schema) {
-        this.schema = schema;
+        parameters.setSchema(schema);
     }
 
+    /**
+     * @since 3.2
+     */
     public void setDefaultPackage(String defaultPackage) {
-        this.defaultPackage = defaultPackage;
+        parameters.setDefaultPackage(defaultPackage);
     }
 
     public void setTablePattern(String tablePattern) {
-        this.tablePattern = tablePattern;
+        parameters.setTablePattern(tablePattern);
     }
 
     public void setImportProcedures(boolean importProcedures) {
-        this.importProcedures = importProcedures;
+        parameters.setImportProcedures(importProcedures);
     }
 
     public void setProcedurePattern(String procedurePattern) {
-        this.procedurePattern = procedurePattern;
+        parameters.setProcedurePattern(procedurePattern);
     }
 
     public void setMeaningfulPk(boolean meaningfulPk) {
-        this.meaningfulPk = meaningfulPk;
+        parameters.setMeaningfulPk(meaningfulPk);
     }
 
     public void setNamingStrategy(String namingStrategy) {
-        this.namingStrategy = namingStrategy;
+        parameters.setNamingStrategy(namingStrategy);
     }
 
-    private String getSchema() {
-        if (schemaName != null) {
-            log("'schemaName' property is deprecated. Use 'schema' instead",
-                    Project.MSG_WARN);
-        }
+    public void setAdapter(String adapter) {
+        parameters.setAdapter(adapter);
+    }
+
+    public void setDriver(String driver) {
+        parameters.setDriver(driver);
+    }
+
+    public void setMap(File map) {
+        parameters.setMap(map);
+    }
+
+    public void setPassword(String password) {
+        parameters.setPassword(password);
+    }
+
+    public void setUrl(String url) {
+        parameters.setUrl(url);
+    }
 
-        return schema != null ? schema : schemaName;
+    public void setUserName(String username) {
+        parameters.setUsername(username);
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/configuration/ToolsModule.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/configuration/ToolsModule.java?rev=1407633&r1=1407632&r2=1407633&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/configuration/ToolsModule.java (original)
+++ cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/configuration/ToolsModule.java Fri Nov  9 21:03:49 2012
@@ -44,6 +44,7 @@ import org.apache.cayenne.di.Module;
 import org.apache.cayenne.di.spi.DefaultAdhocObjectFactory;
 import org.apache.cayenne.log.CommonsJdbcEventLogger;
 import org.apache.cayenne.log.JdbcEventLogger;
+import org.apache.commons.logging.Log;
 
 /**
  * A DI module to bootstrap DI container for Cayenne Ant tasks and Maven
@@ -53,8 +54,21 @@ import org.apache.cayenne.log.JdbcEventL
  */
 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
         binder.bindMap(Constants.PROPERTIES_MAP);
 
@@ -88,6 +102,7 @@ public class ToolsModule implements Modu
                 .add(new MySQLSniffer(objectFactory));
 
         binder.bind(DbAdapterFactory.class).to(DefaultDbAdapterFactory.class);
+
     }
 
 }

Copied: cayenne/main/trunk/framework/cayenne-tools/src/test/java/org/apache/cayenne/dbimport/DbImportActionTest.java (from r1407613, cayenne/main/trunk/framework/maven-cayenne-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoTest.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-tools/src/test/java/org/apache/cayenne/dbimport/DbImportActionTest.java?p2=cayenne/main/trunk/framework/cayenne-tools/src/test/java/org/apache/cayenne/dbimport/DbImportActionTest.java&p1=cayenne/main/trunk/framework/maven-cayenne-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoTest.java&r1=1407613&r2=1407633&rev=1407633&view=diff
==============================================================================
--- cayenne/main/trunk/framework/maven-cayenne-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-tools/src/test/java/org/apache/cayenne/dbimport/DbImportActionTest.java Fri Nov  9 21:03:49 2012
@@ -16,40 +16,39 @@
  *  specific language governing permissions and limitations
  *  under the License.
  ****************************************************************/
-package org.apache.cayenne.tools;
+package org.apache.cayenne.dbimport;
 
 import static org.mockito.Mockito.mock;
 
-import java.lang.reflect.Field;
-
 import javax.sql.DataSource;
 
 import junit.framework.TestCase;
 
+import org.apache.cayenne.configuration.server.DbAdapterFactory;
 import org.apache.cayenne.dba.AutoAdapter;
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.dba.mysql.MySQLAdapter;
 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;
 
-public class DbImporterMojoTest extends TestCase {
+public class DbImportActionTest extends TestCase {
 
     public void testGetAdapter() throws Exception {
 
-        DbImporterMojo mojo = new DbImporterMojo();
+        Injector injector = DIBootstrap.createInjector(new ToolsModule(mock(Log.class)));
+
+        DbImportAction action = new DbImportAction(injector.getInstance(Log.class),
+                injector.getInstance(DbAdapterFactory.class));
 
         DataSource ds = mock(DataSource.class);
-        Injector injector = DIBootstrap.createInjector(new ToolsModule());
-        DbAdapter adapter = mojo.getAdapter(injector, ds);
+
+        DbAdapter adapter = action.getAdapter(null, ds);
         assertNotNull(adapter);
         assertTrue(adapter instanceof AutoAdapter);
 
-        Field adapterField = mojo.getClass().getDeclaredField("adapter");
-        adapterField.setAccessible(true);
-        adapterField.set(mojo, MySQLAdapter.class.getName());
-        
-        DbAdapter adapter2 = mojo.getAdapter(injector, ds);
+        DbAdapter adapter2 = action.getAdapter(MySQLAdapter.class.getName(), ds);
         assertNotNull(adapter2);
         assertTrue(adapter2 instanceof MySQLAdapter);
     }

Modified: cayenne/main/trunk/framework/cayenne-tools/src/test/java/org/apache/cayenne/tools/DbGeneratorTaskTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-tools/src/test/java/org/apache/cayenne/tools/DbGeneratorTaskTest.java?rev=1407633&r1=1407632&r2=1407633&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-tools/src/test/java/org/apache/cayenne/tools/DbGeneratorTaskTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-tools/src/test/java/org/apache/cayenne/tools/DbGeneratorTaskTest.java Fri Nov  9 21:03:49 2012
@@ -31,6 +31,7 @@ import org.apache.cayenne.dba.sqlserver.
 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;
 
 public class DbGeneratorTaskTest extends TestCase {
 
@@ -48,14 +49,13 @@ public class DbGeneratorTaskTest extends
 
     public void testSetAdapter() throws Exception {
         DataSource ds = mock(DataSource.class);
-        Injector injector = DIBootstrap.createInjector(new ToolsModule());
+        Injector injector = DIBootstrap.createInjector(new ToolsModule(mock(Log.class)));
 
         DbGeneratorTask task = new DbGeneratorTask();
-        
+
         DbAdapter autoAdapter = task.getAdapter(injector, ds);
         assertTrue(autoAdapter instanceof AutoAdapter);
-        
-        
+
         task.setAdapter(SQLServerAdapter.class.getName());
 
         DbAdapter sqlServerAdapter = task.getAdapter(injector, ds);

Modified: cayenne/main/trunk/framework/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbGeneratorMojo.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbGeneratorMojo.java?rev=1407633&r1=1407632&r2=1407633&view=diff
==============================================================================
--- cayenne/main/trunk/framework/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbGeneratorMojo.java (original)
+++ cayenne/main/trunk/framework/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbGeneratorMojo.java Fri Nov  9 21:03:49 2012
@@ -43,9 +43,9 @@ import org.xml.sax.InputSource;
 /**
  * Maven mojo to perform class generation from data map. This class is a Maven
  * adapter to DefaultClassGenerator class.
- *
+ * 
  * @since 3.0
- *
+ * 
  * @phase pre-integration-test
  * @goal cdbgen
  */
@@ -53,24 +53,24 @@ public class DbGeneratorMojo extends Abs
 
     /**
      * DataMap XML file to use as a schema descriptor.
-     *
+     * 
      * @parameter expression="${cdbgen.map}"
-	 * @required
+     * @required
      */
-	private File map;
+    private File map;
 
     /**
-     * Java class implementing org.apache.cayenne.dba.DbAdapter.
-     * While this attribute is optional (a generic JdbcAdapter is used if not set),
-     * it is highly recommended to specify correct target adapter.
-     *
+     * Java class implementing org.apache.cayenne.dba.DbAdapter. While this
+     * attribute is optional (a generic JdbcAdapter is used if not set), it is
+     * highly recommended to specify correct target adapter.
+     * 
      * @parameter expression="${cdbgen.adapter}"
      */
     private String adapter;
 
     /**
      * A class of JDBC driver to use for the target database.
-     *
+     * 
      * @parameter expression="${cdbgen.driver}"
      * @required
      */
@@ -78,7 +78,7 @@ public class DbGeneratorMojo extends Abs
 
     /**
      * JDBC connection URL of a target database.
-     *
+     * 
      * @parameter expression="${cdbgen.url}"
      * @required
      */
@@ -86,71 +86,73 @@ public class DbGeneratorMojo extends Abs
 
     /**
      * Database user name.
-     *
+     * 
      * @parameter expression="${cdbgen.username}"
      */
     private String username;
 
     /**
      * Database user password.
-     *
+     * 
      * @parameter expression="${cdbgen.password}"
      */
     private String password;
 
     /**
-     * Defines whether cdbgen should drop the tables before attempting to create new ones.
-     * Default is <code>false</code>.
-     *
+     * Defines whether cdbgen should drop the tables before attempting to create
+     * new ones. Default is <code>false</code>.
+     * 
      * @parameter expression="${cdbgen.dropTables}" default-value="false"
      */
     private boolean dropTables;
 
     /**
-     * Defines whether cdbgen should drop Cayenne primary key support objects. Default is <code>false</code>.
-     *
+     * Defines whether cdbgen should drop Cayenne primary key support objects.
+     * Default is <code>false</code>.
+     * 
      * @parameter expression="${cdbgen.dropPK}" default-value="false"
      */
     private boolean dropPK;
 
     /**
-     * Defines whether cdbgen should create new tables. Default is <code>true</code>.
-     *
+     * Defines whether cdbgen should create new tables. Default is
+     * <code>true</code>.
+     * 
      * @parameter expression="${cdbgen.createTables}" default-value="true"
      */
     private boolean createTables;
 
     /**
-     * Defines whether cdbgen should create Cayenne-specific auto PK objects. Default is <code>true</code>.
-     *
+     * Defines whether cdbgen should create Cayenne-specific auto PK objects.
+     * Default is <code>true</code>.
+     * 
      * @parameter expression="${cdbgen.createPK}" default-value="true"
      */
     private boolean createPK;
 
     /**
-     * Defines whether cdbgen should create foreign key copnstraints. Default is <code>true</code>.
-     *
+     * Defines whether cdbgen should create foreign key copnstraints. Default is
+     * <code>true</code>.
+     * 
      * @parameter expression="${cdbgen.createFK}' default-value="true"
      */
     private boolean createFK;
 
-
     public void execute() throws MojoExecutionException, MojoFailureException {
-    	
-    	Injector injector = DIBootstrap.createInjector(new ToolsModule());
-    	AdhocObjectFactory objectFactory = injector.getInstance(AdhocObjectFactory.class);
 
-		Log logger = new MavenLogger(this);
+        Log logger = new MavenLogger(this);
+        Injector injector = DIBootstrap.createInjector(new ToolsModule(logger));
+        AdhocObjectFactory objectFactory = injector.getInstance(AdhocObjectFactory.class);
 
         logger.info(String.format("connection settings - [driver: %s, url: %s, username: %s]", driver, url, username));
 
-        logger.info(String.format("generator options - [dropTables: %s, dropPK: %s, createTables: %s, createPK: %s, createFK: %s]",
+        logger.info(String.format(
+                "generator options - [dropTables: %s, dropPK: %s, createTables: %s, createPK: %s, createFK: %s]",
                 dropTables, dropPK, createTables, createPK, createFK));
 
         try {
-            final DbAdapter adapterInst = (adapter == null) ? 
-            		(DbAdapter)objectFactory.newInstance(DbAdapter.class, JdbcAdapter.class.getName()) : 
-            		(DbAdapter)objectFactory.newInstance(DbAdapter.class, adapter);
+            final DbAdapter adapterInst = (adapter == null) ? (DbAdapter) objectFactory.newInstance(DbAdapter.class,
+                    JdbcAdapter.class.getName()) : (DbAdapter) objectFactory.newInstance(DbAdapter.class, adapter);
 
             // Load the data map and run the db generator.
             DataMap dataMap = loadDataMap();
@@ -162,12 +164,11 @@ public class DbGeneratorMojo extends Abs
             generator.setShouldDropTables(dropTables);
 
             // load driver taking custom CLASSPATH into account...
-            DriverDataSource dataSource = new DriverDataSource((Driver) Class.forName(
-                    driver).newInstance(), url, username, password);
+            DriverDataSource dataSource = new DriverDataSource((Driver) Class.forName(driver).newInstance(), url,
+                    username, password);
 
             generator.runGenerator(dataSource);
-        }
-        catch (Exception ex) {
+        } catch (Exception ex) {
             Throwable th = Util.unwindException(ex);
 
             String message = "Error generating database";
@@ -186,5 +187,5 @@ public class DbGeneratorMojo extends Abs
         InputSource in = new InputSource(map.getCanonicalPath());
         return new MapLoader().loadDataMap(in);
     }
-    
+
 }

Modified: cayenne/main/trunk/framework/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java?rev=1407633&r1=1407632&r2=1407633&view=diff
==============================================================================
--- cayenne/main/trunk/framework/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java (original)
+++ cayenne/main/trunk/framework/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java Fri Nov  9 21:03:49 2012
@@ -20,32 +20,18 @@
 package org.apache.cayenne.tools;
 
 import java.io.File;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.sql.Driver;
-
-import javax.sql.DataSource;
-
-import org.apache.cayenne.access.DbLoader;
-import org.apache.cayenne.configuration.DataNodeDescriptor;
-import org.apache.cayenne.configuration.server.DbAdapterFactory;
-import org.apache.cayenne.conn.DriverDataSource;
-import org.apache.cayenne.dba.DbAdapter;
-import org.apache.cayenne.dbimport.ImportDbLoaderDelegate;
+
+import org.apache.cayenne.dbimport.DbImportAction;
+import org.apache.cayenne.dbimport.DbImportModule;
+import org.apache.cayenne.dbimport.DbImportParameters;
 import org.apache.cayenne.di.DIBootstrap;
 import org.apache.cayenne.di.Injector;
-import org.apache.cayenne.map.DataMap;
-import org.apache.cayenne.map.MapLoader;
-import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.map.naming.NamingStrategy;
 import org.apache.cayenne.tools.configuration.ToolsModule;
-import org.apache.cayenne.util.DeleteRuleUpdater;
 import org.apache.cayenne.util.Util;
-import org.apache.cayenne.util.XMLEncoder;
+import org.apache.commons.logging.Log;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
-import org.xml.sax.InputSource;
 
 /**
  * Maven mojo to reverse engineer datamap from DB.
@@ -201,20 +187,29 @@ public class DbImporterMojo extends Abst
 
     public void execute() throws MojoExecutionException, MojoFailureException {
 
-        getLog().debug(
-                String.format(
-                        "connection settings - [driver: %s, url: %s, username: %s, password: %s]",
-                        driver, url, username, password));
-
-        getLog().info(
-                String.format(
-                        "importer options - [map: %s, overwrite: %s, schema: %s, tablePattern: %s, importProcedures: %s, procedurePattern: %s, meaningfulPk: %s, namingStrategy: %s]",
-                        map, overwrite, getSchema(), tablePattern,
-                        importProcedures, procedurePattern, meaningfulPk,
-                        namingStrategy));
+        Log logger = new MavenLogger(this);
+
+        DbImportParameters parameters = new DbImportParameters();
+        parameters.setAdapter(adapter);
+        parameters.setCatalog(catalog);
+        parameters.setDefaultPackage(defaultPackage);
+        parameters.setDriver(driver);
+        parameters.setImportProcedures(importProcedures);
+        parameters.setMap(map);
+        parameters.setMeaningfulPk(meaningfulPk);
+        parameters.setNamingStrategy(namingStrategy);
+        parameters.setOverwrite(overwrite);
+        parameters.setPassword(password);
+        parameters.setProcedurePattern(procedurePattern);
+        parameters.setSchema(getSchema());
+        parameters.setTablePattern(tablePattern);
+        parameters.setUrl(url);
+        parameters.setUsername(username);
+
+        Injector injector = DIBootstrap.createInjector(new ToolsModule(logger), new DbImportModule());
 
         try {
-            doExecute();
+            injector.getInstance(DbImportAction.class).execute(parameters);
         } catch (Exception ex) {
             Throwable th = Util.unwindException(ex);
 
@@ -229,109 +224,9 @@ public class DbImporterMojo extends Abst
         }
     }
 
-    private void doExecute() throws Exception {
-
-        String schema = getSchema();
-
-        Injector injector = DIBootstrap.createInjector(new ToolsModule());
-
-        // load driver taking custom CLASSPATH into account...
-        DriverDataSource dataSource = new DriverDataSource((Driver) Class
-                .forName(driver).newInstance(), url, username, password);
-
-        DbAdapter adapter = getAdapter(injector, dataSource);
-
-        // Load the data map and run the db importer.
-        ImportDbLoaderDelegate loaderDelegate = new ImportDbLoaderDelegate();
-        DbLoader loader = new DbLoader(dataSource.getConnection(), adapter,
-                loaderDelegate);
-        loader.setCreatingMeaningfulPK(meaningfulPk);
-
-        if (namingStrategy != null) {
-            NamingStrategy namingStrategyInst = (NamingStrategy) Class.forName(
-                    namingStrategy).newInstance();
-            loader.setNamingStrategy(namingStrategyInst);
-        }
-
-        DataMap dataMap = getDataMap();
-
-        String[] types = loader.getDefaultTableTypes();
-        loader.load(dataMap, catalog, schema, tablePattern, types);
-
-        for (ObjEntity addedObjEntity : loaderDelegate.getAddedObjEntities()) {
-            DeleteRuleUpdater.updateObjEntity(addedObjEntity);
-        }
-
-        if (importProcedures) {
-            loader.loadProcedures(dataMap, catalog, schema, procedurePattern);
-        }
-
-        // Write the new DataMap out to disk.
-        map.delete();
-
-        PrintWriter pw = new PrintWriter(map);
-        XMLEncoder encoder = new XMLEncoder(pw, "\t");
-
-        encoder.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
-        dataMap.encodeAsXML(encoder);
-
-        pw.close();
-    }
-
-    DataMap getDataMap() throws IOException {
-
-        DataMap dataMap;
-
-        if (map.exists()) {
-            InputSource in = new InputSource(map.getCanonicalPath());
-            dataMap = new MapLoader().loadDataMap(in);
-
-            if (overwrite) {
-                dataMap.clearObjEntities();
-                dataMap.clearEmbeddables();
-                dataMap.clearProcedures();
-                dataMap.clearDbEntities();
-                dataMap.clearQueries();
-                dataMap.clearResultSets();
-            }
-        } else {
-            dataMap = new DataMap();
-        }
-
-        // update map defaults
-
-        // do not override default package of existing DataMap unless it is
-        // explicitly requested by the plugin caller
-        if (defaultPackage != null && defaultPackage.length() > 0) {
-            dataMap.setDefaultPackage(defaultPackage);
-        }
-
-        // 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
-        if (schema != null && schema.length() > 0 && schema.indexOf('%') >= 0) {
-            dataMap.setDefaultSchema(schema);
-        }
-
-        return dataMap;
-    }
-
-    DbAdapter getAdapter(Injector injector, DataSource dataSource)
-            throws Exception {
-
-        DbAdapterFactory adapterFactory = injector
-                .getInstance(DbAdapterFactory.class);
-
-        DataNodeDescriptor nodeDescriptor = new DataNodeDescriptor();
-        nodeDescriptor.setAdapterType(adapter);
-
-        return adapterFactory.createAdapter(nodeDescriptor, dataSource);
-    }
-
     private String getSchema() {
         if (schemaName != null) {
-            getLog().warn(
-                    "'schemaName' property is deprecated. Use 'schema' instead");
+            getLog().warn("'schemaName' property is deprecated. Use 'schema' instead");
         }
 
         return schema != null ? schema : schemaName;



Mime
View raw message