use of org.eweb4j.util.ReflectUtil in project eweb4j-framework by laiweiwei.
the class ModelHelper method load.
/**
* 根据当前实体ID值去查询数据库
*/
public void load() {
Long id = _getId();
if (id == null || id <= 0)
return;
ReflectUtil ru = new ReflectUtil(this.model);
T _model = DAOFactory.getSelectDAO(this.dsName).selectOneById(this.model);
if (_model == null)
return;
ReflectUtil _ru = new ReflectUtil(_model);
for (String field : ru.getFieldsName()) {
Method setter = ru.getSetter(field);
if (setter == null)
continue;
Method _getter = _ru.getGetter(field);
if (_getter == null)
continue;
try {
setter.invoke(this.model, _getter.invoke(_model));
} catch (Exception e) {
continue;
}
}
// ToOne relation class cascade select
final String[] fields = ORMConfigBeanUtil.getToOneField(this.model.getClass());
if (fields != null && fields.length > 0)
DAOFactory.getCascadeDAO(this.dsName).select(this.model, fields);
}
use of org.eweb4j.util.ReflectUtil in project eweb4j-framework by laiweiwei.
the class ORMConfigBeanUtil method getIdVal.
public static <T> Object getIdVal(T _t) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
Class<?> clazz = _t.getClass();
if (Map.class.isAssignableFrom(clazz)) {
HashMap<String, Object> map = (HashMap<String, Object>) _t;
return map.get("idValue");
}
String _idField = ORMConfigBeanUtil.getIdField(_t.getClass());
if (_idField == null)
return null;
ReflectUtil _ru = new ReflectUtil(_t);
Method _idGetter = _ru.getGetter(_idField);
return _idGetter.invoke(_t);
}
use of org.eweb4j.util.ReflectUtil in project eweb4j-framework by laiweiwei.
the class ORMConfigBeanUtil method getValue.
public static <T> Object getValue(T _t, String field) throws Exception {
ReflectUtil _ru = new ReflectUtil(_t);
Method getter = _ru.getGetter(field);
Object val = getter.invoke(_t);
if (val == null)
return null;
Object value = String.valueOf(val);
return value;
}
use of org.eweb4j.util.ReflectUtil in project eweb4j-framework by laiweiwei.
the class ORMConfigBeanUtil method getValues.
public static <T> String[] getValues(T t) throws Exception {
if (!(t instanceof Class) && Map.class.isAssignableFrom(t.getClass())) {
HashMap<String, Object> map = (HashMap<String, Object>) t;
return (String[]) map.get("values");
}
String[] fields = ORMConfigBeanUtil.getFields(t.getClass());
String[] values = new String[fields.length];
ReflectUtil _ru = new ReflectUtil(t);
for (int i = 0; i < fields.length; i++) {
Method getter = _ru.getGetter(fields[i]);
Object val = getter.invoke(t);
if (val == null)
continue;
values[i] = String.valueOf(val);
}
return values;
}
Aggregations