Search in sources :

Example 1 with DBInfoConfigBean

use of org.eweb4j.orm.dao.config.bean.DBInfoConfigBean 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 DBInfoConfigBean

use of org.eweb4j.orm.dao.config.bean.DBInfoConfigBean in project eweb4j-framework by laiweiwei.

the class DAOConfigBeanCreator method getDAOBean.

public static DBInfoConfigBean getDAOBean() {
    DBInfoConfigBean dcb = new DBInfoConfigBean();
    List<Property> properties = new ArrayList<Property>();
    Property p = new Property();
    p.setKey("");
    p.setValue("");
    properties.add(p);
    dcb.setProperty(properties);
    return dcb;
}
Also used : DBInfoConfigBean(org.eweb4j.orm.dao.config.bean.DBInfoConfigBean) ArrayList(java.util.ArrayList) Property(org.eweb4j.orm.dao.config.bean.Property)

Example 3 with DBInfoConfigBean

use of org.eweb4j.orm.dao.config.bean.DBInfoConfigBean in project eweb4j-framework by laiweiwei.

the class DAOFactory method getSearchDAO.

/**
	 * 创建SearchDAOImpl实例
	 * 
	 * @param dsName
	 *            数据库配置信息Bean的名字,默认下在eweb4j-dbInfo-config.xml文件中<name></name>
	 *            找到这个值
	 * @return
	 */
public static SearchDAO getSearchDAO(String dsName) {
    DataSource ds = DataSourceWrapCache.get(dsName);
    DBInfoConfigBean dcb = DBInfoConfigBeanCache.get(dsName);
    return new SearchDAOImpl(ds, dcb.getDataBaseType());
}
Also used : SearchDAOImpl(org.eweb4j.orm.dao.select.SearchDAOImpl) DBInfoConfigBean(org.eweb4j.orm.dao.config.bean.DBInfoConfigBean) DataSource(javax.sql.DataSource)

Example 4 with DBInfoConfigBean

use of org.eweb4j.orm.dao.config.bean.DBInfoConfigBean in project eweb4j-framework by laiweiwei.

the class DAOFactory method getSelectDAO.

/**
	 * 创建SelectDAOImpl实例
	 * 
	 * @param dsName
	 *            数据库配置信息Bean的名字,默认下在eweb4j-dbInfo-config.xml文件中<name></name>
	 *            找到这个值
	 * @return
	 */
public static SelectDAO getSelectDAO(String dsName) {
    DataSource ds = DataSourceWrapCache.get(dsName);
    DBInfoConfigBean dcb = DBInfoConfigBeanCache.get(dsName);
    return new SelectDAOImpl(ds, dcb.getDataBaseType());
}
Also used : SelectDAOImpl(org.eweb4j.orm.dao.select.SelectDAOImpl) DBInfoConfigBean(org.eweb4j.orm.dao.config.bean.DBInfoConfigBean) DataSource(javax.sql.DataSource)

Example 5 with DBInfoConfigBean

use of org.eweb4j.orm.dao.config.bean.DBInfoConfigBean in project eweb4j-framework by laiweiwei.

the class DAOFactory method getSearchDAO.

public static SearchDAO getSearchDAO() {
    DataSource ds = DataSourceWrapCache.get();
    DBInfoConfigBean dcb = DBInfoConfigBeanCache.get();
    return new SearchDAOImpl(ds, dcb.getDataBaseType());
}
Also used : SearchDAOImpl(org.eweb4j.orm.dao.select.SearchDAOImpl) DBInfoConfigBean(org.eweb4j.orm.dao.config.bean.DBInfoConfigBean) DataSource(javax.sql.DataSource)

Aggregations

DBInfoConfigBean (org.eweb4j.orm.dao.config.bean.DBInfoConfigBean)13 DataSource (javax.sql.DataSource)9 ConfigBean (org.eweb4j.config.bean.ConfigBean)4 File (java.io.File)2 Property (org.eweb4j.orm.dao.config.bean.Property)2 InsertDAOImpl (org.eweb4j.orm.dao.insert.InsertDAOImpl)2 DivPageDAOImpl (org.eweb4j.orm.dao.select.DivPageDAOImpl)2 SearchDAOImpl (org.eweb4j.orm.dao.select.SearchDAOImpl)2 SelectDAOImpl (org.eweb4j.orm.dao.select.SelectDAOImpl)2 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 CheckConfigBean (org.eweb4j.config.CheckConfigBean)1 DBInfoXmlFiles (org.eweb4j.config.bean.DBInfoXmlFiles)1 ListenerBean (org.eweb4j.config.bean.ListenerBean)1 Listeners (org.eweb4j.config.bean.Listeners)1 LogConfigBean (org.eweb4j.config.bean.LogConfigBean)1