use of org.eweb4j.orm.dao.config.bean.Property 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;
}
use of org.eweb4j.orm.dao.config.bean.Property in project eweb4j-framework by laiweiwei.
the class DataSourceCreator method create.
public static DataSource create(final DBInfoConfigBean dbInfo) throws Exception {
ConfigBean cb = (ConfigBean) SingleBeanCache.get(ConfigBean.class.getName());
Class<?> cls = Thread.currentThread().getContextClassLoader().loadClass(cb.getOrm().getDataSource());
DataSource ds = (DataSource) cls.newInstance();
List<Property> properties = dbInfo.getProperty();
// 通过反射将配置信息注入到数据源对象中
for (Property property : properties) {
String name = property.getKey();
String value = property.getValue();
if (null == name || name.trim().length() == 0)
continue;
if (null == value || value.trim().length() == 0)
continue;
ReflectUtil ru2 = new ReflectUtil(ds);
Method m2 = ru2.getSetter(name);
if (m2 == null)
continue;
Class<?> clazz = m2.getParameterTypes()[0];
if (int.class.isAssignableFrom(clazz) || Integer.class.isAssignableFrom(clazz) || long.class.isAssignableFrom(clazz) || Long.class.isAssignableFrom(clazz))
m2.invoke(ds, Integer.parseInt(value));
else if (float.class.isAssignableFrom(clazz) || Float.class.isAssignableFrom(clazz) || double.class.isAssignableFrom(clazz) || Double.class.isAssignableFrom(clazz))
m2.invoke(ds, Float.parseFloat(value));
else if (boolean.class.isAssignableFrom(clazz) || Boolean.class.isAssignableFrom(clazz))
m2.invoke(ds, Boolean.parseBoolean(value));
else
m2.invoke(ds, value);
}
return ds;
}
Aggregations