Package org.eweb4j.orm.config.bean

Examples of org.eweb4j.orm.config.bean.Property


              idAnn = getter.getAnnotation(Id.class);
              if (idAnn == null)
                continue;
            }
           
            Property p = new Property();
            p.setAutoIncrement("1");
            p.setPk("1");
           
            Pk pkAnn = f.getAnnotation(Pk.class);
           
            if (pkAnn != null) {
              p.setPk("1");
            }
           
            String column = colAnn.name();
            column = "".equals(column.trim()) ? name : column;
            p.setName(name);
            p.setColumn(column);
            p.setType(f.getType().getName());
            pList.add(p);
          }
          ormBean.setProperty(pList);
          ormList.add(ormBean);
        }
View Full Code Here


        mmAnn = f.getAnnotation(ManyToMany.class);
        if (mmAnn != null)
          continue;
      }

      Property p = new Property();

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

      if (idAnn != null) {
        p.setAutoIncrement("1");
        p.setPk("1");
      }

      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());

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

        if (oneAnn != null) {
          p.setType(PropType.ONE);
          p.setColumn(oneAnn.mappedBy());
        }
      }

      pList.add(p);
    }
View Full Code Here

          ReflectUtil ru = new ReflectUtil(t);
          ORMConfigBean ormBean = ORMConfigBeanCache.get(cls);

          for (Iterator<Property> it = ormBean.getProperty()
              .iterator(); it.hasNext();) {
            Property p = it.next();
            String type = p.getType();
            if (type == null)
              continue;

            // 如果查询出来的字段名字没有,则不进行值注入
            boolean flag = false;
            for (String col : columns) {
              if (col.equalsIgnoreCase(p.getColumn())) {
                flag = true;
                continue;
              }
            }

            if (!flag)
              continue;

            Method m = ru.getSetter(p.getName());
            if (m == null)
              continue;

            Object value = rs.getObject(p.getColumn());
            if (value == null)
              continue;

            String v = String.valueOf(value);
            if (v == null) {
              v = "";
            }

            if ("int".equalsIgnoreCase(type)
                || "java.lang.Integer".equalsIgnoreCase(type)) {
              if ("".equals(v.trim())) {
                v = "0";
              }
              m.invoke(t, Integer.parseInt(v));
            } else if ("long".equalsIgnoreCase(type)
                || "java.lang.Long".equalsIgnoreCase(type)) {
              if ("".equals(v.trim())) {
                v = "0";
              }
              m.invoke(t, Long.parseLong(v));
            } else if ("float".equalsIgnoreCase(type)
                || "java.lang.Float".equalsIgnoreCase(type)) {
              if ("".equals(v.trim())) {
                v = "0.0";
              }
              m.invoke(t, Float.parseFloat(v));
            } else if ("double".equalsIgnoreCase(type)
                || "java.lang.Double".equalsIgnoreCase(type)) {
              if ("".equals(v.trim())) {
                v = "0.0";
              }

              m.invoke(t, Float.parseFloat(v));
            } else if ("string".equalsIgnoreCase(type)
                || "java.lang.String".equalsIgnoreCase(type)) {
              m.invoke(t, v);
            } else if ("date".equalsIgnoreCase(type)
                || "java.sql.Date".equalsIgnoreCase(type)
                || "java.util.Date".equalsIgnoreCase(type)) {
              m.invoke(t, value);
            } else if (PropType.ONE.equalsIgnoreCase(type)) {
              if ("".equals(v))
                continue;

              Field field = ru.getField(p.getName());
              Class<?> tarClass = field.getType();

              String tarFKField = null;

              tarFKField = ORMConfigBeanUtil.getIdField(tarClass);
View Full Code Here

*/
public class ORMConfigBeanCreator {
  public static ORMConfigBean getORMBean(){
    ORMConfigBean result = new ORMConfigBean();
    List<Property> pList = new ArrayList<Property>();
    Property p = new Property();
    pList.add(p);
    result.setProperty(pList);
    return result;
  }
View Full Code Here

        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);
              if (getter == null)
                continue;

              OneToMany oneManyAnn = _getter
                  .getAnnotation(OneToMany.class);
              if (oneManyAnn == null)
                oneManyAnn = f.getAnnotation(OneToMany.class);

              if (oneManyAnn == null)
                continue;

              Class<?> _targetClass = ClassUtil
                  .getGenericType(_f);
              if (!clazz.getName().equals(_targetClass.getName()))
                continue;

              String relProperty = oneManyAnn.mappedBy();
              if (relProperty == null
                  || relProperty.trim().length() == 0)
                relProperty = ORMConfigBeanUtil.getIdField(_f
                    .getType());

              p.setRelProperty(relProperty);

              break;
            }
          } catch (Exception e) {
          }

          p.setRelClass(f.getType());
          p.setType(PropType.MANY_ONE);
          p.setSize("20");
          JoinColumn col = getter.getAnnotation(JoinColumn.class);
          if (col == null)
            col = f.getAnnotation(JoinColumn.class);

          if (col == null) {
            p.setColumn(f.getName() + "_id");
          } else {
            if (col.name().trim().length() == 0) {
              String refCol = col.referencedColumnName();
              if (refCol == null || refCol.trim().length() == 0)
                p.setColumn(f.getName() + "_id");
              else
                p.setColumn(f.getName() + "_" + refCol);
            } else
              p.setColumn(col.name());
          }
        }
      }

      result.add(p);
View Full Code Here

          ReflectUtil ru = new ReflectUtil(t);
          ORMConfigBean ormBean = ORMConfigBeanCache.get(cls);

          for (Iterator<Property> it = ormBean.getProperty()
              .iterator(); it.hasNext();) {
            Property p = it.next();
            String type = p.getType();
            if (type == null)
              continue;

            // 如果查询出来的字段名字没有,则不进行值注入
            boolean flag = false;
            for (String col : columns) {
              if (col.equalsIgnoreCase(p.getColumn())) {
                flag = true;
                continue;
              }
            }

            if (!flag)
              continue;

            Method m = ru.getSetter(p.getName());
            if (m == null)
              continue;

            Object value = rs.getObject(p.getColumn());
            if (value == null)
              continue;

            String v = String.valueOf(value);
            if (v == null) {
              v = "";
            }

            if ("int".equalsIgnoreCase(type)
                || "java.lang.Integer".equalsIgnoreCase(type)) {
              if ("".equals(v.trim())) {
                v = "0";
              }
              m.invoke(t, Integer.parseInt(v));
            } else if ("long".equalsIgnoreCase(type)
                || "java.lang.Long".equalsIgnoreCase(type)) {
              if ("".equals(v.trim())) {
                v = "0";
              }
              m.invoke(t, Long.parseLong(v));
            } else if ("float".equalsIgnoreCase(type)
                || "java.lang.Float".equalsIgnoreCase(type)) {
              if ("".equals(v.trim())) {
                v = "0.0";
              }
              m.invoke(t, Float.parseFloat(v));
            } else if ("double".equalsIgnoreCase(type)
                || "java.lang.Double".equalsIgnoreCase(type)) {
              if ("".equals(v.trim())) {
                v = "0.0";
              }

              m.invoke(t, Float.parseFloat(v));
            } else if ("string".equalsIgnoreCase(type)
                || "java.lang.String".equalsIgnoreCase(type)) {
              m.invoke(t, v);
            } else if ("boolean".equalsIgnoreCase(type) || "java.lang.Boolean".equalsIgnoreCase(type)){
              if ("1".equals(v.trim()) || "true".equals(v.trim())){
                m.invoke(t, true);
              }else if ("0".equals(v.trim()) || "false".equals(v.trim())){
                m.invoke(t, false);
              }
            } else if ("date".equalsIgnoreCase(type) || "java.sql.Date".equalsIgnoreCase(type) || "java.util.Date".equalsIgnoreCase(type)) {
              m.invoke(t, value);
            } else if (PropType.ONE_ONE.equalsIgnoreCase(type) || PropType.MANY_ONE.equalsIgnoreCase(type)) {
              if ("".equals(v))
                continue;

              Field field = ru.getField(p.getName());
              Class<?> tarClass = field.getType();

              String tarFKField = null;

              tarFKField = ORMConfigBeanUtil.getIdField(tarClass);
View Full Code Here

TOP

Related Classes of org.eweb4j.orm.config.bean.Property

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.