示例#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 String forModelDeleteById(Table table) {
   String primaryKey = table.getPrimaryKey();
   StringBuilder sql = new StringBuilder(45);
   sql.append("delete from \"");
   sql.append(table.getName());
   sql.append("\" where \"").append(primaryKey).append("\" = ?");
   return sql.toString();
 }
示例#4
0
 public String forModelDeleteById(Table table) {
   String[] pKeys = table.getPrimaryKey();
   StringBuilder sql = new StringBuilder(45);
   sql.append("delete from ");
   sql.append(table.getName());
   sql.append(" where ");
   for (int i = 0; i < pKeys.length; i++) {
     if (i > 0) sql.append(" and ");
     sql.append("\"").append(pKeys[i]).append("\" = ?");
   }
   return sql.toString();
 }
示例#5
0
 public String forModelFindById(Table table, String columns) {
   StringBuilder sql = new StringBuilder("select ").append(columns).append(" from ");
   sql.append(table.getName());
   sql.append(" where ");
   String[] pKeys = table.getPrimaryKey();
   for (int i = 0; i < pKeys.length; i++) {
     if (i > 0) {
       sql.append(" and ");
     }
     sql.append(pKeys[i]).append(" = ?");
   }
   return sql.toString();
 }
示例#6
0
 public String forModelFindById(Table table, String columns) {
   StringBuilder sql = new StringBuilder("select ");
   if (columns.trim().equals("*")) {
     sql.append(columns);
   } else {
     String[] columnsArray = columns.split(",");
     for (int i = 0; i < columnsArray.length; i++) {
       if (i > 0) sql.append(", ");
       sql.append("\"").append(columnsArray[i].trim()).append("\"");
     }
   }
   sql.append(" from \"");
   sql.append(table.getName());
   sql.append("\" where \"").append(table.getPrimaryKey()).append("\" = ?");
   return sql.toString();
 }
示例#7
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(")");
 }
示例#8
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);
 }
示例#9
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(")");
 }
示例#10
0
  public String forModelFindById(Table table, String columns) {
    StringBuilder sql = new StringBuilder("select ");
    columns = columns.trim();
    if ("*".equals(columns)) {
      sql.append("*");
    } else {
      String[] arr = columns.split(",");
      for (int i = 0; i < arr.length; i++) {
        if (i > 0) sql.append(",");
        sql.append("\"").append(arr[i].trim()).append("\"");
      }
    }

    sql.append(" from \"");
    sql.append(table.getName());
    sql.append("\" where ");
    String[] pKeys = table.getPrimaryKey();
    for (int i = 0; i < pKeys.length; i++) {
      if (i > 0) sql.append(" and ");
      sql.append("\"").append(pKeys[i]).append("\" = ?");
    }
    return sql.toString();
  }