Examples of ORMConfigBean


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

      return "";
    }
  }

  private String makeSQL(T t, String condition) {
    ORMConfigBean ormBean = ORMConfigBeanCache.get(t.getClass());
    String table = ormBean != null ? ormBean.getTable() : t.getClass()
        .getSimpleName();
    return String.format("DELETE FROM %s WHERE %s ;", table, condition);
  }
View Full Code Here

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

  public static String write(String dataBase) {
    StringBuilder sql = new StringBuilder();
    StringBuilder manyMany = new StringBuilder();
    for (Iterator<Entry<Object, ORMConfigBean>> it = ORMConfigBeanCache.entrySet().iterator(); it.hasNext();) {
      Entry<Object, ORMConfigBean> e = it.next();
      ORMConfigBean ocb = e.getValue();
      String table = ocb.getTable();
     
      sql.append( "\n-- ----------------------------" +
            "\n-- Created by "+ EWeb4JConfig.about() +
            "\n-- at "+ StringUtil.getNowTime()  +
            "\n-- Models of "+ ocb.getClazz()  +
            "\n-- Records of "+ table +
            "\n-- ----------------------------\n");
     
      List<Property> properties = ocb.getProperty();
      StringBuilder sb = new StringBuilder();
      StringBuilder fkSb = new StringBuilder();
      final String fk = ", \n\tKEY %s (%s), \n\tCONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s)";
      StringBuilder pkSb = new StringBuilder();
      final String pk = ", \n\tPRIMARY KEY (%s)";
View Full Code Here

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

      return "";
    }
  }

  private String makeSQL(T t, String condition) {
    ORMConfigBean ormBean = ORMConfigBeanCache.get(t.getClass());
    String table = ormBean != null ? ormBean.getTable() : t.getClass()
        .getSimpleName();
    return String.format("DELETE FROM %s WHERE %s ;", table, condition);
  }
View Full Code Here

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

         
          Table tableAnn = clazz.getAnnotation(Table.class);
          String table = tableAnn == null ? "" :tableAnn.name();
          table = "".equals(table.trim()) ? clsName
              : 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;
            }

            Id idAnn = f.getAnnotation(Id.class);
            if (idAnn == null){
              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);
        }

        BeanXMLUtil.getBeanXMLWriter(file, ormList).write();
      } catch (Exception e) {
View Full Code Here

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

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

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

      ManyToMany mmAnn = getter.getAnnotation(ManyToMany.class);
      if (mmAnn != null)
        continue;
      else {
        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);
    }

    ormBean.setProperty(pList);
    ORMConfigBeanCache.add(clazz, ormBean);
  }
View Full Code Here

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

   *            1的时候获取的是数据库字段名,2的时候获取的是java类的属性名
   * @return
   */
  public static String getId(Class<?> clazz, int type) {
    String pk = "id";
    ORMConfigBean ormBean = ORMConfigBeanCache.get(clazz);
    if (ormBean == null)
      return pk;
   
    for (Property property : ormBean.getProperty()) {
      if (("true".equals(property.getPk()) || "1"
          .equals(property.getPk()))
          && ("true".equals(property.getAutoIncrement()) || "1"
              .equals(property.getAutoIncrement()))) {
        if (1 == type)
View Full Code Here

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

   *
   * @param clazz
   * @return
   */
  public static String getTable(Class<?> clazz) {
    ORMConfigBean ormBean = ORMConfigBeanCache.get(clazz);
    String table = ormBean == null ? clazz.getSimpleName() : ormBean
        .getTable();
    return table;
  }
View Full Code Here

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

      int type) {
    if (strs == null)
      strs = new String[] { "" };
    String[] result = strs.clone();
    List<String> list = new ArrayList<String>();
    ORMConfigBean ormBean = ORMConfigBeanCache.get(clazz);
    if (ormBean != null) {
      // String idColumn = getIdColumn(clazz);
      for (int i = 0; i < strs.length; i++) {
        boolean finished = false;
        List<Property> properties = ormBean.getProperty();
        for (Property p : properties) {
          if (finished)
            break;
          // if ((3 == type || 4 == type)
          // && idColumn.equals(p.getColumn()))
View Full Code Here

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

        return (List<T>) (_list.isEmpty() ? null : _list);
      } else {
        while (rs.next()) {
          t = cls.newInstance();
          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;
View Full Code Here

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

* @author cfuture.aw
* @since v1.a.0
*/
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
TOP
Copyright © 2018 www.massapi.com. 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.