diff --git a/Zutil.jar b/Zutil.jar index 4525eff..10177f4 100755 Binary files a/Zutil.jar and b/Zutil.jar differ diff --git a/src/zutil/db/DBUpgradeHandler.java b/src/zutil/db/DBUpgradeHandler.java index 505e350..05b60a7 100755 --- a/src/zutil/db/DBUpgradeHandler.java +++ b/src/zutil/db/DBUpgradeHandler.java @@ -11,6 +11,7 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -29,10 +30,12 @@ public class DBUpgradeHandler { private DBConnection target; private boolean forceUpgradeEnabled = false; private HashMap tableRenameMap; + private HashSet ignoredTablesSet; public DBUpgradeHandler(DBConnection reference){ this.tableRenameMap = new HashMap<>(); + this.ignoredTablesSet = new HashSet<>(); this.reference = reference; } @@ -50,6 +53,13 @@ public class DBUpgradeHandler { this.tableRenameMap.put(oldTableName, newTableName); } + /** + * @param table a table name that will be ignored from the upgrade procedure + */ + public void addIgnoredTable(String table){ + ignoredTablesSet.add(table); + } + /** * With the default behaviour unnecessary columns will not be removed. * But if forced upgrade is set to true then the upgrade handler will @@ -61,6 +71,7 @@ public class DBUpgradeHandler { this.forceUpgradeEnabled = enable; } + public void upgrade() throws SQLException { try { logger.fine("Starting upgrade transaction..."); @@ -204,8 +215,18 @@ public class DBUpgradeHandler { } - private static List getTableList(DBConnection db) throws SQLException { - return db.exec("SELECT name FROM sqlite_master WHERE type='table';", new ListSQLResult()); + private List getTableList(DBConnection db) throws SQLException { + return db.exec("SELECT name FROM sqlite_master WHERE type='table';", new SQLResultHandler>() { + public List handleQueryResult(Statement stmt, ResultSet result) throws SQLException { + ArrayList list = new ArrayList(); + while( result.next() ) { + String table = result.getString(1); + if(!ignoredTablesSet.contains(table)) + list.add(result.getString(1)); + } + return list; + } + }); } private static String getTableSql(DBConnection db, String table) throws SQLException { PreparedStatement stmt = db.getPreparedStatement("SELECT sql FROM sqlite_master WHERE name == ?");