[OPENJPA-2808] indicies are dropped in schema tool
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 @@
                         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 @@
             }
         }
 
+        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);