コード例 #1
0
  /**
   * Converts a native value into a JDBC value. The type of cnversion is detected by looking at the
   * columndefinition. If the type of the is unknown to the conversion system, the value is returned
   * unchanged.
   *
   * @returns the converted value or null
   */
  public Object convertNativeToJDBC(tsColumn coldef, Object o) throws tinySQLException {
    int type = coldef.getType();
    if (o == null) {
      return convertNativeToNull(coldef);
    }

    try {

      switch (type) {
        case Types.BIT:
          return convertNativeToBoolean(coldef, o);

        case Types.TINYINT:
          return convertNativeToByte(coldef, o);

        case Types.SMALLINT:
          return convertNativeToShort(coldef, o);

        case Types.INTEGER:
          return convertNativeToInteger(coldef, o);

        case Types.BIGINT:
          return convertNativeToBigInteger(coldef, o);

        case Types.FLOAT:
          return convertNativeToFloat(coldef, o);

        case Types.REAL:
          return convertNativeToDouble(coldef, o);

        case Types.DOUBLE:
          return convertNativeToDouble(coldef, o);

        case Types.NUMERIC:
          return convertNativeToNumber(coldef, o);

        case Types.DECIMAL:
          return convertNativeToNumber(coldef, o);

        case Types.CHAR:
          return convertNativeToString(coldef, o);

        case Types.VARCHAR:
          return convertNativeToString(coldef, o);

        case Types.LONGVARCHAR:
          return convertNativeToString(coldef, o);

        case Types.DATE:
          return convertNativeToDate(coldef, o);

        case Types.TIME:
          return convertNativeToTime(coldef, o);

        case Types.TIMESTAMP:
          return convertNativeToTimestamp(coldef, o);

          // if we don't know how to handle a object, return it unchanged
        default:
          Log.warn("Unknown type, returning object unchanged.");

          return o;
      }
    } catch (Exception e) {
      Log.error("Convert Failed for column " + coldef, e);
    }
    return o;
  }