cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dkazimirc...@apache.org
Subject [8/8] cayenne git commit: CAY-2051 Fixes for reverse engineering in Modeler: configurtion file naming, catalog/schema handling, code formatting.
Date Fri, 26 Feb 2016 08:40:57 GMT
CAY-2051 Fixes for reverse engineering in Modeler: configurtion file naming, catalog/schema
handling, code formatting.


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/fdfeb3ac
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/fdfeb3ac
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/fdfeb3ac

Branch: refs/heads/master
Commit: fdfeb3ac45fbf81551c82bcc6b2478372fb215d8
Parents: b5bfbd5
Author: Olya Bondareva <ollybondareva@gmail.com>
Authored: Wed Feb 24 20:50:36 2016 +0100
Committer: Dzmitry Kazimirchyk <dkazimirchyk@gmail.com>
Committed: Fri Feb 26 11:38:58 2016 +0300

----------------------------------------------------------------------
 .../project/ReverseEngineeringSaverTest.java    |   2 +-
 .../org/apache/cayenne/access/DbLoader.java     |  20 ++
 .../DefaultConfigurationNameMapper.java         |   2 +-
 .../dbimport/ReverseEngineeringLoader.java      |   3 +-
 .../java/org/apache/cayenne/map/DataMap.java    |   2 +-
 .../java/org/apache/cayenne/map/MapLoader.java  |   2 +-
 .../apache/cayenne/tools/DbImporterTask.java    |  40 ++--
 .../tools/dbimport/DbImportActionDefault.java   |   7 +-
 .../dialog/db/DbImportActionModeler.java        |   6 +-
 .../dialog/db/ReverseEngineeringController.java | 226 +++++++++++++------
 .../dialog/db/ReverseEngineeringView.java       |  13 +-
 .../modeler/dialog/db/model/DBElement.java      |   9 +
 .../apache/cayenne/tools/DbImporterMojo.java    |  75 +++---
 13 files changed, 265 insertions(+), 142 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/fdfeb3ac/cayenne-project/src/test/java/org/apache/cayenne/project/ReverseEngineeringSaverTest.java
----------------------------------------------------------------------
diff --git a/cayenne-project/src/test/java/org/apache/cayenne/project/ReverseEngineeringSaverTest.java
b/cayenne-project/src/test/java/org/apache/cayenne/project/ReverseEngineeringSaverTest.java
index 38fe391..1176f19 100644
--- a/cayenne-project/src/test/java/org/apache/cayenne/project/ReverseEngineeringSaverTest.java
+++ b/cayenne-project/src/test/java/org/apache/cayenne/project/ReverseEngineeringSaverTest.java
@@ -53,7 +53,7 @@ public class ReverseEngineeringSaverTest extends Project2Case {
         DataMap dataMap1 = dataMapLoader.load(dataMap.getConfigurationSource());
         String reverseEngineeringName = dataMap1.getReverseEngineering().getName();
 
-        File reFile = new File(testFolder, reverseEngineeringName + ".reverseEngineering.xml");
+        File reFile = new File(testFolder, reverseEngineeringName + ".xml");
         assertTrue(reFile.exists());
         assertTrue(reFile.length() > 0);
     }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fdfeb3ac/cayenne-server/src/main/java/org/apache/cayenne/access/DbLoader.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/DbLoader.java b/cayenne-server/src/main/java/org/apache/cayenne/access/DbLoader.java
index af4358b..67477dd 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/DbLoader.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/DbLoader.java
@@ -118,6 +118,26 @@ public class DbLoader {
 	}
 
 	/**
+	 * Check if database support schemas.
+	 */
+	protected boolean supportSchemas() throws SQLException {
+		if (metaData == null) {
+			metaData = connection.getMetaData();
+		}
+		return metaData.supportsSchemasInTableDefinitions();
+	}
+
+	/**
+	 * Check if database support catalogs.
+	 */
+	protected boolean supportCatalogs() throws SQLException {
+		if (metaData == null) {
+			metaData = connection.getMetaData();
+		}
+		return metaData.supportsCatalogsInTableDefinitions();
+	}
+
+	/**
 	 * @since 3.0
 	 */
 	public void setCreatingMeaningfulPK(boolean creatingMeaningfulPK) {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fdfeb3ac/cayenne-server/src/main/java/org/apache/cayenne/configuration/DefaultConfigurationNameMapper.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/configuration/DefaultConfigurationNameMapper.java
b/cayenne-server/src/main/java/org/apache/cayenne/configuration/DefaultConfigurationNameMapper.java
index 24cea5d..16b782a 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/configuration/DefaultConfigurationNameMapper.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/configuration/DefaultConfigurationNameMapper.java
@@ -32,7 +32,7 @@ public class DefaultConfigurationNameMapper implements ConfigurationNameMapper
{
 
 	private static final String DATA_MAP_SUFFIX = ".map.xml";
 
-	private static final String REVERSE_ENGINEERING_SUFFIX = ".reverseEngineering.xml";
+	private static final String REVERSE_ENGINEERING_SUFFIX = ".xml";
 
 	protected ConfigurationNodeVisitor<String> nameMapper;
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fdfeb3ac/cayenne-server/src/main/java/org/apache/cayenne/dbimport/ReverseEngineeringLoader.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/dbimport/ReverseEngineeringLoader.java
b/cayenne-server/src/main/java/org/apache/cayenne/dbimport/ReverseEngineeringLoader.java
index b3dbb8d..83d0f45 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/dbimport/ReverseEngineeringLoader.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/dbimport/ReverseEngineeringLoader.java
@@ -31,6 +31,7 @@ import java.net.URL;
  */
 public interface ReverseEngineeringLoader {
 
-    ReverseEngineering load(InputStream inputStream) throws CayenneRuntimeException, SAXException,
ParserConfigurationException, IOException, ReverseEngineeringLoaderException;
+    ReverseEngineering load(InputStream inputStream) throws CayenneRuntimeException, SAXException,

+            ParserConfigurationException, IOException, ReverseEngineeringLoaderException;
 
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fdfeb3ac/cayenne-server/src/main/java/org/apache/cayenne/map/DataMap.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/map/DataMap.java b/cayenne-server/src/main/java/org/apache/cayenne/map/DataMap.java
index 9c511c8..a570d66 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/map/DataMap.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/map/DataMap.java
@@ -322,7 +322,7 @@ public class DataMap implements Serializable, ConfigurationNode, XMLSerializable
 		encoder.println(">");
 
         if (reverseEngineering != null) {
-            encoder.print("<reverseEngineering");
+			encoder.print("<reverse-engineering-config");
             encoder.printAttribute("name", reverseEngineering.getName().trim());
             encoder.println("/>");
         }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fdfeb3ac/cayenne-server/src/main/java/org/apache/cayenne/map/MapLoader.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/map/MapLoader.java b/cayenne-server/src/main/java/org/apache/cayenne/map/MapLoader.java
index c4787c7..213e38e 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/map/MapLoader.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/map/MapLoader.java
@@ -49,7 +49,7 @@ public class MapLoader extends DefaultHandler {
 	/**
 	 * @since 4.0
 	 */
-	public static final String REVERSE_ENGINEERING = "reverseEngineering";
+	public static final String REVERSE_ENGINEERING = "reverse-engineering-config";
 
 	public static final String PROPERTY_TAG = "property";
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fdfeb3ac/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 ddc44ae..119ebf4 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,11 +19,11 @@
 package org.apache.cayenne.tools;
 
 import java.io.File;
-import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
 
 import org.apache.cayenne.access.loader.filters.OldFilterConfigBridge;
+import org.apache.cayenne.configuration.ConfigurationNameMapper;
 import org.apache.cayenne.configuration.DataNodeDescriptor;
 import org.apache.cayenne.configuration.XMLDataMapLoader;
 import org.apache.cayenne.configuration.server.DataSourceFactory;
@@ -98,12 +98,10 @@ public class DbImporterTask extends Task {
 
                 log(message, Project.MSG_ERR);
                 throw new BuildException(message, th);
-            }
-            finally {
+            } finally {
                 injector.shutdown();
             }
-        }
-        else {
+        } else {
             if (dataMapFile.exists()) {
                 try {
                     URL url = dataMapFile.toURI().toURL();
@@ -112,21 +110,21 @@ public class DbImporterTask extends Task {
                     XMLDataMapLoader xmlDataMapLoader = new XMLDataMapLoader();
                     DataMap dataMap = xmlDataMapLoader.load(resource);
                     if (dataMap.getReverseEngineering() != null) {
-                        Resource reverseEngineeringResource = new URLResource(dataMapFile.toURL()).getRelativeResource(dataMap.getReverseEngineering().getName()
+ ".reverseEngineering.xml");
-
-                        DefaultReverseEngineeringLoader reverseEngineeringLoader = new DefaultReverseEngineeringLoader();
-                        ReverseEngineering reverseEngineering = reverseEngineeringLoader.load(reverseEngineeringResource.getURL().openStream());
-                        reverseEngineering.setName(dataMap.getReverseEngineering().getName());
-                        reverseEngineering.setConfigurationSource(reverseEngineeringResource);
-                        dataMap.setReverseEngineering(reverseEngineering);
-
-                        FiltersConfigBuilder filtersConfigBuilder = new FiltersConfigBuilder(dataMap.getReverseEngineering());
-                        config.getDbLoaderConfig().setFiltersConfig(filtersConfigBuilder.filtersConfig());
                         Injector injector = DIBootstrap.createInjector(new ToolsModule(logger),
new DbImportModule());
-
-                        validateDbImportConfiguration(config, injector);
-
                         try {
+                            ConfigurationNameMapper nameMapper = injector.getInstance(ConfigurationNameMapper.class);
+                            String reverseEngineeringLocation = nameMapper.configurationLocation(ReverseEngineering.class,
dataMap.getReverseEngineering().getName());
+                            Resource reverseEngineeringResource = new URLResource(dataMapFile.toURI().toURL()).getRelativeResource(reverseEngineeringLocation);
+
+                            DefaultReverseEngineeringLoader reverseEngineeringLoader = new
DefaultReverseEngineeringLoader();
+                            ReverseEngineering reverseEngineering = reverseEngineeringLoader.load(reverseEngineeringResource.getURL().openStream());
+                            reverseEngineering.setName(dataMap.getReverseEngineering().getName());
+                            reverseEngineering.setConfigurationSource(reverseEngineeringResource);
+                            dataMap.setReverseEngineering(reverseEngineering);
+
+                            FiltersConfigBuilder filtersConfigBuilder = new FiltersConfigBuilder(dataMap.getReverseEngineering());
+                            config.getDbLoaderConfig().setFiltersConfig(filtersConfigBuilder.filtersConfig());
+                            validateDbImportConfiguration(config, injector);
                             injector.getInstance(DbImportAction.class).execute(config);
                         } catch (Exception ex) {
                             Throwable th = Util.unwindException(ex);
@@ -139,17 +137,13 @@ public class DbImporterTask extends Task {
 
                             log(message, Project.MSG_ERR);
                             throw new BuildException(message, th);
-                        }
-                        finally {
+                        } finally {
                             injector.shutdown();
                         }
                     }
                 } catch (MalformedURLException e) {
                     log(e.getMessage(), Project.MSG_ERR);
                     throw new BuildException(e.getMessage(), e);
-                } catch (IOException e) {
-                    log(e.getMessage(), Project.MSG_ERR);
-                    throw new BuildException(e.getMessage(), e);
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fdfeb3ac/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DbImportActionDefault.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DbImportActionDefault.java
b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DbImportActionDefault.java
index aa58e56..fd1c235 100644
--- a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DbImportActionDefault.java
+++ b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DbImportActionDefault.java
@@ -210,7 +210,9 @@ public class DbImportActionDefault implements DbImportAction {
         return null;
     }
 
-    private List<MergerToken> reverse(MergerFactory mergerFactory, Iterable<MergerToken>
mergeTokens) throws IOException {
+    private List<MergerToken> reverse(
+            MergerFactory mergerFactory, 
+            Iterable<MergerToken> mergeTokens) throws IOException {
         List<MergerToken> tokens = new LinkedList<>();
         for (MergerToken token : mergeTokens) {
             if (token instanceof AbstractToModelToken) {
@@ -254,7 +256,8 @@ public class DbImportActionDefault implements DbImportAction {
         return dataMap;
     }
 
-    private DbLoader getLoader(DbImportConfiguration config, DbAdapter adapter, Connection
connection) throws InstantiationException, IllegalAccessException, ClassNotFoundException
{
+    private DbLoader getLoader(DbImportConfiguration config, DbAdapter adapter, Connection
connection) 
+            throws InstantiationException, IllegalAccessException, ClassNotFoundException
{
         return config.createLoader(adapter, connection, config.createLoaderDelegate());
     }
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fdfeb3ac/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbImportActionModeler.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbImportActionModeler.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbImportActionModeler.java
index b131dd8..150444b 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbImportActionModeler.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbImportActionModeler.java
@@ -29,7 +29,6 @@ import org.apache.cayenne.map.MapLoader;
 import org.apache.cayenne.map.event.MapEvent;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.ProjectController;
-import org.apache.cayenne.modeler.event.DataMapDisplayEvent;
 import org.apache.cayenne.project.ProjectSaver;
 import org.apache.cayenne.resource.Resource;
 import org.apache.cayenne.tools.dbimport.DbImportAction;
@@ -38,8 +37,6 @@ import org.apache.cayenne.tools.dbimport.DbImportConfiguration;
 import org.apache.commons.logging.Log;
 
 import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
 import java.sql.Connection;
 
 public class DbImportActionModeler implements DbImportAction {
@@ -102,7 +99,8 @@ public class DbImportActionModeler implements DbImportAction {
             }
 
             @Override
-            protected DataMap load(DbImportConfiguration config, DbAdapter adapter, Connection
connection) throws Exception {
+            protected DataMap load(DbImportConfiguration config, 
+                                   DbAdapter adapter, Connection connection) throws Exception
{
                 DataMap dataMap;
 
                 try {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fdfeb3ac/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/ReverseEngineeringController.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/ReverseEngineeringController.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/ReverseEngineeringController.java
index f084187..b2ac550 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/ReverseEngineeringController.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/ReverseEngineeringController.java
@@ -1,22 +1,21 @@
 /*****************************************************************
- * 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.
+ *   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.modeler.dialog.db;
 
 import org.apache.cayenne.access.DbLoader;
@@ -27,7 +26,6 @@ import org.apache.cayenne.access.loader.filters.SchemaFilter;
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.dbimport.FiltersConfigBuilder;
 import org.apache.cayenne.dbimport.ReverseEngineering;
-import org.apache.cayenne.dbimport.ReverseEngineeringLoaderException;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
@@ -117,25 +115,61 @@ public class ReverseEngineeringController extends CayenneController
{
         try {
             buildDBProperties();
 
-            DbLoader dbLoader = new DbLoader(connection, adapter, new DefaultDbLoaderDelegate())
{
+            final DbLoader dbLoader = new DbLoader(connection, adapter, new DefaultDbLoaderDelegate())
{
                 @Override
                 public DataMap load(DbLoaderConfiguration config) throws SQLException {
                     DataMap dataMap = new DataMap();
                     Map<String, Procedure> procedureMap = loadProcedures(dataMap, config);
-                    load(dataMap, config, procedureMap);
+                    load(dataMap, config);
+                    addProcedures(procedureMap);
                     return dataMap;
                 }
 
-                public void load(DataMap dataMap, DbLoaderConfiguration config, Map<String,
Procedure> procedureMap
-                )
-                        throws SQLException {
-                    LOGGER.info("Schema loading...");
-
-                    String[] types = config.getTableTypes();
-                    if (types == null || types.length == 0) {
-                        types = getDefaultTableTypes();
+                private void addProcedures(Map<String, Procedure> procedureMap) throws
SQLException {
+                    DBElement currentDBCatalog;
+                    DBElement currentDBSchema;
+                    for (Map.Entry<String, Procedure> procedure : procedureMap.entrySet())
{
+                        if (supportCatalogs()) {
+                            String dbCatalogName = procedure.getValue().getCatalog();
+                            DBElement dbCatalog = dbModel.getExistingElement(dbCatalogName);
+                            if (dbCatalog != null) {
+                                currentDBCatalog = dbCatalog;
+                            } else {
+                                currentDBCatalog = new DBCatalog(dbCatalogName);
+                                dbModel.addElement(currentDBCatalog);
+                            }
+                            if (supportSchemas()) {
+                                String dbSchemaName = procedure.getValue().getSchema();
+                                DBElement dbSchema = currentDBCatalog.getExistingElement(dbSchemaName);
+                                if (dbSchema != null) {
+                                    currentDBSchema = dbSchema;
+                                } else {
+                                    currentDBSchema = new DBSchema(dbSchemaName);
+                                    currentDBCatalog.addElement(currentDBSchema);
+                                }
+                                DBProcedure currentProcedure = new DBProcedure(procedure.getValue().getName());
+                                currentDBSchema.addElement(currentProcedure);
+                            } else {
+                                DBProcedure currentProcedure = new DBProcedure(procedure.getValue().getName());
+                                currentDBCatalog.addElement(currentProcedure);
+                            }
+                        } else if (supportSchemas()) {
+                            String dbSchemaName = procedure.getValue().getSchema();
+                            DBElement dbSchema = dbModel.getExistingElement(dbSchemaName);
+                            if (dbSchema != null) {
+                                currentDBSchema = dbSchema;
+                            } else {
+                                currentDBSchema = new DBSchema(dbSchemaName);
+                                dbModel.addElement(currentDBSchema);
+                            }
+                            DBProcedure currentProcedure = new DBProcedure(procedure.getValue().getName());
+                            currentDBSchema.addElement(currentProcedure);
+                        }
                     }
+                }
 
+                private void createIfNotNull(DataMap dataMap, DbLoaderConfiguration config,

+                                             String[] types) throws SQLException {
                     treeEditor.setRoot(dataSourceKey);
                     dbModel = new DBModel(dataSourceKey);
                     boolean catalogSetted = false;
@@ -144,13 +178,13 @@ public class ReverseEngineeringController extends CayenneController
{
 
                     for (CatalogFilter catalog : config.getFiltersConfig().catalogs) {
                         for (SchemaFilter schema : catalog.schemas) {
-                            boolean entityChecked = false;
-                            List<DbEntity> entityList = createTableLoader(catalog.name,
schema.name, schema.tables).loadDbEntities(
-                                    dataMap, config, types);
+                            List<DbEntity> entityList = 
+                                    createTableLoader(catalog.name, schema.name, schema.tables)
+                                            .loadDbEntities(dataMap, config, types);
                             DbEntity entityFromLoader = entityList.get(0);
 
                             if (entityFromLoader != null) {
-                                if (catalogSetted == false && entityFromLoader.getCatalog()
!= null) {
+                                if (!catalogSetted && entityFromLoader.getCatalog()
!= null) {
                                     currentDBCatalog = new DBCatalog(entityFromLoader.getCatalog());
                                     dbModel.addElement(currentDBCatalog);
                                     catalogSetted = true;
@@ -158,28 +192,7 @@ public class ReverseEngineeringController extends CayenneController {
 
                                 if (entityFromLoader.getSchema() != null) {
                                     currentDBSchema = new DBSchema(entityFromLoader.getSchema());
-                                    if(currentDBCatalog != null) {
-                                        currentDBCatalog.addElement(currentDBSchema);
-                                    } else {
-                                        dbModel.addElement(currentDBSchema);
-                                    }
-                                }
-                                entityChecked = true;
-                            }
-
-                            if (!entityChecked && !procedureMap.isEmpty()) {
-                                Map.Entry<String, Procedure> entry = procedureMap.entrySet().iterator().next();
-                                Procedure procedure = entry.getValue();
-
-                                if (catalogSetted && procedure.getCatalog() != null)
{
-                                    currentDBCatalog = new DBCatalog(procedure.getCatalog());
-                                    dbModel.addElement(currentDBCatalog);
-                                    catalogSetted = true;
-                                }
-
-                                if (procedure.getSchema() != null) {
-                                    currentDBSchema = new DBSchema(procedure.getSchema());
-                                    if(currentDBCatalog != null) {
+                                    if (currentDBCatalog != null) {
                                         currentDBCatalog.addElement(currentDBSchema);
                                     } else {
                                         dbModel.addElement(currentDBSchema);
@@ -205,22 +218,103 @@ public class ReverseEngineeringController extends CayenneController
{
                                     currentDBCatalog.addElement(currentDBEntity);
                                 }
                             }
-
-                            if (currentDBSchema != null) {
-                                for (Map.Entry<String, Procedure> entry : procedureMap.entrySet())
{
-                                    currentDBSchema.addElement(new DBProcedure(entry.getValue().getName()));
-                                }
-                            } else {
-                                for (Map.Entry<String, Procedure> entry : procedureMap.entrySet())
{
-                                    currentDBCatalog.addElement(new DBProcedure(entry.getValue().getName()));
-                                }
-                            }
                             currentDBSchema = null;
                         }
                         catalogSetted = false;
                         currentDBCatalog = null;
                     }
                 }
+
+                private void createIfNull(DataMap dataMap, DbLoaderConfiguration config,

+                                          String[] types) throws SQLException {
+                    
+                    treeEditor.setRoot(dataSourceKey);
+                    dbModel = new DBModel(dataSourceKey);
+                    DBElement currentDBCatalog;
+                    DBElement currentDBSchema;
+
+                    for (CatalogFilter catalog : config.getFiltersConfig().catalogs) {
+                        for (SchemaFilter schema : catalog.schemas) {
+                            List<DbEntity> entityList = 
+                                    createTableLoader(catalog.name, schema.name, schema.tables)
+                                            .loadDbEntities(dataMap, config, types);
+
+                            for (DbEntity dbEntity : entityList) {
+                                if (supportCatalogs()) {
+                                    String dbCatalogName = dbEntity.getCatalog();
+                                    DBElement dbCatalog = dbModel.getExistingElement(dbCatalogName);
+                                    if (dbCatalog != null) {
+                                        currentDBCatalog = dbCatalog;
+                                    } else {
+                                        currentDBCatalog = new DBCatalog(dbCatalogName);
+                                        dbModel.addElement(currentDBCatalog);
+                                    }
+                                    if (supportSchemas()) {
+                                        String dbSchemaName = dbEntity.getSchema();
+                                        DBElement dbSchema = currentDBCatalog.getExistingElement(dbSchemaName);
+                                        if (dbSchema != null) {
+                                            currentDBSchema = dbSchema;
+                                        } else {
+                                            currentDBSchema = new DBSchema(dbSchemaName);
+                                            currentDBCatalog.addElement(currentDBSchema);
+                                        }
+                                        DBEntity currentDBEntity = new DBEntity(dbEntity.getName());
+                                        currentDBSchema.addElement(currentDBEntity);
+                                        for (DbAttribute dbColumn : dbEntity.getAttributes())
{
+                                            currentDBEntity.addElement(new DBColumn(dbColumn.getName()));
+                                        }
+                                    } else {
+                                        DBEntity currentDBEntity = new DBEntity(dbEntity.getName());
+                                        currentDBCatalog.addElement(currentDBEntity);
+                                        for (DbAttribute dbColumn : dbEntity.getAttributes())
{
+                                            currentDBEntity.addElement(new DBColumn(dbColumn.getName()));
+                                        }
+                                    }
+                                } else {
+                                    if (supportSchemas()) {
+                                        String dbSchemaName = dbEntity.getSchema();
+                                        DBElement dbSchema = dbModel.getExistingElement(dbSchemaName);
+                                        if (dbSchema != null) {
+                                            currentDBSchema = dbSchema;
+                                        } else {
+                                            currentDBSchema = new DBSchema(dbSchemaName);
+                                            dbModel.addElement(currentDBSchema);
+                                        }
+                                        DBEntity currentDBEntity = new DBEntity(dbEntity.getName());
+                                        currentDBSchema.addElement(currentDBEntity);
+                                        for (DbAttribute dbColumn : dbEntity.getAttributes())
{
+                                            currentDBEntity.addElement(new DBColumn(dbColumn.getName()));
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+
+                public void load(DataMap dataMap, DbLoaderConfiguration config
+                )
+                        throws SQLException {
+                    LOGGER.info("Schema loading...");
+
+                    String[] types = config.getTableTypes();
+                    if (types == null || types.length == 0) {
+                        types = getDefaultTableTypes();
+                    }
+                    boolean isNullDetected = false;
+                    for (CatalogFilter catalog : config.getFiltersConfig().catalogs) {
+                        for (SchemaFilter schema : catalog.schemas) {
+                            if (schema.name == null && catalog.name == null) {
+                                isNullDetected = true;
+                            }
+                        }
+                    }
+                    if (isNullDetected) {
+                        createIfNull(dataMap, config, types);
+                    } else {
+                        createIfNotNull(dataMap, config, types);
+                    }
+                }
             };
 
             ReverseEngineering reverseEngineering = xmlFileEditor.convertTextIntoReverseEngineering();
@@ -238,8 +332,6 @@ public class ReverseEngineeringController extends CayenneController {
             dataMapViewModel.setReverseEngineeringText(xmlFileEditor.getView().getEditorPane().getText());
             reverseEngineeringMap.put(mapName, dataMapViewModel);
             treeEditor.convertTreeViewIntoTreeNode(dbModel);
-        } catch (ReverseEngineeringLoaderException e) {
-            xmlFileEditor.addAlertMessage(e.getMessage());
         } catch (Exception e) {
             xmlFileEditor.addAlertMessage(e.getMessage());
         }
@@ -274,8 +366,6 @@ public class ReverseEngineeringController extends CayenneController {
 
             th.start();
             view.setTempDataMap(projectController.getCurrentDataMap());
-        } catch (ReverseEngineeringLoaderException e) {
-            xmlFileEditor.addAlertMessage(e.getMessage());
         } catch (Exception e) {
             xmlFileEditor.addAlertMessage(e.getMessage());
         }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fdfeb3ac/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/ReverseEngineeringView.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/ReverseEngineeringView.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/ReverseEngineeringView.java
index 087ab26..80e0070 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/ReverseEngineeringView.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/ReverseEngineeringView.java
@@ -40,7 +40,6 @@ import javax.swing.JButton;
 import javax.swing.JComboBox;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
-import javax.swing.JSeparator;
 import javax.swing.JSplitPane;
 import java.awt.BorderLayout;
 import java.awt.FlowLayout;
@@ -52,7 +51,7 @@ import java.util.Map;
  */
 public class ReverseEngineeringView extends JPanel {
     protected ProjectController controller;
-    public ReverseEngineeringController reverseEngineeringController;
+    protected ReverseEngineeringController reverseEngineeringController;
     protected JPanel reverseEngineering;
 
     protected JComboBox dataSources;
@@ -61,7 +60,6 @@ public class ReverseEngineeringView extends JPanel {
     protected JButton executeButton;
 
     protected PanelBuilder builder;
-    protected JSeparator separator;
     protected JSplitPane splitPane;
     protected JLabel xmlLabel;
     protected JLabel treeLabel;
@@ -199,7 +197,8 @@ public class ReverseEngineeringView extends JPanel {
             if (dataMap != null) {
                 String reverseEngineeringText = null;
                 if (reverseEngineeringViewMap.containsKey(dataMap.getName())) {
-                    reverseEngineeringText = reverseEngineeringViewMap.get(dataMap.getName()).getReverseEngineeringText();
+                    reverseEngineeringText = reverseEngineeringViewMap
+                            .get(dataMap.getName()).getReverseEngineeringText();
                 }
                 if (reverseEngineeringText != null) {
                     xmlFileEditor.getView().getEditorPane().setText(reverseEngineeringText);
@@ -209,14 +208,16 @@ public class ReverseEngineeringView extends JPanel {
                     } else {
                         ReverseEngineering reverseEngineering = dataMap.getReverseEngineering();
                         if (reverseEngineering.getConfigurationSource() != null) {
-                            xmlFileEditor.getView().getEditorPane().setPage(reverseEngineering.getConfigurationSource().getURL());
+                            xmlFileEditor.getView().getEditorPane()
+                                    .setPage(reverseEngineering.getConfigurationSource().getURL());
                         }
                     }
                 }
 
                 if (reverseEngineeringViewMap.containsKey(dataMap.getName())) {
                     if (reverseEngineeringViewMap.get(dataMap.getName()).getReverseEngineeringTree()
!= null) {
-                        DBModel loadedPreviousTree = reverseEngineeringViewMap.get(dataMap.getName()).getReverseEngineeringTree();
+                        DBModel loadedPreviousTree = reverseEngineeringViewMap
+                                .get(dataMap.getName()).getReverseEngineeringTree();
                         treeEditor.convertTreeViewIntoTreeNode(loadedPreviousTree);
                     } else {
                         treeEditor.setRoot("");

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fdfeb3ac/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/model/DBElement.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/model/DBElement.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/model/DBElement.java
index b3a352f..c9c9411 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/model/DBElement.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/model/DBElement.java
@@ -37,6 +37,15 @@ public abstract class DBElement {
         return dbElements;
     }
 
+    public DBElement getExistingElement(String name) {
+        for (DBElement dbElement : dbElements) {
+            if (dbElement.name.equals(name)) {
+                return dbElement;
+            }
+        }
+        return null;
+    }
+
     public abstract void addElement(DBElement dbElement);
 
     public String getName() {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fdfeb3ac/plugins/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java
----------------------------------------------------------------------
diff --git a/plugins/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java
b/plugins/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java
index f3dfdc7..f3198d8 100644
--- a/plugins/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java
+++ b/plugins/maven-cayenne-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java
@@ -18,14 +18,15 @@
  ****************************************************************/
 package org.apache.cayenne.tools;
 
-import org.apache.cayenne.access.loader.filters.*;
+import org.apache.cayenne.access.loader.filters.OldFilterConfigBridge;
+import org.apache.cayenne.configuration.ConfigurationNameMapper;
 import org.apache.cayenne.configuration.DataNodeDescriptor;
 import org.apache.cayenne.configuration.XMLDataMapLoader;
 import org.apache.cayenne.configuration.server.DataSourceFactory;
 import org.apache.cayenne.configuration.server.DbAdapterFactory;
 import org.apache.cayenne.dba.DbAdapter;
+
 import java.io.File;
-import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
 
@@ -49,16 +50,16 @@ import javax.sql.DataSource;
 
 /**
  * Maven mojo to reverse engineer datamap from DB.
- * 
+ *
  * @since 3.0
- * 
+ *
  * @phase generate-sources
  * @goal cdbimport
  */
 public class DbImporterMojo extends AbstractMojo {
     /**
      * DataMap XML file to use as a base for DB importing.
-     * 
+     *
      * @parameter map="map"
      * @required
      */
@@ -68,7 +69,7 @@ public class DbImporterMojo extends AbstractMojo {
      * 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.
-     * 
+     *
      * @parameter defaultPackage="defaultPackage"
      * @since 4.0
      */
@@ -78,7 +79,7 @@ public class DbImporterMojo extends AbstractMojo {
      * Indicates that the old mapping should be completely removed and replaced
      * with the new data based on reverse engineering. Default is
      * <code>true</code>.
-     * 
+     *
      * @parameter overwrite="overwrite" default-value="true"
      */
     private boolean overwrite;
@@ -93,9 +94,9 @@ public class DbImporterMojo extends AbstractMojo {
      * Java class implementing org.apache.cayenne.map.naming.NamingStrategy.
      * This is used to specify how ObjEntities will be mapped from the imported
      * DB schema.
-     * 
+     *
      * The default is a basic naming strategy.
-     * 
+     *
      * @parameter namingStrategy="namingStrategy"
      *            default-value="org.apache.cayenne.map.naming.DefaultNameGenerator"
      */
@@ -105,7 +106,7 @@ public class DbImporterMojo extends AbstractMojo {
      * 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.
-     * 
+     *
      * @parameter adapter="adapter"
      *            default-value="org.apache.cayenne.dba.AutoAdapter"
      */
@@ -113,7 +114,7 @@ public class DbImporterMojo extends AbstractMojo {
 
     /**
      * A class of JDBC driver to use for the target database.
-     * 
+     *
      * @parameter driver="driver"
      * @required
      */
@@ -121,7 +122,7 @@ public class DbImporterMojo extends AbstractMojo {
 
     /**
      * JDBC connection URL of a target database.
-     * 
+     *
      * @parameter url="url"
      * @required
      */
@@ -129,21 +130,21 @@ public class DbImporterMojo extends AbstractMojo {
 
     /**
      * Database user name.
-     * 
+     *
      * @parameter username="username"
      */
     private String username;
 
     /**
      * Database user password.
-     * 
+     *
      * @parameter password="password"
      */
     private String password;
 
     /**
      * If true, would use primitives instead of numeric and boolean classes.
-     * 
+     *
      * @parameter usePrimitives="usePrimitives" default-value="true"
      */
     private boolean usePrimitives;
@@ -157,6 +158,16 @@ public class DbImporterMojo extends AbstractMojo {
      */
     private ReverseEngineering reverseEngineering = new ReverseEngineering();
 
+    /**
+     * Flag which defines from where to take the configuration of cdbImport.
+     * If we define the config of cdbImport in pom.xml
+     * we should set it to true or it will be setted to true automatically
+     * if we will define some configuration parameters in pom.xml
+     * Else it remains default(false) and for cdbImport
+     * we use the configuration defined in signed dataMap
+     *
+     *  @parameter isReverseEngineeringDefined="isReverseEngineeringDefined" default-value="false"
+     */
     private boolean isReverseEngineeringDefined = false;
 
     public void setIsReverseEngineeringDefined(boolean isReverseEngineeringDefined) {
@@ -283,8 +294,7 @@ public class DbImporterMojo extends AbstractMojo {
                 getLog().error(message);
                 throw new MojoExecutionException(message, th);
             }
-        }
-        else {
+        } else {
             if (dataMapFile.exists()) {
                 try {
                     URL url = dataMapFile.toURI().toURL();
@@ -293,21 +303,21 @@ public class DbImporterMojo extends AbstractMojo {
                     XMLDataMapLoader xmlDataMapLoader = new XMLDataMapLoader();
                     DataMap dataMap = xmlDataMapLoader.load(resource);
                     if (dataMap.getReverseEngineering() != null) {
-                        Resource reverseEngineeringResource = new URLResource(dataMapFile.toURI().toURL()).getRelativeResource(dataMap.getReverseEngineering().getName()
+ ".reverseEngineering.xml");
-
-                        DefaultReverseEngineeringLoader reverseEngineeringLoader = new DefaultReverseEngineeringLoader();
-                        ReverseEngineering reverseEngineering = reverseEngineeringLoader.load(reverseEngineeringResource.getURL().openStream());
-                        reverseEngineering.setName(dataMap.getReverseEngineering().getName());
-                        reverseEngineering.setConfigurationSource(reverseEngineeringResource);
-                        dataMap.setReverseEngineering(reverseEngineering);
-
-                        FiltersConfigBuilder filtersConfigBuilder = new FiltersConfigBuilder(dataMap.getReverseEngineering());
-                        config.getDbLoaderConfig().setFiltersConfig(filtersConfigBuilder.filtersConfig());
-                        Injector injector = DIBootstrap.createInjector(new ToolsModule(logger),
new DbImportModule());
-
-                        validateDbImportConfiguration(config, injector);
-
                         try {
+                            Injector injector = DIBootstrap.createInjector(new ToolsModule(logger),
new DbImportModule());
+                            ConfigurationNameMapper nameMapper = injector.getInstance(ConfigurationNameMapper.class);
+                            String reverseEngineeringLocation = nameMapper.configurationLocation(ReverseEngineering.class,
dataMap.getReverseEngineering().getName());
+                            Resource reverseEngineeringResource = new URLResource(dataMapFile.toURI().toURL()).getRelativeResource(reverseEngineeringLocation);
+
+                            DefaultReverseEngineeringLoader reverseEngineeringLoader = new
DefaultReverseEngineeringLoader();
+                            ReverseEngineering reverseEngineering = reverseEngineeringLoader.load(reverseEngineeringResource.getURL().openStream());
+                            reverseEngineering.setName(dataMap.getReverseEngineering().getName());
+                            reverseEngineering.setConfigurationSource(reverseEngineeringResource);
+                            dataMap.setReverseEngineering(reverseEngineering);
+
+                            FiltersConfigBuilder filtersConfigBuilder = new FiltersConfigBuilder(dataMap.getReverseEngineering());
+                            config.getDbLoaderConfig().setFiltersConfig(filtersConfigBuilder.filtersConfig());
+                            validateDbImportConfiguration(config, injector);
                             injector.getInstance(DbImportAction.class).execute(config);
                         } catch (Exception ex) {
                             Throwable th = Util.unwindException(ex);
@@ -325,9 +335,6 @@ public class DbImporterMojo extends AbstractMojo {
                 } catch (MalformedURLException e) {
                     getLog().error(e);
                     throw new MojoExecutionException(e.getMessage(), e);
-                } catch (IOException e) {
-                    getLog().error(e);
-                    throw new MojoExecutionException(e.getMessage(), e);
                 }
             }
         }


Mime
View raw message