cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject cayenne git commit: refactoring DbImportConfiguration
Date Sat, 05 Nov 2016 10:48:19 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master 72dc1a3b4 -> cfb5171da


refactoring DbImportConfiguration


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

Branch: refs/heads/master
Commit: cfb5171da33dcaf78b06e4dcde641b5b3141b463
Parents: 72dc1a3
Author: Andrus Adamchik <andrus@objectstyle.com>
Authored: Sat Nov 5 12:46:11 2016 +0300
Committer: Andrus Adamchik <andrus@objectstyle.com>
Committed: Sat Nov 5 13:44:29 2016 +0300

----------------------------------------------------------------------
 .../tools/dbimport/DbImportConfiguration.java   |  7 ----
 .../tools/dbimport/DefaultDbImportAction.java   |  7 ++--
 .../dbimport/DefaultDbImportActionTest.java     | 35 ++++++++------------
 3 files changed, 18 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/cfb5171d/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DbImportConfiguration.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DbImportConfiguration.java
b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DbImportConfiguration.java
index 04c241d..ebc01e0 100644
--- a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DbImportConfiguration.java
+++ b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DbImportConfiguration.java
@@ -28,7 +28,6 @@ import org.apache.cayenne.dbsync.merge.DefaultModelMergeDelegate;
 import org.apache.cayenne.dbsync.merge.ModelMergeDelegate;
 import org.apache.cayenne.dbsync.naming.DefaultObjectNameGenerator;
 import org.apache.cayenne.dbsync.naming.ObjectNameGenerator;
-import org.apache.cayenne.dbsync.reverse.db.DbLoader;
 import org.apache.cayenne.dbsync.reverse.db.DbLoaderConfiguration;
 import org.apache.cayenne.dbsync.reverse.db.DbLoaderDelegate;
 import org.apache.cayenne.dbsync.reverse.db.DefaultDbLoaderDelegate;
@@ -37,7 +36,6 @@ import org.apache.cayenne.dbsync.reverse.filters.FiltersConfig;
 import org.apache.commons.logging.Log;
 
 import java.io.File;
-import java.sql.Connection;
 import java.util.regex.Pattern;
 
 /**
@@ -133,11 +131,6 @@ public class DbImportConfiguration {
         this.usePrimitives = usePrimitives;
     }
 
-    public DbLoader createLoader(DbAdapter adapter, Connection connection, DbLoaderDelegate
loaderDelegate)
-            throws InstantiationException, IllegalAccessException, ClassNotFoundException
{
-        return new DbLoader(connection, adapter, loaderDelegate, createNameGenerator());
-    }
-
     public NameFilter createMeaningfulPKFilter() {
 
         if (meaningfulPkTables == null) {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/cfb5171d/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DefaultDbImportAction.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DefaultDbImportAction.java
b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DefaultDbImportAction.java
index d19f44d..e7307de 100644
--- a/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DefaultDbImportAction.java
+++ b/cayenne-tools/src/main/java/org/apache/cayenne/tools/dbimport/DefaultDbImportAction.java
@@ -397,8 +397,11 @@ public class DefaultDbImportAction implements DbImportAction {
 
     protected DataMap load(DbImportConfiguration config, DbAdapter adapter, Connection connection)
throws Exception {
         DataMap dataMap = new DataMap("_import_source_");
-        DbLoader loader = config.createLoader(adapter, connection, config.createLoaderDelegate());
-        loader.load(dataMap, config.getDbLoaderConfig());
+        createDbLoader(config, adapter, connection).load(dataMap, config.getDbLoaderConfig());
         return dataMap;
     }
+
+    protected DbLoader createDbLoader(DbImportConfiguration config, DbAdapter adapter, Connection
connection) {
+        return new DbLoader(connection, adapter, config.createLoaderDelegate(), config.createNameGenerator());
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cayenne/blob/cfb5171d/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/DefaultDbImportActionTest.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/DefaultDbImportActionTest.java
b/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/DefaultDbImportActionTest.java
index e55fd89..20ccc1d 100644
--- a/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/DefaultDbImportActionTest.java
+++ b/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/DefaultDbImportActionTest.java
@@ -120,8 +120,6 @@ public class DefaultDbImportActionTest {
         };
 
         DbImportConfiguration config = mock(DbImportConfiguration.class);
-        when(config.createLoader(any(DbAdapter.class), any(Connection.class), any(DbLoaderDelegate.class)))
-                .thenReturn(dbLoader);
 
         when(config.createMergeDelegate()).thenReturn(new DefaultModelMergeDelegate());
         when(config.getDbLoaderConfig()).thenReturn(new DbLoaderConfiguration());
@@ -138,7 +136,7 @@ public class DefaultDbImportActionTest {
                 // Validation phase
                 assertTrue(project.getRootNode() instanceof DataMap);
             }
-        }, null);
+        }, null, dbLoader);
 
         action.execute(config);
 
@@ -164,8 +162,6 @@ public class DefaultDbImportActionTest {
         };
 
         DbImportConfiguration params = mock(DbImportConfiguration.class);
-        when(params.createLoader(any(DbAdapter.class), any(Connection.class), any(DbLoaderDelegate.class)))
-                .thenReturn(dbLoader);
 
         when(params.getTargetDataMap()).thenReturn(FILE_STUB);
         when(params.createMergeDelegate()).thenReturn(new DefaultModelMergeDelegate());
@@ -203,7 +199,7 @@ public class DefaultDbImportActionTest {
                                 objAttr("name").type(String.class).dbPath("NAME")
                         )).build();
             }
-        });
+        }, dbLoader);
 
         action.execute(params);
 
@@ -223,16 +219,10 @@ public class DefaultDbImportActionTest {
         };
 
         DbImportConfiguration params = mock(DbImportConfiguration.class);
-        when(params.createLoader(any(DbAdapter.class), any(Connection.class), any(DbLoaderDelegate.class)))
-                .thenReturn(dbLoader);
-
         when(params.getTargetDataMap()).thenReturn(FILE_STUB);
         when(params.createMergeDelegate()).thenReturn(new DefaultModelMergeDelegate());
         when(params.getDbLoaderConfig()).thenReturn(new DbLoaderConfiguration());
 
-        Log log = mock(Log.class);
-        when(log.isDebugEnabled()).thenReturn(false);
-        when(log.isInfoEnabled()).thenReturn(false);
 
         FileProjectSaver projectSaver = mock(FileProjectSaver.class);
         doNothing().when(projectSaver).save(any(Project.class));
@@ -243,7 +233,7 @@ public class DefaultDbImportActionTest {
                         dbAttr("NAME").typeVarchar(100).mandatory()
                 )).build());
 
-        DefaultDbImportAction action = buildDbImportAction(log, projectSaver, mapLoader);
+        DefaultDbImportAction action = buildDbImportAction(projectSaver, mapLoader, dbLoader);
 
         action.execute(params);
 
@@ -258,8 +248,6 @@ public class DefaultDbImportActionTest {
         doThrow(new SQLException()).when(dbLoader).load(any(DataMap.class), any(DbLoaderConfiguration.class));
 
         DbImportConfiguration params = mock(DbImportConfiguration.class);
-        when(params.createLoader(any(DbAdapter.class), any(Connection.class), any(DbLoaderDelegate.class)))
-                .thenReturn(dbLoader);
 
         FileProjectSaver projectSaver = mock(FileProjectSaver.class);
         doNothing().when(projectSaver).save(any(Project.class));
@@ -267,7 +255,7 @@ public class DefaultDbImportActionTest {
         MapLoader mapLoader = mock(MapLoader.class);
         when(mapLoader.loadDataMap(any(InputSource.class))).thenReturn(null);
 
-        DefaultDbImportAction action = buildDbImportAction(projectSaver, mapLoader);
+        DefaultDbImportAction action = buildDbImportAction(projectSaver, mapLoader, dbLoader);
 
         try {
             action.execute(params);
@@ -280,15 +268,13 @@ public class DefaultDbImportActionTest {
         verify(mapLoader, never()).loadDataMap(any(InputSource.class));
     }
 
-    private DefaultDbImportAction buildDbImportAction(FileProjectSaver projectSaver, MapLoader
mapLoader) throws Exception {
+    private DefaultDbImportAction buildDbImportAction(FileProjectSaver projectSaver, MapLoader
mapLoader, final DbLoader dbLoader)
+            throws Exception {
+
         Log log = mock(Log.class);
         when(log.isDebugEnabled()).thenReturn(true);
         when(log.isInfoEnabled()).thenReturn(true);
 
-        return buildDbImportAction(log, projectSaver, mapLoader);
-    }
-
-    private DefaultDbImportAction buildDbImportAction(Log log, FileProjectSaver projectSaver,
MapLoader mapLoader) throws Exception {
         DbAdapter dbAdapter = mock(DbAdapter.class);
 
         DbAdapterFactory adapterFactory = mock(DbAdapterFactory.class);
@@ -301,7 +287,12 @@ public class DefaultDbImportActionTest {
         MergerTokenFactoryProvider mergerTokenFactoryProvider = mock(MergerTokenFactoryProvider.class);
         when(mergerTokenFactoryProvider.get(any(DbAdapter.class))).thenReturn(new DefaultMergerTokenFactory());
 
-        return new DefaultDbImportAction(log, projectSaver, dataSourceFactory, adapterFactory,
mapLoader, mergerTokenFactoryProvider);
+        return new DefaultDbImportAction(log, projectSaver, dataSourceFactory, adapterFactory,
mapLoader, mergerTokenFactoryProvider) {
+            @Override
+            protected DbLoader createDbLoader(DbImportConfiguration config, DbAdapter adapter,
Connection connection) {
+                return dbLoader;
+            }
+        };
     }
 
     @Test


Mime
View raw message