Package org.eweb4j.util

Examples of org.eweb4j.util.ReflectUtil


    if (Map.class.isAssignableFrom(parentPojo.getClass())) {
      return parentPojo;
    }

    ReflectUtil _ru = new ReflectUtil(parentPojo);

    Method pojoSetter = _ru.getSetter(pojoParamName);
    if (pojoSetter == null)
      return parentPojo;

    Class<?> pojoClass = pojoSetter.getParameterTypes()[0];
View Full Code Here


            map.put(_paramName, paramValue);

          lastPojo = map;
        }

        ReflectUtil lpRu = new ReflectUtil(lastPojo);

        setter = lpRu.getSetter(_paramName);
        if (setter == null)
          continue;

        invokeSetter(lastPojo, paramValue, setter);
View Full Code Here

            map.put(_paramName, paramValue);
 
          lastPojo = map;
        }
 
        ReflectUtil lpRu = new ReflectUtil(lastPojo);
 
        setter = lpRu.getSetter(_paramName);
        if (setter == null)
          continue;
       
        Class<?> clazz = setter.getParameterTypes()[0];
        if (File.class.isAssignableFrom(clazz)){
View Full Code Here

  }

  public void init(Object t, List<Field> fields) throws DAOException {
    this.t = t;
    this.fields = fields;
    this.ru = new ReflectUtil(this.t);
    // 主类的ID属性名
    this.idField = ORMConfigBeanUtil.getIdField(this.t.getClass());
    this.idSetter = ru.getSetter(idField);
    if (this.idSetter == null)
      throw new DAOException("can not get idSetter.", null);
View Full Code Here

      for (int i = 0; i < tarList.size(); i++) {
        Object tarObj = tarList.get(i);
        String from = froms[0].name();
        String to = tos[0].name();

        ReflectUtil tarRu = new ReflectUtil(tarObj);
        Method tarIdGetter = tarRu.getGetter(tarIdField);
        Object _tarIdVal = null;

        try {
          _tarIdVal = tarIdGetter.invoke(tarObj);
        } catch (Exception e) {
          throw new DAOException(tarIdGetter + " invoke exception ",
              e);
        }

        if (_tarIdVal == null)
          continue;

        String tarIdVal = String.valueOf(_tarIdVal);
        Object tempObj = DAOFactory.getSelectDAO(dsName).selectOne(
            tarClass, new String[] { tarIdField },
            new String[] { tarIdVal });

        if (tempObj == null) {
          // 如果目标对象不存在于数据库,则将目标对象插入到数据库
          Object tarIdValObj = DAOFactory.getInsertDAO(dsName)
              .insert(tarObj);
          // 将获取到的id值注入到tarObj中
          Method tarIdSetter = tarRu.getSetter(tarIdField);
          try {
            tarIdSetter.invoke(tarObj, tarIdValObj);
          } catch (Exception e) {
            throw new DAOException(tarIdSetter
                + " invoke exception ", e);
View Full Code Here

        String _format = "delete from %s where %s = ? and %s = ?";
        for (int i = 0; i < tarList.size(); i++) {
          Object tarObj = tarList.get(i);
          if (tarObj == null)
            continue;
          ReflectUtil tarRu = new ReflectUtil(tarObj);
          String tarIdField = ORMConfigBeanUtil.getIdField(tarClass);
          Method tarIdGetter = tarRu.getGetter(tarIdField);
          Object toValObj = null;

          try {
            toValObj = tarIdGetter.invoke(tarObj);
          } catch (Exception e) {
View Full Code Here

        tarList = (List<?>) tarGetter.invoke(t);

        if (tarList != null && tarList.size() > 0) {
          for (int i = 0; i < tarList.size(); i++) {
            Object tarObj = tarList.get(i);
            ReflectUtil tarRu = new ReflectUtil(tarObj);
            String tarIdField = ORMConfigBeanUtil
                .getIdField(tarClass);
            Method tarIdGetter = tarRu.getGetter(tarIdField);
            Object tarIdValObj = tarIdGetter.invoke(tarObj);
            if (tarIdValObj == null)
              continue;
            String tarIdVal = String.valueOf(tarIdValObj);
            // 查询 select * from {tarTable} where {tarIdColumn} =
View Full Code Here

    return false;
  }

  private static List<Property> getProperties(Class<?> clazz,
      final List<Property> pList, final boolean requireSuper) {
    ReflectUtil ru;
    try {
      ru = new ReflectUtil(clazz);
      ru.setRequiredSuper(requireSuper);
    } catch (Error e) {
      return null;
    } catch (Exception e) {
      return null;
    }

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

      Ignore igAnn = f.getAnnotation(Ignore.class);
      if (igAnn == null)
        igAnn = getter.getAnnotation(Ignore.class);
     
      if (igAnn != null)
        continue;

      Transient trans = f.getAnnotation(Transient.class);
      if (trans == null)
        trans = getter.getAnnotation(Transient.class);
     
      if (trans != null)
        continue;
     
      OneToMany manyAnn = getter.getAnnotation(OneToMany.class);
      if (manyAnn != null)
        continue;
      else {
        manyAnn = f.getAnnotation(OneToMany.class);
        if (manyAnn != null)
          continue;
      }

      ManyToMany manyManyAnn = getter.getAnnotation(ManyToMany.class);
      if (manyManyAnn != null)
        continue;
      else {
        manyManyAnn = f.getAnnotation(ManyToMany.class);
        if (manyManyAnn != null)
          continue;
      }

      Property p = new Property();

      if (Long.class.isAssignableFrom(f.getType())
          || long.class.isAssignableFrom(f.getType()))
        p.setSize("20");
      else if (Integer.class.isAssignableFrom(f.getType())
          || int.class.isAssignableFrom(f.getType()))
        p.setSize("4");
      else if (String.class.isAssignableFrom(f.getType()))
        p.setSize("255");
      else if (Boolean.class.isAssignableFrom(f.getType())
          || boolean.class.isAssignableFrom(f.getType()))
        p.setSize("");
      else if (Float.class.isAssignableFrom(f.getType())
          || float.class.isAssignableFrom(f.getType()))
        p.setSize("8");

      Id idAnn = getter.getAnnotation(Id.class);
      if (idAnn == null)
        idAnn = f.getAnnotation(Id.class);

      if (idAnn != null) {
        if (pList != null && hasIdProperty(pList))
          continue;

        p.setAutoIncrement("1");
        p.setPk("1");
        p.setSize("20");

      }

      Column colAnn = getter.getAnnotation(Column.class);
      if (colAnn == null) {
        colAnn = f.getAnnotation(Column.class);
      }

      String column = colAnn == null ? "" : colAnn.name();
      column = "".equals(column.trim()) ? name : column;
      p.setName(name);
      p.setColumn(column);
      p.setType(f.getType().getName());
      p.setNotNull("true");
      if (colAnn != null) {
        // int size = colAnn.length();
        p.setNotNull(String.valueOf(colAnn.nullable()));
        p.setUnique(String.valueOf(colAnn.unique()));
      }

      if (ClassUtil.isPojo(f.getType())) {
        OneToOne oneAnn = getter.getAnnotation(OneToOne.class);
        if (oneAnn == null)
          oneAnn = f.getAnnotation(OneToOne.class);

        if (oneAnn != null) {
          JoinColumn joinColumn = getter
              .getAnnotation(JoinColumn.class);
          if (joinColumn == null)
            joinColumn = f.getAnnotation(JoinColumn.class);

          if (joinColumn == null) {
            p.setColumn(f.getName() + "_id");
          } else {
            if (joinColumn.name().trim().length() == 0) {
              String refCol = joinColumn.referencedColumnName();
              if (refCol == null || refCol.trim().length() == 0)
                p.setColumn(f.getName() + "_id");
              else
                p.setColumn(f.getName() + "_" + refCol);
            } else
              p.setColumn(joinColumn.name());
          }
          String relProperty = oneAnn.mappedBy();
          if (relProperty == null || relProperty.trim().length() == 0)
            relProperty = ORMConfigBeanUtil.getIdField(f.getType());

          p.setRelProperty(relProperty);
          p.setRelClass(f.getType());
          p.setType(PropType.ONE_ONE);
          p.setSize("20");
        }

        ManyToOne manyOneAnn = getter.getAnnotation(ManyToOne.class);
        if (manyOneAnn == null)
          manyOneAnn = f.getAnnotation(ManyToOne.class);

        if (manyOneAnn != null) {
          ReflectUtil _ru;
          try {
            _ru = new ReflectUtil(f.getType());

            for (Field _f : _ru.getFields()) {
              if (!ClassUtil.isListClass(_f))
                continue;

              String _name = _f.getName();
              Method _getter = ru.getGetter(_name);
View Full Code Here

          && !clsName.endsWith("Model")) {
       
        return ;
      }
     
      ReflectUtil ru = new ReflectUtil(t);
      Field[] fields = null;
      if (fieldNames == null || fieldNames.length == 0) {
        fields = ru.getFields();
      } else {
        List<Field> fieldList = new ArrayList<Field>();
        for (String n : fieldNames) {
          if (n != null && !"".equals(n.trim())) {
            Field f = ru.getField(n);
            if (f != null) {
              fieldList.add(f);
            }
          }
        }
View Full Code Here

    xmlWriter.close();
    return this.file;
  }

  private <T> void writeRecursion(Element bean, T t) throws Exception {
    ReflectUtil ru = new ReflectUtil(t);
    Field[] fields = ru.getFields();
    Element property;
    for (Field f : fields) {
      String n = f.getName();
      Method m = ru.getMethod("get" + StringUtil.toUpCaseFirst(n));
      if (m != null) {
        if ("clazz".equals(n)) {
          n = "class";
        }
        Object v = m.invoke(t);
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.