Search in sources :

Example 46 with ReflectUtil

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);
}
Also used : ReflectUtil(org.eweb4j.util.ReflectUtil) Method(java.lang.reflect.Method)

Example 47 with ReflectUtil

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);
}
Also used : ReflectUtil(org.eweb4j.util.ReflectUtil) HashMap(java.util.HashMap) Method(java.lang.reflect.Method)

Example 48 with ReflectUtil

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;
}
Also used : ReflectUtil(org.eweb4j.util.ReflectUtil) Method(java.lang.reflect.Method)

Example 49 with ReflectUtil

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;
}
Also used : ReflectUtil(org.eweb4j.util.ReflectUtil) HashMap(java.util.HashMap) Method(java.lang.reflect.Method) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ReflectUtil (org.eweb4j.util.ReflectUtil)49 Method (java.lang.reflect.Method)37 Field (java.lang.reflect.Field)26 JoinColumn (javax.persistence.JoinColumn)14 ManyToOne (javax.persistence.ManyToOne)10 ArrayList (java.util.ArrayList)9 OneToOne (javax.persistence.OneToOne)9 DAOException (org.eweb4j.orm.dao.DAOException)9 JoinTable (javax.persistence.JoinTable)7 HashMap (java.util.HashMap)6 ManyToMany (javax.persistence.ManyToMany)6 OneToMany (javax.persistence.OneToMany)6 ORMConfigBean (org.eweb4j.orm.config.bean.ORMConfigBean)6 Property (org.eweb4j.orm.config.bean.Property)6 Entry (java.util.Map.Entry)5 File (java.io.File)4 List (java.util.List)4 Map (java.util.Map)4 ConfigBean (org.eweb4j.config.bean.ConfigBean)4 Hashtable (java.util.Hashtable)3