cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abulat...@apache.org
Subject [cayenne] branch master updated: CAY-2535 Imposible to import stored proceedure apart from db tables
Date Wed, 06 Mar 2019 08:53:16 GMT
This is an automated email from the ASF dual-hosted git repository.

abulatski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git


The following commit(s) were added to refs/heads/master by this push:
     new 7024368  CAY-2535 Imposible to import stored proceedure apart from db tables
7024368 is described below

commit 7024368368e1a74be580fbdee8398563bd1a3505
Author: Arseni Bulatski <ancarseni@gmail.com>
AuthorDate: Tue Feb 12 15:17:38 2019 +0300

    CAY-2535 Imposible to import stored proceedure apart from db tables
---
 RELEASE-NOTES.txt                                  |  1 +
 .../reverse/dbimport/DefaultDbImportAction.java    | 42 +++++++++++-----------
 .../dialog/db/load/ModelerDbImportAction.java      | 40 +++++++++++++++++----
 .../cayenne/modeler/editor/DbImportController.java | 19 ++++++----
 4 files changed, 69 insertions(+), 33 deletions(-)

diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index 9855398..8f710ee 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -32,6 +32,7 @@ CAY-2509 Result of resolving lazily faulted relationships can be out-of-date
 CAY-2530 DB Import and Class Generation from Project is performed for removed datamaps
 CAY-2531 Importing same schema after Import Revert clears all entities in datamap
 CAY-2533 Modeler: Exception on validating ObjRelationship without db path
+CAY-2535 Imposible to import stored proceedure apart from db tables
 CAY-2544 Possible name clash of ivar and property name in generated class
 CAY-2547 CayenneDataObject serialization issue
 
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 d0884cc..7785234 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,6 +19,16 @@
 
 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;
@@ -30,17 +40,17 @@ import org.apache.cayenne.configuration.server.DataSourceFactory;
 import org.apache.cayenne.configuration.server.DbAdapterFactory;
 import org.apache.cayenne.configuration.xml.DataChannelMetaData;
 import org.apache.cayenne.dba.DbAdapter;
-import org.apache.cayenne.dbsync.merge.token.model.AbstractToModelToken;
 import org.apache.cayenne.dbsync.merge.DataMapMerger;
 import org.apache.cayenne.dbsync.merge.context.MergerContext;
-import org.apache.cayenne.dbsync.merge.token.MergerToken;
-import org.apache.cayenne.dbsync.reverse.dbload.ModelMergeDelegate;
-import org.apache.cayenne.dbsync.reverse.dbload.ProxyModelMergeDelegate;
 import org.apache.cayenne.dbsync.merge.factory.MergerTokenFactory;
 import org.apache.cayenne.dbsync.merge.factory.MergerTokenFactoryProvider;
+import org.apache.cayenne.dbsync.merge.token.MergerToken;
+import org.apache.cayenne.dbsync.merge.token.model.AbstractToModelToken;
 import org.apache.cayenne.dbsync.naming.ObjectNameGenerator;
 import org.apache.cayenne.dbsync.reverse.dbload.DbLoader;
 import org.apache.cayenne.dbsync.reverse.dbload.DbLoaderConfiguration;
+import org.apache.cayenne.dbsync.reverse.dbload.ModelMergeDelegate;
+import org.apache.cayenne.dbsync.reverse.dbload.ProxyModelMergeDelegate;
 import org.apache.cayenne.dbsync.reverse.filters.CatalogFilter;
 import org.apache.cayenne.dbsync.reverse.filters.FiltersConfig;
 import org.apache.cayenne.dbsync.reverse.filters.FiltersConfigBuilder;
@@ -60,16 +70,6 @@ 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;
 
 /**
@@ -272,19 +272,19 @@ public class DefaultDbImportAction implements DbImportAction {
             return false;
         }
 
-        if(!defaultPackage.equals(targetDataMap.getDefaultPackage())) {
-            return false;
-        }
+        return defaultPackage.equals(targetDataMap.getDefaultPackage());
+    }
 
-        return true;
+    protected boolean hasChangesForProcedure(Procedure procedure) {
+        PatternFilter proceduresFilter = filters.proceduresFilter(procedure.getCatalog(),
procedure.getSchema());
+        return proceduresFilter != null && proceduresFilter.isIncluded(procedure.getName());
     }
 
-    private boolean checkIncludedProcedures(DataMap loadedDataMap, FiltersConfig filters)
{
+    protected boolean checkIncludedProcedures(DataMap loadedDataMap, FiltersConfig filters)
{
         Collection<Procedure> procedures = loadedDataMap.getProcedures();
         boolean hasChanges = false;
         for (Procedure procedure : procedures) {
-            PatternFilter proceduresFilter = filters.proceduresFilter(procedure.getCatalog(),
procedure.getSchema());
-            if (proceduresFilter == null || !proceduresFilter.isIncluded(procedure.getName()))
{
+            if(!hasChangesForProcedure(procedure)) {
                 continue;
             }
             hasChanges = true;
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/load/ModelerDbImportAction.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/load/ModelerDbImportAction.java
index 476f4d0..0d10909 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/load/ModelerDbImportAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/load/ModelerDbImportAction.java
@@ -37,8 +37,10 @@ import org.apache.cayenne.dbsync.merge.factory.MergerTokenFactoryProvider;
 import org.apache.cayenne.dbsync.merge.token.MergerToken;
 import org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration;
 import org.apache.cayenne.dbsync.reverse.dbimport.DefaultDbImportAction;
+import org.apache.cayenne.dbsync.reverse.filters.FiltersConfig;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.map.Procedure;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.editor.DbImportController;
 import org.apache.cayenne.project.ProjectSaver;
@@ -55,7 +57,7 @@ public class ModelerDbImportAction extends DefaultDbImportAction {
     DbImportConfiguration config;
 
     private DbLoadResultDialog resultDialog;
-    private boolean isNothingChanged;
+    private boolean hasTokenToMerge;
 
     private DbImportController dbImportController;
 
@@ -108,10 +110,10 @@ public class ModelerDbImportAction extends DefaultDbImportAction {
         });
 
         logger.info("");
+
         if (tokens.isEmpty()) {
             logger.info("Detected changes: No changes to import.");
-            resultDialog.addMsg(targetMap);
-            isNothingChanged = true;
+            hasTokenToMerge = false;
             return tokens;
         }
 
@@ -120,7 +122,7 @@ public class ModelerDbImportAction extends DefaultDbImportAction {
             String logString = String.format("    %-20s %s", token.getTokenName(), token.getTokenValue());
             logger.info(logString);
             resultDialog.addRowToOutput(logString, targetMap);
-            isNothingChanged = false;
+            hasTokenToMerge = true;
         }
 
         logger.info("");
@@ -147,13 +149,13 @@ public class ModelerDbImportAction extends DefaultDbImportAction {
         String formattedMessage = String.format("    %-20s", message);
         messages.add(formattedMessage);
         resultDialog.addRowToOutput(formattedMessage, targetMap);
-        isNothingChanged = false;
+        hasTokenToMerge = true;
     }
 
     @Override
     protected void logMessages(List<String> messages) {
         super.logMessages(messages);
-        if (isNothingChanged) {
+        if (!hasTokenToMerge) {
             JOptionPane optionPane = new JOptionPane("Detected changes: No changes to import.",
JOptionPane.PLAIN_MESSAGE);
             JDialog dialog = optionPane.createDialog(DIALOG_TITLE);
             dialog.setModal(false);
@@ -168,4 +170,30 @@ public class ModelerDbImportAction extends DefaultDbImportAction {
     protected DataMap existingTargetMap(DbImportConfiguration configuration) throws IOException
{
         return targetMap;
     }
+
+    @Override
+    protected boolean checkIncludedProcedures(DataMap loadedDataMap, FiltersConfig filters)
{
+        Collection<Procedure> procedures = loadedDataMap.getProcedures();
+        boolean hasProceduresToMerge = false;
+        for (Procedure procedure : procedures) {
+            if(!hasChangesForProcedure(procedure)) {
+               continue;
+            }
+            hasProceduresToMerge = true;
+            Procedure oldProcedure = targetMap.getProcedure(procedure.getName());
+
+            String msg = "";
+            if (oldProcedure != null) {
+                msg = "Replace procedure " + procedure.getName();
+            } else {
+                msg = "Create procedure " + procedure.getName();
+            }
+            String formattedMessage = String.format("    %-20s", msg);
+            resultDialog.addRowToOutput(formattedMessage, targetMap);
+        }
+        if(!hasTokenToMerge && !hasProceduresToMerge) {
+            resultDialog.addMsg(targetMap);
+        }
+        return hasProceduresToMerge;
+    }
 }
\ No newline at end of file
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DbImportController.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DbImportController.java
index 201293e..ec97576 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DbImportController.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DbImportController.java
@@ -65,12 +65,7 @@ public class DbImportController {
     public void resetDialog() {
         ConcurrentMap<DataMap, JTable> tableMap = dbLoadResultDialog.getTableForMap();
         for(DataMap dataMap : tableMap.keySet()) {
-            JTable table = tableMap.get(dataMap);
-            DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
-            int rowCount = tableModel.getRowCount();
-            for (int i = rowCount - 1; i >= 0; i--) {
-                tableModel.removeRow(i);
-            }
+            clearTable(dataMap);
         }
 
         dbLoadResultDialog.getTableForMap().clear();
@@ -78,6 +73,18 @@ public class DbImportController {
         dbLoadResultDialog.getTablePanel().removeAll();
     }
 
+    public void clearTable(DataMap dataMap) {
+        JTable table = dbLoadResultDialog.getTableForMap().get(dataMap);
+        if(table == null) {
+            return;
+        }
+        DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
+        int rowCount = tableModel.getRowCount();
+        for (int i = rowCount - 1; i >= 0; i--) {
+            tableModel.removeRow(i);
+        }
+    }
+
     public void fireDataMapChangeEvent(DataMap dataMap) {
         Application.getInstance().getFrameController().getProjectController().fireDataMapEvent(new
DataMapEvent(this, dataMap));
     }


Mime
View raw message