Package org.eweb4j.util

Examples of org.eweb4j.util.ReflectUtil


      final String _sql = String.format(create_table_script, table, table, sb.toString());
      sql.append(_sql);
     
      Class<?> clazz = (Class<?>) e.getKey();
      try {
        ReflectUtil ru = new ReflectUtil(clazz);
        for (Field f : ru.getFields()){
          if (!ClassUtil.isListClass(f))
            continue;
         
          String name = f.getName();
          Method getter = ru.getGetter(name);
          if (getter == null)
            continue;
         
          ManyToMany mmAnn = getter.getAnnotation(ManyToMany.class);
         
View Full Code Here


      idValue = map.get("idValue");
    } else {
      idField = ORMConfigBeanUtil.getIdField(clazz);
      table = ORMConfigBeanUtil.getTable(clazz);
      idColumn = ORMConfigBeanUtil.getIdColumn(clazz);
      ReflectUtil ru = new ReflectUtil(t);
      Method method = ru.getGetter(idField);
      if (method == null) {
        throw new SqlCreateException("can not find id getter.");
      }

      try {
View Full Code Here

  private String makeSQL(T t, String... fields) throws SqlCreateException {
    Class<?> clazz = t.getClass();
    String table = ORMConfigBeanUtil.getTable(clazz);
    StringBuilder condition = new StringBuilder();
    ReflectUtil ru = new ReflectUtil(t);

    for (int i = 0; i < fields.length; i++) {
      if (condition.length() > 0)
        condition.append(" AND ");

      Method getter = ru.getGetter(fields[i]);
      if (getter == null)
        continue;

      String column = ORMConfigBeanUtil.getColumn(clazz, fields[i]);
      condition.append(column + " = ");

      Object _value = null;
      Object value = null;
      try {
        _value = getter.invoke(t);
        if (_value == null)
          continue;

        if (ClassUtil.isPojo(_value.getClass())) {
          Field f = ru.getField(fields[i]);
          OneToOne oneAnn = getter.getAnnotation(OneToOne.class);
          if (oneAnn == null)
            oneAnn = f.getAnnotation(OneToOne.class);
         
          ManyToOne manyToOneAnn = null;
          if (oneAnn == null){
            manyToOneAnn = getter.getAnnotation(ManyToOne.class);
            if (manyToOneAnn == null)
              manyToOneAnn = f.getAnnotation(ManyToOne.class);
           
          }
         
          if (oneAnn != null || manyToOneAnn != null) {
            ReflectUtil tarRu = new ReflectUtil(_value);
            String tarFKField = ORMConfigBeanUtil.getIdField(_value.getClass());

            Method tarFKGetter = tarRu.getGetter(tarFKField);
            value = tarFKGetter.invoke(_value);
          }
        }

        if (value == null)
View Full Code Here

              : table;
          ORMConfigBean ormBean = new ORMConfigBean();
          ormBean.setClazz(clazz.getName());
          ormBean.setId(clazz.getSimpleName());
          ormBean.setTable(table);
          ReflectUtil ru;

          ru = new ReflectUtil(clazz);
          List<Property> pList = new ArrayList<Property>();
          for (Field f : ru.getFields()) {
            String name = f.getName();
            Method getter = ru.getGetter(name);
            Column colAnn = getter.getAnnotation(Column.class);
            if (colAnn == null) {
              colAnn = f.getAnnotation(Column.class);
              if (colAnn == null)
                continue;
View Full Code Here

    // 通过反射将配置信息注入到数据源对象中
    for (Property property : properties) {
      String name = property.getKey();
      String value = property.getValue();
      ReflectUtil ru2 = new ReflectUtil(ds);
      Method m2 = ru2.getSetter(name);
      if (m2 == null)
        continue;

      Class<?> clazz = m2.getParameterTypes()[0];
      if (int.class.isAssignableFrom(clazz)
View Full Code Here

   * @param clsName
   * @throws Exception
   */
  public static void handlePojoClass(String clsName) {
    Class<?> clazz = null;
    ReflectUtil ru;
    try {
      clazz = Class.forName(clsName);
    } catch (Error e) {
      return;
    } catch (Exception e) {
      return;
    }

    if (clazz == null)
      return;

    Entity entity = clazz.getAnnotation(Entity.class);
    if (entity == null && !clsName.endsWith("PO")
        && !clsName.endsWith("POJO") && !clsName.endsWith("Entity")
        && !clsName.endsWith("Model")) {
      return;
    }
    Table tableAnn = clazz.getAnnotation(Table.class);
    String table = tableAnn == null ? "" : tableAnn.name();
    table = "".equals(table.trim()) ? clazz.getSimpleName()
        .replace("PO", "").replace("POJO", "").replace("Entity", "")
        .replace("Model", "") : table;
    ORMConfigBean ormBean = new ORMConfigBean();
    ormBean.setClazz(clazz.getName());
    ormBean.setId(clazz.getSimpleName());
    ormBean.setTable(table);
    try {
      ru = new ReflectUtil(clazz);
    } catch (Error e) {
      return;
    } catch (Exception e) {
      return;
    }

    List<Property> pList = new ArrayList<Property>();
    for (Field f : ru.getFields()) {
      String name = f.getName();
      Method getter = ru.getGetter(name);
      if (getter == null)
        continue;

      Ignore igAnn = f.getAnnotation(Ignore.class);
      if (igAnn != null)
View Full Code Here

public class ORMConfigBeanUtil {

  public static <T> Object getIdVal(T _t) throws IllegalArgumentException,
      IllegalAccessException, InvocationTargetException {
    String _idField = ORMConfigBeanUtil.getIdField(_t.getClass());
    ReflectUtil _ru = new ReflectUtil(_t);
    Method _idGetter = _ru.getGetter(_idField);
    return _idGetter.invoke(_t);
  }
View Full Code Here

      return null;
    }

    List<String> result = new ArrayList<String>();

    ReflectUtil ru;
    try {
      ru = new ReflectUtil(clazz);
      Field[] fields = ru.getFields();
      for (Field f : fields) {

        Method getter = ru.getGetter(f.getName());
        if (getter == null)
          continue;

        OneToOne oneAnn = getter.getAnnotation(OneToOne.class);
        if (oneAnn == null) {
View Full Code Here

  }

  public static <T> String[] getValues(T _t) throws Exception {
    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);
    }
View Full Code Here

    return values;
  }

  public static <T> Object getValue(T _t, String field) throws Exception {
    String value = null;
    ReflectUtil _ru = new ReflectUtil(_t);
    Method getter = _ru.getGetter(field);
    Object val = getter.invoke(_t);
    if (val == null)
      return null;

    value = String.valueOf(val);
View Full Code Here

TOP

Related Classes of org.eweb4j.util.ReflectUtil

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.