Search in sources :

Example 1 with UpgradeDatabase

use of com.rebuild.core.support.setup.UpgradeDatabase in project rebuild by getrebuild.

the class Application method init.

/**
 * 系统初始化
 *
 * @throws Exception
 */
public static boolean init() throws Exception {
    if (_READY)
        throw new IllegalStateException("REBUILD ALREADY STARTED");
    log.info("Initializing Rebuild context [ {} ] ...", _CONTEXT.getClass().getSimpleName());
    if (!(_READY = ServerStatus.checkAll())) {
        log.error(RebuildBanner.formatBanner("REBUILD STARTUP FILAED DURING THE STATUS CHECK.", "PLEASE VIEW LOGS FOR MORE DETAILS."));
        return false;
    }
    // 升级数据库
    new UpgradeDatabase().upgradeQuietly();
    // 版本升级会清除缓存
    int lastBuild = ObjectUtils.toInt(RebuildConfiguration.get(ConfigurationItem.AppBuild, true), 0);
    if (lastBuild < BUILD) {
        log.warn("Clean up the cache once when upgrading : {}", BUILD);
        Installer.clearAllCache();
        RebuildConfiguration.set(ConfigurationItem.AppBuild, BUILD);
    }
    // 刷新配置缓存
    for (ConfigurationItem item : ConfigurationItem.values()) {
        RebuildConfiguration.get(item, true);
    }
    // 加载自定义实体
    log.info("Loading customized/business entities ...");
    ((DynamicMetadataFactory) _CONTEXT.getBean(PersistManagerFactory.class).getMetadataFactory()).refresh();
    // 实体对应的服务类
    _ESS = new HashMap<>();
    for (Map.Entry<String, ServiceSpec> e : _CONTEXT.getBeansOfType(ServiceSpec.class).entrySet()) {
        ServiceSpec s = e.getValue();
        if (s.getEntityCode() > 0) {
            _ESS.put(s.getEntityCode(), s);
            if (devMode()) {
                log.info("Service specification : {} for [ {} ]", s.getClass().getName(), s.getEntityCode());
            }
        }
    }
    // 初始化业务组件
    List<Initialization> ordered = new ArrayList<>(_CONTEXT.getBeansOfType(Initialization.class).values());
    OrderComparator.sort(ordered);
    for (Initialization bean : ordered) {
        bean.init();
    }
    License.isRbvAttached();
    DataMigrator.dataMigrateIfNeed();
    return true;
}
Also used : ConfigurationItem(com.rebuild.core.support.ConfigurationItem) UpgradeDatabase(com.rebuild.core.support.setup.UpgradeDatabase) ServiceSpec(com.rebuild.core.service.ServiceSpec) DynamicMetadataFactory(com.rebuild.core.metadata.impl.DynamicMetadataFactory)

Aggregations

DynamicMetadataFactory (com.rebuild.core.metadata.impl.DynamicMetadataFactory)1 ServiceSpec (com.rebuild.core.service.ServiceSpec)1 ConfigurationItem (com.rebuild.core.support.ConfigurationItem)1 UpgradeDatabase (com.rebuild.core.support.setup.UpgradeDatabase)1