示例#1
0
 public void forModelUpdate(
     Table table,
     Map<String, Object> attrs,
     Set<String> modifyFlag,
     StringBuilder sql,
     List<Object> paras) {
   sql.append("update ").append(table.getName()).append(" set ");
   String[] pKeys = table.getPrimaryKey();
   for (Entry<String, Object> e : attrs.entrySet()) {
     String colName = e.getKey();
     if (modifyFlag.contains(colName)
         && !isPrimaryKey(colName, pKeys)
         && table.hasColumnLabel(colName)) {
       if (paras.size() > 0) {
         sql.append(", ");
       }
       sql.append(colName).append(" = ? ");
       paras.add(e.getValue());
     }
   }
   sql.append(" where ");
   for (int i = 0; i < pKeys.length; i++) {
     if (i > 0) {
       sql.append(" and ");
     }
     sql.append(pKeys[i]).append(" = ?");
     paras.add(attrs.get(pKeys[i]));
   }
 }
示例#2
0
  public void forModelUpdate(
      Table table,
      Map<String, Object> attrs,
      Set<String> modifyFlag,
      StringBuilder sql,
      List<Object> paras) {
    sql.append("update \"").append(table.getName()).append("\" set ");
    String[] pKeys = table.getPrimaryKey();
    for (Map.Entry<String, Object> e : attrs.entrySet()) {
      String colName = e.getKey();
      if (modifyFlag.contains(colName) && table.hasColumnLabel(colName)) {
        boolean isKey = false;
        for (String pKey : pKeys) // skip primaryKeys
        if (pKey.equalsIgnoreCase(colName)) {
            isKey = true;
            break;
          }

        if (isKey) continue;

        if (paras.size() > 0) sql.append(", ");
        sql.append("\"").append(colName).append("\" = ? ");
        paras.add(e.getValue());
      }
    }
    sql.append(" where ");
    for (int i = 0; i < pKeys.length; i++) {
      if (i > 0) sql.append(" and ");
      sql.append("\"").append(pKeys[i]).append("\" = ?");
      paras.add(attrs.get(pKeys[i]));
    }
  }
示例#3
0
 public void forModelSave(
     Table table, Map<String, Object> attrs, StringBuilder sql, List<Object> paras) {
   sql.append("insert into \"").append(table.getName()).append("\"(");
   StringBuilder temp = new StringBuilder(") values(");
   for (Entry<String, Object> e : attrs.entrySet()) {
     String colName = e.getKey();
     if (table.hasColumnLabel(colName)) {
       if (paras.size() > 0) {
         sql.append(", ");
         temp.append(", ");
       }
       sql.append("\"").append(colName).append("\"");
       temp.append("?");
       paras.add(e.getValue());
     }
   }
   sql.append(temp.toString()).append(")");
 }
示例#4
0
 public void forModelUpdate(
     Table table,
     Map<String, Object> attrs,
     Set<String> modifyFlag,
     String primaryKey,
     Object id,
     StringBuilder sql,
     List<Object> paras) {
   sql.append("update \"").append(table.getName()).append("\" set ");
   for (Entry<String, Object> e : attrs.entrySet()) {
     String colName = e.getKey();
     if (!primaryKey.equalsIgnoreCase(colName)
         && modifyFlag.contains(colName)
         && table.hasColumnLabel(colName)) {
       if (paras.size() > 0) sql.append(", ");
       sql.append("\"").append(colName).append("\" = ? ");
       paras.add(e.getValue());
     }
   }
   sql.append(" where \"").append(primaryKey).append("\" = ?");
   paras.add(id);
 }
示例#5
0
 @Override
 public void forModelSave(
     Table table, Map<String, Object> attrs, StringBuilder sql, List<Object> paras) {
   sql.append("insert into \"").append(table.getName()).append("\"(");
   String primaryKey = table.getPrimaryKey().toString().toLowerCase();
   if (StringUtils.isEmpty(primaryKey)) {
     primaryKey = "id";
   }
   if (attrs.keySet().contains(primaryKey) == false) {
     attrs.put(primaryKey, null);
   }
   StringBuilder temp = new StringBuilder(") values(");
   for (Entry<String, Object> e : attrs.entrySet()) {
     String colName = e.getKey();
     String idVal = null;
     if (primaryKey.equals(colName.toLowerCase())) { // 获取主键值
       if (StringUtils.isNotEmpty((String) e.getValue())) {
         idVal = (String) e.getValue();
       } else {
         idVal = IdGenerater.me.diValFromPool();
       }
     }
     if (table.hasColumnLabel(colName)) {
       if (paras.size() > 0) {
         sql.append(", ");
         temp.append(", ");
       }
       sql.append("\"").append(colName).append("\"");
       temp.append("?");
       if (idVal == null) {
         paras.add(e.getValue());
       } else {
         paras.add(idVal);
       }
     }
   }
   sql.append(temp.toString()).append(")");
 }