Beispiel #1
0
  public String getColUpdate(String colName) {
    StringBuilder builder = new StringBuilder();
    ColumnMapping mapping = colsToFields.get(colName);

    // simple mapping
    if (!mapping.isMap) {
      builder.append(colName).append(" = ? ");
    }

    return builder.toString();
  }
Beispiel #2
0
 public String getIdPredicate() {
   StringBuilder builder = new StringBuilder();
   builder.append(" where ");
   if (embedded == null) {
     builder.append(idMapping.name).append(eqParam);
   } else {
     int i = 0;
     for (ColumnMapping mapping : embedded.columns) {
       builder.append(mapping.name).append(eqParam);
       if (i < embedded.columns.length - 1) builder.append(" and ");
       i++;
     }
   }
   return builder.toString();
 }
Beispiel #3
0
  /**
   * Might move this out to a utility class This has been moved to {@link
   * AbstractEntityManager#getUpdateStatement(Object)}
   *
   * @param obj
   * @return
   */
  @Deprecated
  public SimpleStatement getUpdateStatement(T obj) {

    StringBuilder builder = new StringBuilder("UPDATE ").append(tableName).append(" SET ");
    ArrayList<Object> valueList = new ArrayList<>();
    int i = 0;
    // go through the columns
    for (String col : colsToFields.keySet()) {

      ColumnMapping mapping = colsToFields.get(col);
      Object valueObj = mapping.get(obj);

      if (!mapping.isMap) {
        builder.append(getColUpdate(col));
        valueList.add(valueObj);

      } else {
        Map<String, String> map = (Map<String, String>) valueObj;
        if (map != null) {
          int im = 0;
          for (String key : map.keySet()) {
            builder.append(col).append(openbsq).append(key).append(sqcloseb).append(eqParam);
            if (im++ < map.size() - 1) builder.append(comma).append(space);

            valueList.add(map.get(key));
          }
        }
      }
      if (i++ < (colsToFields.size() - 1)) builder.append(comma).append(space);
    }

    builder.append(getIdPredicate());
    if (embedded != null) {
      try {
        // this needs some improvement to the embedded class
        Object idObj = embedded.field.get(obj);
        for (ColumnMapping membed : embedded.columns) {
          valueList.add(membed.get(idObj));
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    SimpleStatement ss = new SimpleStatement(builder.toString(), valueList.toArray());
    // System.out.println("update ss : " + ss.getQueryString());
    return ss;
  }