Search in sources :

Example 1 with JQDatabase

use of org.h2.jaqu.Table.JQDatabase in project h2database by h2database.

the class Db method upgradeDb.

Db upgradeDb() {
    if (!upgradeChecked.contains(dbUpgrader.getClass())) {
        // flag as checked immediately because calls are nested.
        upgradeChecked.add(dbUpgrader.getClass());
        JQDatabase model = dbUpgrader.getClass().getAnnotation(JQDatabase.class);
        if (model.version() > 0) {
            DbVersion v = new DbVersion();
            DbVersion dbVersion = // (SCHEMA="" && TABLE="") == DATABASE
            from(v).where(v.schema).is("").and(v.table).is("").selectFirst();
            if (dbVersion == null) {
                // database has no version registration, but model specifies
                // version: insert DbVersion entry and return.
                DbVersion newDb = new DbVersion(model.version());
                insert(newDb);
            } else {
                // check to see if upgrade is required.
                if ((model.version() > dbVersion.version) && (dbUpgrader != null)) {
                    // database is an older version than the model
                    boolean success = dbUpgrader.upgradeDatabase(this, dbVersion.version, model.version());
                    if (success) {
                        dbVersion.version = model.version();
                        update(dbVersion);
                    }
                }
            }
        }
    }
    return this;
}
Also used : JQDatabase(org.h2.jaqu.Table.JQDatabase)

Aggregations

JQDatabase (org.h2.jaqu.Table.JQDatabase)1