cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject [cayenne] branch STABLE-4.1 updated: CAY-2594 DbImport: AutoAdapter resolving inside an import operation hangs up the op on Hana DB
Date Sun, 07 Jul 2019 08:42:38 GMT
This is an automated email from the ASF dual-hosted git repository.

aadamchik pushed a commit to branch STABLE-4.1
in repository https://gitbox.apache.org/repos/asf/cayenne.git


The following commit(s) were added to refs/heads/STABLE-4.1 by this push:
     new 2f809e3  CAY-2594 DbImport: AutoAdapter resolving inside an import operation hangs
up the op on Hana DB
2f809e3 is described below

commit 2f809e33c9d6daaba4fbaaa29356342b7e00048f
Author: Andrus Adamchik <andrus@objectstyle.com>
AuthorDate: Sun Jul 7 11:17:41 2019 +0300

    CAY-2594 DbImport: AutoAdapter resolving inside an import operation hangs up the op on
Hana DB
---
 .../reverse/dbimport/DefaultDbImportAction.java    | 34 +++++++++++++++-------
 .../org/apache/cayenne/tools/DbImporterMojo.java   |  4 +++
 2 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/DefaultDbImportAction.java
b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/DefaultDbImportAction.java
index 7785234..1c50a25 100644
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/DefaultDbImportAction.java
+++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/DefaultDbImportAction.java
@@ -19,16 +19,6 @@
 
 package org.apache.cayenne.dbsync.reverse.dbimport;
 
-import javax.sql.DataSource;
-import java.io.File;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.sql.Connection;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.configuration.ConfigurationNode;
 import org.apache.cayenne.configuration.ConfigurationTree;
@@ -70,6 +60,16 @@ import org.apache.cayenne.validation.ValidationFailure;
 import org.apache.cayenne.validation.ValidationResult;
 import org.slf4j.Logger;
 
+import javax.sql.DataSource;
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.sql.Connection;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+
 import static org.apache.cayenne.util.Util.isBlank;
 
 /**
@@ -147,6 +147,17 @@ public class DefaultDbImportAction implements DbImportAction {
         commit(config, loadDataMap(config));
     }
 
+    protected DbAdapter createAdapter(DataNodeDescriptor dataNodeDescriptor, DataSource dataSource)
throws Exception {
+        DbAdapter adapter = adapterFactory.createAdapter(dataNodeDescriptor, dataSource);
+
+        // Warm up the AutoAdapter by calling any method. This to avoid AutoAdapter opening
a connection later in
+        // the middle of import to detect the DB type. Opening two connections in the same
thread causes issues with
+        // some DBs (namely com.sap.cloud.db.jdbc:ngdbc:2.4.56)
+        adapter.getPkGenerator();
+
+        return adapter;
+    }
+
     protected void commit(DbImportConfiguration config, DataMap sourceDataMap) throws Exception
{
         if (hasChanges) {
             DataMap targetDataMap = loadedDataMap;
@@ -162,6 +173,7 @@ public class DefaultDbImportAction implements DbImportAction {
     }
 
     protected DataMap loadDataMap(DbImportConfiguration config) throws Exception {
+
         if (logger.isDebugEnabled()) {
             logger.debug("DB connection: " + config.getDataSourceInfo());
             logger.debug(String.valueOf(config));
@@ -169,7 +181,7 @@ public class DefaultDbImportAction implements DbImportAction {
 
         DataNodeDescriptor dataNodeDescriptor = config.createDataNodeDescriptor();
         DataSource dataSource = dataSourceFactory.getDataSource(dataNodeDescriptor);
-        DbAdapter adapter = adapterFactory.createAdapter(dataNodeDescriptor, dataSource);
+        DbAdapter adapter = createAdapter(dataNodeDescriptor, dataSource);
 
         DataMap sourceDataMap;
         DataMap targetDataMap = existingTargetMap(config);
diff --git a/maven-plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java
b/maven-plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java
index 1c2d601..b34e77e 100644
--- a/maven-plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java
+++ b/maven-plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java
@@ -107,6 +107,10 @@ public class DbImporterMojo extends AbstractMojo {
 
         final DbImportConfigurationValidator validator = new DbImportConfigurationValidator(
                 dbImportConfig, config, injector);
+
+        // TODO: "validator.validate()" creates an AutoAdapter (which checks for DB type),
then  "DbImportAction.execute()"
+        //   does it again. We need to make AutoAdapter a DI singleton to avoid this extra
operation
+
         try {
             validator.validate();
         } catch (Exception ex) {


Mime
View raw message