cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject [3/6] cayenne git commit: [CAY-2128] Modeler stored procedures are not imported
Date Thu, 03 Nov 2016 17:53:33 GMT
[CAY-2128] Modeler stored procedures are not imported


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

Branch: refs/heads/master
Commit: 988835afe6c102bd87e96d5641fe9cc2ba863f83
Parents: ebeb86f
Author: Nikita Timofeev <stariy95@gmail.com>
Authored: Wed Nov 2 15:33:32 2016 +0300
Committer: Nikita Timofeev <stariy95@gmail.com>
Committed: Wed Nov 2 15:59:01 2016 +0300

----------------------------------------------------------------------
 .../cayenne/dbsync/reverse/db/DbLoader.java     |  6 ++--
 .../java/org/apache/cayenne/map/Procedure.java  |  7 +++++
 .../tools/dbimport/DefaultDbImportAction.java   | 31 ++++++++++++++++++++
 3 files changed, 41 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/988835af/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/db/DbLoader.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/db/DbLoader.java
b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/db/DbLoader.java
index 89f5f5e..9e447c6 100644
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/db/DbLoader.java
+++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/db/DbLoader.java
@@ -446,10 +446,10 @@ public class DbLoader {
 
         try (ResultSet columnsRS = getMetaData().getProcedureColumns(catalog, schema, null,
null);) {
             while (columnsRS.next()) {
-
-                String s = columnsRS.getString("PROCEDURE_SCHEM");
+                String procSchema = columnsRS.getString("PROCEDURE_SCHEM");
+                String procCatalog = columnsRS.getString("PROCEDURE_CAT");
                 String name = columnsRS.getString("PROCEDURE_NAME");
-                String key = (s == null ? "" : s + '.') + name;
+                String key = Procedure.generateFullyQualifiedName(procCatalog, procSchema,
name);
                 Procedure procedure = procedures.get(key);
                 if (procedure == null) {
                     continue;

http://git-wip-us.apache.org/repos/asf/cayenne/blob/988835af/cayenne-server/src/main/java/org/apache/cayenne/map/Procedure.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/map/Procedure.java b/cayenne-server/src/main/java/org/apache/cayenne/map/Procedure.java
index d411f58..a40a22e 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/map/Procedure.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/map/Procedure.java
@@ -124,6 +124,13 @@ public class Procedure implements ConfigurationNode, CayenneMapEntry,
XMLSeriali
      * Returns procedure name including schema and catalog, if present.
      */
     public String getFullyQualifiedName() {
+        return generateFullyQualifiedName(catalog, schema, name);
+    }
+
+    /**
+    * Utility function to generate fully qualified name for procedure
+    */
+    public static String generateFullyQualifiedName(String catalog, String schema, String
name) {
         return (catalog != null ? catalog + '.' : "")
                 + (schema != null ? schema + '.' : "")
                 + name;

http://git-wip-us.apache.org/repos/asf/cayenne/blob/988835af/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 df548c3..e417f2a 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
@@ -36,12 +36,15 @@ import org.apache.cayenne.dbsync.merge.factory.MergerTokenFactoryProvider;
 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.filters.FiltersConfig;
+import org.apache.cayenne.dbsync.reverse.filters.PatternFilter;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.map.MapLoader;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
+import org.apache.cayenne.map.Procedure;
 import org.apache.cayenne.project.Project;
 import org.apache.cayenne.project.ProjectSaver;
 import org.apache.cayenne.resource.URLResource;
@@ -162,6 +165,7 @@ public class DefaultDbImportAction implements DbImportAction {
                 config.getNameGenerator(),
                 config.getMeaningfulPKFilter(),
                 config.isUsePrimitives());
+        hasChanges |= syncProcedures(targetDataMap, loadedFomDb, loaderConfig.getFiltersConfig());
 
         if (hasChanges) {
             saveLoaded(targetDataMap);
@@ -295,6 +299,33 @@ public class DefaultDbImportAction implements DbImportAction {
         return true;
     }
 
+    private boolean syncProcedures(DataMap targetDataMap, DataMap loadedDataMap, FiltersConfig
filters) {
+        Collection<Procedure> procedures = loadedDataMap.getProcedures();
+        if (procedures.isEmpty()) {
+            return false;
+        }
+
+        boolean hasChanges = false;
+        for (Procedure procedure : procedures) {
+            PatternFilter proceduresFilter = filters.proceduresFilter(procedure.getCatalog(),
procedure.getSchema());
+            if (proceduresFilter == null || !proceduresFilter.isIncluded(procedure.getName()))
{
+                continue;
+            }
+
+            Procedure oldProcedure = targetDataMap.getProcedure(procedure.getName());
+            // maybe we need to compare oldProcedure's and procedure's fully qualified names?
+            if (oldProcedure != null) {
+                targetDataMap.removeProcedure(procedure.getName());
+                logger.info("Replace procedure " + procedure.getName());
+            } else {
+                logger.info("Add new procedure " + procedure.getName());
+            }
+            targetDataMap.addProcedure(procedure);
+            hasChanges = true;
+        }
+        return hasChanges;
+    }
+
     protected void saveLoaded(DataMap dataMap) throws FileNotFoundException {
         ConfigurationTree<DataMap> projectRoot = new ConfigurationTree<>(dataMap);
         Project project = new Project(projectRoot);


Mime
View raw message