Fixed some bugs
This commit is contained in:
parent
55ceb0bf34
commit
d6fc1390fd
2 changed files with 30 additions and 16 deletions
|
|
@ -14,7 +14,7 @@ public class HalCoreDatabaseUpgrade extends HalDatabaseUpgrade {
|
||||||
private static final Logger logger = LogUtil.getLogger();
|
private static final Logger logger = LogUtil.getLogger();
|
||||||
|
|
||||||
private static final int REFERENCE_DB_VERSION = 16;
|
private static final int REFERENCE_DB_VERSION = 16;
|
||||||
private static final String REFERENCE_DB_PATH = "resource/hal-core-reference.db";
|
private static final String REFERENCE_DB_PATH = HalContext.RESOURCE_ROOT + "/resource/hal-core-reference.db";
|
||||||
|
|
||||||
private static final int CLEAR_INTERNAL_AGGR_DATA_DB_VERSION = 11;
|
private static final int CLEAR_INTERNAL_AGGR_DATA_DB_VERSION = 11;
|
||||||
private static final int CLEAR_EXTERNAL_AGGR_DATA_DB_VERSION = 0;
|
private static final int CLEAR_EXTERNAL_AGGR_DATA_DB_VERSION = 0;
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import se.hal.struct.User;
|
||||||
import zutil.db.DBConnection;
|
import zutil.db.DBConnection;
|
||||||
import zutil.db.DBUpgradeHandler;
|
import zutil.db.DBUpgradeHandler;
|
||||||
import zutil.db.handler.PropertiesSQLResult;
|
import zutil.db.handler.PropertiesSQLResult;
|
||||||
|
import zutil.db.handler.SimpleSQLResult;
|
||||||
import zutil.io.file.FileUtil;
|
import zutil.io.file.FileUtil;
|
||||||
import zutil.log.LogUtil;
|
import zutil.log.LogUtil;
|
||||||
import zutil.plugin.PluginManager;
|
import zutil.plugin.PluginManager;
|
||||||
|
|
@ -23,6 +24,7 @@ import java.util.logging.Logger;
|
||||||
public class HalDatabaseUpgradeManager {
|
public class HalDatabaseUpgradeManager {
|
||||||
private static final Logger logger = LogUtil.getLogger();
|
private static final Logger logger = LogUtil.getLogger();
|
||||||
|
|
||||||
|
private static HalDatabaseUpgrade halCoreUpgrade;
|
||||||
private static Queue<HalDatabaseUpgrade> upgradeQueue;
|
private static Queue<HalDatabaseUpgrade> upgradeQueue;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -40,6 +42,10 @@ public class HalDatabaseUpgradeManager {
|
||||||
|
|
||||||
for (Iterator<HalDatabaseUpgrade> it = pluginManager.getSingletonIterator(HalDatabaseUpgrade.class); it.hasNext(); ) {
|
for (Iterator<HalDatabaseUpgrade> it = pluginManager.getSingletonIterator(HalDatabaseUpgrade.class); it.hasNext(); ) {
|
||||||
HalDatabaseUpgrade dbUpgrade = it.next();
|
HalDatabaseUpgrade dbUpgrade = it.next();
|
||||||
|
|
||||||
|
if (dbUpgrade instanceof HalCoreDatabaseUpgrade)
|
||||||
|
halCoreUpgrade = dbUpgrade;
|
||||||
|
else
|
||||||
upgradeQueue.add(dbUpgrade);
|
upgradeQueue.add(dbUpgrade);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -51,6 +57,12 @@ public class HalDatabaseUpgradeManager {
|
||||||
if (upgradeQueue == null)
|
if (upgradeQueue == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Prioritize upgrade of HalCore
|
||||||
|
if (halCoreUpgrade != null) {
|
||||||
|
upgrade(halCoreUpgrade);
|
||||||
|
halCoreUpgrade = null;
|
||||||
|
}
|
||||||
|
|
||||||
while (!upgradeQueue.isEmpty()) {
|
while (!upgradeQueue.isEmpty()) {
|
||||||
upgrade(upgradeQueue.poll());
|
upgrade(upgradeQueue.poll());
|
||||||
}
|
}
|
||||||
|
|
@ -69,14 +81,20 @@ public class HalDatabaseUpgradeManager {
|
||||||
// Init DB
|
// Init DB
|
||||||
File dbFile = FileUtil.find(HalContext.DB_FILE);
|
File dbFile = FileUtil.find(HalContext.DB_FILE);
|
||||||
mainDB = new DBConnection(DBConnection.DBMS.SQLite, HalContext.DB_FILE);
|
mainDB = new DBConnection(DBConnection.DBMS.SQLite, HalContext.DB_FILE);
|
||||||
Properties dbConf =
|
Properties dbConf = new Properties();
|
||||||
mainDB.exec("SELECT * FROM conf", new PropertiesSQLResult());
|
|
||||||
|
// Read in conf table from DB if it exists
|
||||||
|
|
||||||
|
String confTableExists = mainDB.exec("SELECT name FROM sqlite_master WHERE type='table' AND name='conf';", new SimpleSQLResult<>());
|
||||||
|
if ("conf".equals(confTableExists))
|
||||||
|
dbConf = mainDB.exec("SELECT * FROM conf", new PropertiesSQLResult());
|
||||||
|
|
||||||
if (dbFile == null) {
|
if (dbFile == null) {
|
||||||
logger.info("No database file found, creating new DB...");
|
logger.info("No database file found, creating new DB...");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upgrade DB needed?
|
// Evaluate if DB upgrade is needed?
|
||||||
|
|
||||||
referenceDB = new DBConnection(DBConnection.DBMS.SQLite, referenceDBPath);
|
referenceDB = new DBConnection(DBConnection.DBMS.SQLite, referenceDBPath);
|
||||||
String mainDBVersionProperty = dbUpgrade.getClass().getSimpleName() + ".db_version";
|
String mainDBVersionProperty = dbUpgrade.getClass().getSimpleName() + ".db_version";
|
||||||
|
|
||||||
|
|
@ -85,7 +103,7 @@ public class HalDatabaseUpgradeManager {
|
||||||
final int mainDBVersion = (dbConf.getProperty(mainDBVersionProperty) != null ?
|
final int mainDBVersion = (dbConf.getProperty(mainDBVersionProperty) != null ?
|
||||||
Integer.parseInt(dbConf.getProperty(mainDBVersionProperty)) :
|
Integer.parseInt(dbConf.getProperty(mainDBVersionProperty)) :
|
||||||
-1);
|
-1);
|
||||||
logger.info("DB version: " + mainDBVersion);
|
logger.info("DB version: " + mainDBVersion + "(" + dbUpgrade.getClass().getSimpleName() + ")");
|
||||||
|
|
||||||
if (referenceDBVersion > mainDBVersion) {
|
if (referenceDBVersion > mainDBVersion) {
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
|
@ -94,22 +112,18 @@ public class HalDatabaseUpgradeManager {
|
||||||
|
|
||||||
logger.info("Starting DB upgrade from v" + mainDBVersion + " to v" + referenceDBVersion + "...");
|
logger.info("Starting DB upgrade from v" + mainDBVersion + " to v" + referenceDBVersion + "...");
|
||||||
|
|
||||||
if (dbFile != null){
|
|
||||||
File backupDB = FileUtil.getNextFile(dbFile);
|
|
||||||
logger.fine("Backing up DB to: "+ backupDB);
|
|
||||||
FileUtil.copy(dbFile, backupDB);
|
|
||||||
}
|
|
||||||
|
|
||||||
final DBUpgradeHandler handler = new DBUpgradeHandler(referenceDB);
|
final DBUpgradeHandler handler = new DBUpgradeHandler(referenceDB);
|
||||||
|
handler.setForcedDBUpgrade(false);
|
||||||
handler.addIgnoredTable("sqlite_sequence"); // sqlite internal
|
handler.addIgnoredTable("sqlite_sequence"); // sqlite internal
|
||||||
handler.setTargetDB(mainDB);
|
handler.setTargetDB(mainDB);
|
||||||
|
|
||||||
logger.fine("Performing pre-upgrade activities");
|
logger.fine("Performing pre-upgrade activities");
|
||||||
|
|
||||||
/*if (doForceUpgrade) {
|
if (dbFile != null){
|
||||||
logger.fine("Forced upgrade enabled.");
|
File backupDB = FileUtil.getNextFile(dbFile);
|
||||||
handler.setForcedDBUpgrade(true); // set to true if any of the intermediate db version requires it.
|
logger.fine("Backing up DB to: "+ backupDB);
|
||||||
}*/
|
FileUtil.copy(dbFile, backupDB);
|
||||||
|
}
|
||||||
|
|
||||||
dbUpgrade.preDatabaseUpgrade(mainDB, mainDBVersion, referenceDBVersion);
|
dbUpgrade.preDatabaseUpgrade(mainDB, mainDBVersion, referenceDBVersion);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue