Example #1
0
 private String buildSql(final List<Column> columns, final String tableName) {
   StringBuilder builder = new StringBuilder();
   builder.append("upsert into ");
   builder.append(tableName);
   builder.append(" (");
   int count = 1;
   for (Column column : columns) {
     builder.append(column.getName());
     if (count < columns.size()) {
       builder.append(",");
     } else {
       builder.append(")");
     }
     count++;
   }
   builder.append(" VALUES (");
   for (int i = 0; i < columns.size(); i++) {
     if (i < columns.size() - 1) {
       builder.append("?,");
     } else {
       builder.append("?)");
     }
   }
   return builder.toString();
 }
Example #2
0
  private PreparedStatement buildStatement(
      Scenario scenario,
      List<Column> columns,
      PreparedStatement statement,
      SimpleDateFormat simpleDateFormat)
      throws Exception {
    int count = 1;
    for (Column column : columns) {

      DataValue dataValue = getRulesApplier().getDataForRule(scenario, column);
      switch (column.getType()) {
        case VARCHAR:
          if (dataValue.getValue().equals("")) {
            statement.setNull(count, Types.VARCHAR);
          } else {
            statement.setString(count, dataValue.getValue());
          }
          break;
        case CHAR:
          if (dataValue.getValue().equals("")) {
            statement.setNull(count, Types.CHAR);
          } else {
            statement.setString(count, dataValue.getValue());
          }
          break;
        case DECIMAL:
          if (dataValue.getValue().equals("")) {
            statement.setNull(count, Types.DECIMAL);
          } else {
            statement.setBigDecimal(count, new BigDecimal(dataValue.getValue()));
          }
          break;
        case INTEGER:
          if (dataValue.getValue().equals("")) {
            statement.setNull(count, Types.INTEGER);
          } else {
            statement.setInt(count, Integer.parseInt(dataValue.getValue()));
          }
          break;
        case DATE:
          if (dataValue.getValue().equals("")) {
            statement.setNull(count, Types.DATE);
          } else {
            Date date = new java.sql.Date(simpleDateFormat.parse(dataValue.getValue()).getTime());
            statement.setDate(count, date);
          }
          break;
        default:
          break;
      }
      count++;
    }
    return statement;
  }