@@ -64,7 +64,7 @@ public void close() {
6464 @ Override
6565 public void tables (Class <?>... classes ) {
6666 HashMap <String , HashMap <String , String >> tablesMap = new HashMap <>();
67- HashMap <String , Boolean > indexMap = new HashMap <>();
67+ HashMap <String , String > indexMap = new HashMap <>();
6868 String s = SQLTemplate .query ("sqlite_master" , new Options ().where ("type = ?" , "table" ));
6969 try (Statement statement = connection .createStatement (); ResultSet result = statement .executeQuery (s )) {
7070 DatabaseMetaData metaData = connection .getMetaData ();
@@ -83,9 +83,7 @@ public void tables(Class<?>... classes) {
8383 while (set .next ()) {
8484 String index = set .getString ("INDEX_NAME" );
8585 String column = set .getString ("COLUMN_NAME" );
86- if (index != null ) {
87- indexMap .put (column , true );
88- }
86+ Optional .ofNullable (index ).ifPresent (i -> indexMap .put (index , column ));
8987 }
9088 }
9189 }
@@ -106,25 +104,25 @@ public void tables(Class<?>... classes) {
106104 }
107105 });
108106 }
109- reflect .getIndexList (column -> {
107+ reflect .getIndexList (( index , column ) -> {
110108 try {
111- if (indexMap .getOrDefault ( column , false ) ) {
112- indexMap .remove (column , true );
109+ if (indexMap .get ( index ) != null ) {
110+ indexMap .remove (index , column );
113111 } else {
114112 statement .executeUpdate (SQLTemplate .createIndex (tClass , column ));
115113 }
116114 } catch (SQLException e ) {
117115 throw new RuntimeException (e );
118116 }
119117 });
120- indexMap .keySet ().forEach (column -> {
121- try {
122- statement .executeUpdate (SQLTemplate .dropIndex (tClass , column ));
123- } catch (SQLException e ) {
124- throw new RuntimeException (e );
125- }
126- });
127118 }
119+ indexMap .forEach ((index , column ) -> {
120+ try {
121+ statement .executeUpdate (SQLTemplate .dropIndex (index ));
122+ } catch (SQLException e ) {
123+ throw new RuntimeException (e );
124+ }
125+ });
128126 } catch (Exception e ) {
129127 throw new RuntimeException (e );
130128 }
0 commit comments