Search in sources :

Example 1 with DBInfoXmlFiles

use of org.eweb4j.config.bean.DBInfoXmlFiles in project eweb4j-framework by laiweiwei.

the class DAOConfig method check.

public static synchronized String check() {
    String error = null;
    ConfigBean cb = (ConfigBean) SingleBeanCache.get(ConfigBean.class.getName());
    if (cb == null)
        return null;
    DBInfoXmlFiles dbInfoXmlFiles = cb.getOrm().getDbInfoXmlFiles();
    if (dbInfoXmlFiles == null)
        return ConfigInfoCons.CANNOT_READ_CONFIG_FILE;
    for (String filePath : dbInfoXmlFiles.getPath()) {
        if (filePath == null || filePath.length() == 0)
            continue;
        File configFile = new File(ConfigConstant.CONFIG_BASE_PATH + filePath);
        try {
            XMLReader reader = BeanXMLUtil.getBeanXMLReader(configFile);
            reader.setBeanName("dataSource");
            reader.setClass("dataSource", DBInfoConfigBean.class);
            DBInfoConfigBean dcb = reader.readOne();
            if (dcb == null) {
                error = rebuildXmlFile(configFile, ConfigInfoCons.REPAIR_FILE_INFO);
            } else {
                String error1 = CheckConfigBean.checkORMDBInfo(dcb, filePath);
                if (error1 == null) {
                    if (DBInfoConfigBeanCache.get(dcb.getDsName()) == null) {
                        DBInfoConfigBeanCache.add(dcb.getDsName(), dcb);
                    }
                    DataSourceWrap dsw = null;
                    if (DataSourceWrapCache.containsKey(dcb.getDsName())) {
                        dsw = (DataSourceWrap) DataSourceWrapCache.get(dcb.getDsName());
                        if (dsw == null) {
                            DataSourceWrapCache.remove(dcb.getDsName());
                            log.debug("remove dsName->" + dcb.getDsName());
                        } else
                            log.debug("DataSource -> " + dcb.getDsName() + " is alive !");
                    }
                    if (dsw == null)
                        dsw = new DataSourceWrap(dcb.getDsName(), DataSourceCreator.create(dcb));
                    String error2 = dsw.getConnection() == null ? ConfigInfoCons.CANNOT_GET_DB_CON : null;
                    if (error2 != null)
                        if (error == null)
                            error = error2;
                        else
                            error += error2;
                    else {
                        String info = dcb.getDsName() + "." + ConfigInfoCons.READ_CONFIG_INFO_SUCCESS;
                        log.debug(info);
                        // 此步也是为了共存多个数据源
                        if (!DataSourceWrapCache.containsKey(dcb.getDsName())) {
                            log.debug("init put ds to cache...");
                            DataSourceWrapCache.put(dcb.getDsName(), dsw);
                        }
                    }
                } else if (error == null)
                    error = error1;
                else
                    error += error1;
            }
        } catch (Throwable e) {
            e.printStackTrace();
            error = rebuildXmlFile(configFile, CommonUtil.getExceptionString(e));
        }
    }
    if (error != null)
        DBInfoConfigBeanCache.clear();
    return error;
}
Also used : DataSourceWrap(org.eweb4j.orm.jdbc.DataSourceWrap) DBInfoConfigBean(org.eweb4j.orm.dao.config.bean.DBInfoConfigBean) CheckConfigBean(org.eweb4j.config.CheckConfigBean) DBInfoConfigBean(org.eweb4j.orm.dao.config.bean.DBInfoConfigBean) ConfigBean(org.eweb4j.config.bean.ConfigBean) File(java.io.File) XMLReader(org.eweb4j.util.xml.XMLReader) DBInfoXmlFiles(org.eweb4j.config.bean.DBInfoXmlFiles)

Example 2 with DBInfoXmlFiles

use of org.eweb4j.config.bean.DBInfoXmlFiles in project eweb4j-framework by laiweiwei.

the class ConfigBeanCreator method create.

public static ConfigBean create() {
    ConfigBean cb = new ConfigBean();
    I18N i18n = new I18N();
    Locale locale = new Locale();
    locale.setLanguage(java.util.Locale.CHINA.getLanguage());
    locale.setCountry(java.util.Locale.CHINA.getCountry());
    i18n.getLocale().add(locale);
    cb.setLocales(i18n);
    Properties props = new Properties();
    Prop file = new Prop();
    props.getFile().add(file);
    cb.setProperties(props);
    LogsConfigBean lcb = new LogsConfigBean();
    ConfigIOC ioc = new ConfigIOC();
    IOCXmlFiles iocXmlFiles = new IOCXmlFiles();
    iocXmlFiles.setPath(new ArrayList<String>());
    ioc.setIocXmlFiles(iocXmlFiles);
    ioc.setLogs(lcb);
    cb.setIoc(ioc);
    ConfigORM orm = new ConfigORM();
    orm.setLogs(lcb);
    Ddl ddl = new Ddl();
    orm.setDdl(ddl);
    ORMXmlFiles ormXmlFiles = new ORMXmlFiles();
    orm.setOrmXmlFiles(ormXmlFiles);
    ScanPojoPackage spp = new ScanPojoPackage();
    orm.setScanPojoPackage(spp);
    DBInfoXmlFiles dbInfoXmlFiles = new DBInfoXmlFiles();
    dbInfoXmlFiles.setPath(new ArrayList<String>());
    orm.setDbInfoXmlFiles(dbInfoXmlFiles);
    cb.setOrm(orm);
    ConfigMVC mvc = new ConfigMVC();
    mvc.setLogs(lcb);
    UploadConfigBean upload = new UploadConfigBean();
    mvc.setUpload(upload);
    ActionXmlFile actionFiles = new ActionXmlFile();
    actionFiles.setPath(new ArrayList<String>());
    mvc.setActionXmlFiles(actionFiles);
    InterXmlFile intFiles = new InterXmlFile();
    intFiles.setPath(new ArrayList<String>());
    mvc.setInterXmlFiles(intFiles);
    ScanActionPackage sap = new ScanActionPackage();
    mvc.setScanActionPackage(sap);
    ScanInterceptorPackage sip = new ScanInterceptorPackage();
    mvc.setScanInterceptorPackage(sip);
    cb.setMvc(mvc);
    return cb;
}
Also used : Locale(org.eweb4j.config.bean.Locale) ActionXmlFile(org.eweb4j.config.bean.ActionXmlFile) Prop(org.eweb4j.config.bean.Prop) ConfigIOC(org.eweb4j.config.bean.ConfigIOC) ConfigMVC(org.eweb4j.config.bean.ConfigMVC) InterXmlFile(org.eweb4j.config.bean.InterXmlFile) UploadConfigBean(org.eweb4j.config.bean.UploadConfigBean) ConfigBean(org.eweb4j.config.bean.ConfigBean) LogsConfigBean(org.eweb4j.config.bean.LogsConfigBean) ScanInterceptorPackage(org.eweb4j.config.bean.ScanInterceptorPackage) Properties(org.eweb4j.config.bean.Properties) ScanPojoPackage(org.eweb4j.config.bean.ScanPojoPackage) Ddl(org.eweb4j.config.bean.Ddl) IOCXmlFiles(org.eweb4j.config.bean.IOCXmlFiles) ConfigORM(org.eweb4j.config.bean.ConfigORM) LogsConfigBean(org.eweb4j.config.bean.LogsConfigBean) ScanActionPackage(org.eweb4j.config.bean.ScanActionPackage) ORMXmlFiles(org.eweb4j.config.bean.ORMXmlFiles) I18N(org.eweb4j.config.bean.I18N) DBInfoXmlFiles(org.eweb4j.config.bean.DBInfoXmlFiles) UploadConfigBean(org.eweb4j.config.bean.UploadConfigBean)

Aggregations

ConfigBean (org.eweb4j.config.bean.ConfigBean)2 DBInfoXmlFiles (org.eweb4j.config.bean.DBInfoXmlFiles)2 File (java.io.File)1 CheckConfigBean (org.eweb4j.config.CheckConfigBean)1 ActionXmlFile (org.eweb4j.config.bean.ActionXmlFile)1 ConfigIOC (org.eweb4j.config.bean.ConfigIOC)1 ConfigMVC (org.eweb4j.config.bean.ConfigMVC)1 ConfigORM (org.eweb4j.config.bean.ConfigORM)1 Ddl (org.eweb4j.config.bean.Ddl)1 I18N (org.eweb4j.config.bean.I18N)1 IOCXmlFiles (org.eweb4j.config.bean.IOCXmlFiles)1 InterXmlFile (org.eweb4j.config.bean.InterXmlFile)1 Locale (org.eweb4j.config.bean.Locale)1 LogsConfigBean (org.eweb4j.config.bean.LogsConfigBean)1 ORMXmlFiles (org.eweb4j.config.bean.ORMXmlFiles)1 Prop (org.eweb4j.config.bean.Prop)1 Properties (org.eweb4j.config.bean.Properties)1 ScanActionPackage (org.eweb4j.config.bean.ScanActionPackage)1 ScanInterceptorPackage (org.eweb4j.config.bean.ScanInterceptorPackage)1 ScanPojoPackage (org.eweb4j.config.bean.ScanPojoPackage)1