Search in sources :

Example 1 with DbUpdater

use of com.haulmont.cuba.core.sys.DbUpdater in project cuba by cuba-platform.

the class DbUpdateManager method checkDatabase.

protected void checkDatabase(String storeName) {
    DbUpdater dbUpdater = AppBeans.getPrototype(DbUpdater.NAME, storeName);
    try {
        boolean initialized = false;
        try {
            initialized = dbUpdater.dbInitialized();
        } catch (DbInitializationException e) {
            if (!Stores.isMain(storeName)) {
                return;
            }
        }
        if (!initialized) {
            throw new IllegalStateException(StringHelper.wrapLogMessage("ERROR: Data store " + (Stores.isMain(storeName) ? "" : "[" + storeNameToString(storeName) + "]") + "is not initialized. " + getLogString(storeName)));
        }
        List<String> scripts = dbUpdater.findUpdateDatabaseScripts();
        if (!scripts.isEmpty()) {
            log.warn(StringHelper.wrapLogMessage("WARNING: The application contains unapplied update scripts for data store" + (Stores.isMain(storeName) ? "" : " [" + storeNameToString(storeName) + "]") + ":\n\n" + Joiner.on('\n').join(scripts) + "\n\n" + getLogString(storeName)));
        }
    } catch (DbInitializationException e) {
        throw new RuntimeException(StringHelper.wrapLogMessage("ERROR: Cannot check data store [" + storeNameToString(storeName) + "]. See the stacktrace below for details."), e);
    }
}
Also used : DbInitializationException(com.haulmont.cuba.core.sys.DbInitializationException) DbUpdater(com.haulmont.cuba.core.sys.DbUpdater) Stores.storeNameToString(com.haulmont.cuba.core.global.Stores.storeNameToString)

Aggregations

Stores.storeNameToString (com.haulmont.cuba.core.global.Stores.storeNameToString)1 DbInitializationException (com.haulmont.cuba.core.sys.DbInitializationException)1 DbUpdater (com.haulmont.cuba.core.sys.DbUpdater)1