Examples of ORMColumn


Examples of cn.org.zeronote.orm.ORMColumn

   */
  public void find(Object... objs) throws IllegalArgumentException, IllegalAccessException, SQLException {
    Class<?> clz = objs[0].getClass();
    Field[] fields = clz.getDeclaredFields();
    for (Field field : fields) {
      ORMColumn oc = field.getAnnotation(ORMColumn.class);
      if (oc != null && oc.physicalPkFld() && oc.autoIncrement()) {
        // 找到最后一个自增id
        QueryRunner qr = new QueryRunner();
        Object identityVal = qr.query(conn, selectKey.getQuery(), new ScalarHandler<Object>());
        Long identity = NumberUtils.parseNumber(identityVal.toString(), Long.class);
       
View Full Code Here

Examples of cn.org.zeronote.orm.ORMColumn

 
  private boolean check(T t) throws IllegalArgumentException, IllegalAccessException {
    Field[] fields = pojoType.getDeclaredFields();
    for (Field field : fields) {
      field.setAccessible(true);
      ORMColumn ormc = field.getAnnotation(ORMColumn.class);
      if (ormc != null) {
        if (filter.get(ormc.value()) == null) {
          continue;
        }
        if (!field.get(t).equals(filter.get(isIgnoreCase() ? ormc.value().toLowerCase() : ormc.value()))) {
          return false;
        }
      }
    }
    return true;
View Full Code Here

Examples of cn.org.zeronote.orm.ORMColumn

        parentClz = parentClz.getSuperclass();
       
        fields = parentClz.getDeclaredFields();
        for (Field field : fields) {
          field.setAccessible(true);
          ORMColumn ormc = field.getAnnotation(ORMColumn.class);
          fieldsMap.put(field, ormc);
        }
      }
      // this class
      fields = clz.getDeclaredFields();
      for (Field field : fields) {
        field.setAccessible(true);
        ORMColumn ormc = field.getAnnotation(ORMColumn.class);
        fieldsMap.put(field, ormc);
        ORMCanUpdate ocu = field.getAnnotation(ORMCanUpdate.class);
        if (ocu != null) {
          // 只取一个,并且是最后找到的那个,po里只应该存在一个
          fieldsCanUpdateCache.put(clz, field);
        }
      }

    }
   
    for (Field field : fieldsMap.keySet()) {
      if (requireFields != null && !requireFields.isEmpty() && !requireFields.contains(field.getName())) {
        continue;
      }
      ORMColumn ormc = fieldsMap.get(field);
      if (ormc != null && clList.keySet().contains(ignoreCase ? ormc.value().toLowerCase() : ormc.value())) {  // metadata中需要有
        try {
          Integer[] is = clList.get(ignoreCase ? ormc.value().toLowerCase() : ormc.value());
          field.set(bean, conversionType(getValue(rs, is[0], is[1], field.getType()), is[1], field.getType()));
        } catch (IllegalArgumentException e) {
          throw new SQLException("Cannot write value: " + field.getName(), e);
        } catch (IllegalAccessException e) {
          throw new SQLException("Cannot write value: " + field.getName(), e);
View Full Code Here

Examples of cn.org.zeronote.orm.ORMColumn

      if (!requireFields.isEmpty() && !requireFields.contains(field.getName())) {
        // 不为空,则表示需要过滤,则判断是否包含,不包含,找下一个
        continue;
      }
      field.setAccessible(true);
      ORMColumn ormc = getAnnotation(pojoClazz, field);
      if (ormc != null) {
        sql.append(ormc.value()).append(",");
      }
    }
    sql.replace(sql.length() - 1, sql.length(), " ");
    // FROM
    sql.append("FROM ").append(tableName).append(" ");
    // WHERE
    if (argsMap != null && argsMap.size() > 0) {
      sql.append("WHERE (");
      for (Field field : fields) {
        field.setAccessible(true);
        ORMColumn ormc = getAnnotation(pojoClazz, field);
        if (ormc != null) {
          Object[] val = argsMap.get(field.getName());
          if (val != null) {
            if (val.length > 1) {
              // 多参数
              sql.append("(");
              for (Object ovl : val) {
                sql.append(ormc.value()).append("=? OR ");
                Class<?> tc = field.getDeclaringClass();
                params.add(matchParam(ovl, tc));
              }
              sql.delete(sql.length() - 3, sql.length());
              sql.append(") AND ");
            } else {
              // 单参数
              sql.append(ormc.value()).append("=? AND ");
              Class<?> tc = field.getDeclaringClass();
              params.add(matchParam(val[0], tc));
            }
          }
        }
View Full Code Here

Examples of cn.org.zeronote.orm.ORMColumn

        if (fs == null) {
          fs = new HashMap<Field, ORMColumn>();
          Field[] fields = pojoClazz.getDeclaredFields();
          for (Field f : fields) {
            f.setAccessible(true);
            ORMColumn ormc = f.getAnnotation(ORMColumn.class);
            fs.put(f, ormc);
          }
          fieldsCache.put(clz, fs);
        }
      }
View Full Code Here

Examples of cn.org.zeronote.orm.ORMColumn

    ins.append(tableName).append(" (");
    // INSERT
    Field[] fields = pojoClazz.getDeclaredFields();
    for (Field field : fields) {
      field.setAccessible(true);
      ORMColumn ormc = field.getAnnotation(ORMColumn.class);
      if (ormc != null) {
        Object val = field.get(pojo);
        if (val != null) {
          // 不是空才去设置
          ins.append(ormc.value()).append(", ");
          params.add(val);
          paramKeys.add("?");
        } else if (!"null".equalsIgnoreCase(ormc.defaultValue())) {
          // 是空,但是有默认值,则设置
          switch (ormc.defaultValueScope()) {
          case ALL:
          case INSERT:
            ins.append(ormc.value()).append(", ");
            Object value = ORMColumn.DEFAULT_DATE.equals(ormc.defaultValue()) ? new Date() : ormc.defaultValue();
            params.add(value);
            paramKeys.add("?");
            // 回写到pojo中
            try {
              if (value != null) {
View Full Code Here

Examples of cn.org.zeronote.orm.ORMColumn

   */
  private Map<String, Object> fieldArgsMap(Class<?> pojoType, Object pkVal, boolean usePhysicalPk) throws IllegalArgumentException, IllegalAccessException {
    Map<String, Object> delArgs = new HashMap<String, Object>();
    Field[] fields = pojoType.getDeclaredFields();
    for (Field f : fields) {
      ORMColumn ormc = f.getAnnotation(ORMColumn.class);
      if (ormc != null) {
        if (usePhysicalPk) {
          if (ormc.physicalPkFld()) {
            f.setAccessible(true);
            delArgs.put(f.getName(), pkVal);
          }
        } else {
          if (ormc.LogicPkFld()) {
            f.setAccessible(true);
            delArgs.put(f.getName(), pkVal);
          }
        }
       
View Full Code Here

Examples of cn.org.zeronote.orm.ORMColumn

   */
  private Map<String, Object> fieldArgsMap(Object pojo, boolean usePhysicalPk) throws IllegalArgumentException, IllegalAccessException {
    Map<String, Object> delArgs = new HashMap<String, Object>();
    Field[] fields = pojo.getClass().getDeclaredFields();
    for (Field f : fields) {
      ORMColumn ormc = f.getAnnotation(ORMColumn.class);
      if (ormc != null) {
        if (usePhysicalPk) {
          if (ormc.physicalPkFld()) {
            f.setAccessible(true);
            delArgs.put(f.getName(), f.get(pojo));
          }
        } else {
          if (ormc.LogicPkFld()) {
            f.setAccessible(true);
            delArgs.put(f.getName(), f.get(pojo));
          }
        }
       
View Full Code Here

Examples of cn.org.zeronote.orm.ORMColumn

    if (delArgs != null && !delArgs.isEmpty()) {
      del.append("WHERE ");
      for (String pk : delArgs.keySet()) {
        for (Field field : fields) {
          field.setAccessible(true);
          ORMColumn ormc = field.getAnnotation(ORMColumn.class);
          if (ormc != null && field.getName().equalsIgnoreCase(pk)) {
            // 是主键,作为条件
            del.append(ormc.value()).append("=? AND ");
            Object val = delArgs.get(pk);
            params.add(val);
          }
        }
      }
View Full Code Here

Examples of cn.org.zeronote.orm.ORMColumn

    Field[] fields = pojoClazz.getDeclaredFields();
    List<String> pks = null;
    if (usePhysicalPk) {
      pks = new ArrayList<String>();
      for (Field f : fields) {
        ORMColumn ormc = f.getAnnotation(ORMColumn.class);
        if (ormc != null && ormc.physicalPkFld()) {
          pks.add(ormc.value());
        }
      }
    } else {
      pks = new ArrayList<String>();
      for (Field f : fields) {
        ORMColumn ormc = f.getAnnotation(ORMColumn.class);
        if (ormc != null && ormc.LogicPkFld()) {
          pks.add(ormc.value());
        }
      }
    }
   
    for (Field field : fields) {
      field.setAccessible(true);
      ORMColumn ormc = field.getAnnotation(ORMColumn.class);
      // 主键不允许修改
      if (ormc != null && !pks.contains(ormc.value())) {
        Object val = field.get(pojo);
        if (val != null) {
          // 不是空才去设置
          if (ormc.append()) {
            upd.append(ormc.value()).append("=").append(ormc.value()).append("||?, ")// XXX 只适合Oracle,需要方言支持
          } else {
            upd.append(ormc.value()).append("=?, ");
          }
          params.add(val);
        } else if (!"null".equalsIgnoreCase(ormc.defaultValue())) {
          // 是null,但是有默认值,则设置
          switch (ormc.defaultValueScope()) {
          case ALL:
          case UPDATE:
              if (ormc.append()) {
                          upd.append(ormc.value()).append("=").append(ormc.value()).append("||?, ")// XXX 只适合Oracle,需要方言支持
                      } else {
                          upd.append(ormc.value()).append("=?, ");
                      }
             
                Object value = ORMColumn.DEFAULT_DATE.equals(ormc.defaultValue()) ? new Date() : ValueUtils.conversionType(ormc.defaultValue(), field.getType());
                        params.add(value);
            break;
          default:
            break;
          }
        }
      }
    }
    upd.replace(upd.length() - 2, upd.length(), " ");
    // WHERE
    if (pks != null && pks.size() > 0) {
      upd.append("WHERE ");
      for (String pk : pks) {
        for (Field field : fields) {
          field.setAccessible(true);
          ORMColumn ormc = field.getAnnotation(ORMColumn.class);
          if (ormc != null && ormc.value().equalsIgnoreCase(pk)) {
            // 是主键,作为条件
            upd.append(pk).append("=? AND ");
            Object val = field.get(pojo);
            params.add(val);
          }
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.