Exemplo n.º 1
0
  private static void loadParameters(
      PreparedStatement statement, Collection<ColumnInfo> columns, TableRow row)
      throws SQLException {
    int count = 0;
    for (ColumnInfo info : columns) {
      count++;
      String column = info.getCanonicalizedName();
      int jdbctype = info.getType();

      if (row.isColumnNull(column)) {
        statement.setNull(count, jdbctype);
      } else {
        switch (jdbctype) {
          case Types.BOOLEAN:
          case Types.BIT:
            statement.setBoolean(count, row.getBooleanColumn(column));
            break;

          case Types.INTEGER:
            if (isOracle) {
              statement.setLong(count, row.getLongColumn(column));
            } else {
              statement.setInt(count, row.getIntColumn(column));
            }
            break;

          case Types.NUMERIC:
          case Types.DECIMAL:
            statement.setLong(count, row.getLongColumn(column));
            // FIXME should be BigDecimal if TableRow supported that
            break;

          case Types.BIGINT:
            statement.setLong(count, row.getLongColumn(column));
            break;

          case Types.CLOB:
            if (isOracle) {
              // Support CLOBs in place of TEXT columns in Oracle
              statement.setString(count, row.getStringColumn(column));
            } else {
              throw new IllegalArgumentException("Unsupported JDBC type: " + jdbctype);
            }
            break;

          case Types.VARCHAR:
            statement.setString(count, row.getStringColumn(column));
            break;

          case Types.DATE:
            statement.setDate(count, new java.sql.Date(row.getDateColumn(column).getTime()));
            break;

          case Types.TIME:
            statement.setTime(count, new Time(row.getDateColumn(column).getTime()));
            break;

          case Types.TIMESTAMP:
            statement.setTimestamp(count, new Timestamp(row.getDateColumn(column).getTime()));
            break;

          default:
            throw new IllegalArgumentException("Unsupported JDBC type: " + jdbctype);
        }
      }
    }
  }