You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by so...@apache.org on 2020/04/05 09:59:04 UTC

[openjpa] 01/01: [OPENJPA-2808] indicies are dropped in schema tool

This is an automated email from the ASF dual-hosted git repository.

solomax pushed a commit to branch OPENJPA-2808-index-drop
in repository https://gitbox.apache.org/repos/asf/openjpa.git

commit 20f682eb7e75fec97d41ed31b14de30322e67841
Author: Maxim Solodovnik <so...@gmail.com>
AuthorDate: Sun Apr 5 16:58:42 2020 +0700

    [OPENJPA-2808] indicies are dropped in schema tool
---
 .../org/apache/openjpa/jdbc/schema/SchemaTool.java | 59 ++++++++++++++++++----
 1 file changed, 50 insertions(+), 9 deletions(-)

diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java
index a3c22be..3a1b4f2 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java
@@ -971,21 +971,21 @@ public class SchemaTool {
                         continue;
                     fks = tabs[j].getForeignKeys();
                     dbTable = db.findTable(tabs[j]);
+                    if (dbTable == null) {
+                        continue;
+                    }
                     for (int k = 0; k < fks.length; k++) {
                         if (fks[k].isLogical())
                             continue;
 
-                        fk = null;
-                        if (dbTable != null)
-                            fk = findForeignKey(dbTable, fks[k]);
-                        if (dbTable == null || fk == null)
+                        fk = findForeignKey(dbTable, fks[k]);
+                        if (fk == null) {
                             continue;
+                        }
 
-                        if (dropForeignKey(fks[k]))
-                            if (dbTable != null)
-                                dbTable.removeForeignKey(fk);
-                            else
-                                _log.warn(_loc.get("drop-fk", fks[k], tabs[j]));
+                        if (dropForeignKey(fks[k])) {
+                            dbTable.removeForeignKey(fk);
+                        }
                     }
                 }
             }
@@ -1008,6 +1008,47 @@ public class SchemaTool {
             }
         }
 
+        if (_indexes) {
+            Index idx;
+            for (int i = 0; i < schemas.length; ++i) {
+                tabs = schemas[i].getTables();
+                for (Table tab : schemas[i].getTables()) {
+                    if (!isDroppable(tab)) {
+                        continue;
+                    }
+                    dbTable = db.findTable(tab);
+                    if (dbTable == null) {
+                        continue;
+                    }
+                    for (Index index : tab.getIndexes()) {
+                        idx = findIndex(dbTable, index);
+                        if (idx == null) {
+                            continue;
+                        }
+                        if (dropIndex(index)) {
+                            dbTable.removeIndex(idx);
+                        }
+                    }
+                }
+            }
+
+            // also drop imported indicies for tables that will be dropped
+            for (Table tab: drops) {
+                dbTable = db.findTable(tab);
+                if (dbTable == null) {
+                    continue;
+                }
+                for (Index index : tab.getIndexes()) {
+                    idx = findIndex(dbTable, index);
+                    if (dropIndex(index)) {
+                        dbTable.removeIndex(idx);
+                    } else {
+                        _log.warn(_loc.get("drop-index", index, dbTable));
+                    }
+                }
+            }
+        }
+
         // drop the tables we calculated above
         dropTables(drops, db);