Hi all,

I am still working on the JDBC sinks. This time on implementing
timestamps.

Like in the MySQL sink implemented by Philipp,I am trying to get an
universal approach.

I would like to test it but there is a problem.
I am using the ISS adapter and the random adapter and in both cases the
timestamp is not running under SO.DateTime domain.It is running under
FLOAT! I checked the ISS adapter and timestamp is set as timestamp with
the correct DateTime domain.
Can someone reproduce this?



For the implementation  I added some extras in the enum SQLAttribute
enum
First I added a new enum field with 

TIMESTAMP("TIMESTAMP").

Then I also added in the getFromUri a case for SO.DateTime

  public static SqlAttribute getFromUri(final String s) {
    SqlAttribute r;
    if (s.equals(XSD._integer.toString())) {
      r = SqlAttribute.INTEGER;
    } else if (s.equals(XSD._long.toString())) {
      r = SqlAttribute.LONG;
    } else if (s.equals(XSD._float.toString())) {
      r = SqlAttribute.FLOAT;
    } else if (s.equals(XSD._double.toString())) {
      r = SqlAttribute.DOUBLE;
    } else if (s.equals(XSD._boolean.toString())) {
      r = SqlAttribute.BOOLEAN;
    } else if (s.equals(SO.DateTime)) {
      r = SqlAttribute.TIMESTAMP;
    } else {
      r = SqlAttribute.STRING;
    }
    return r;
  }


The value transformation from Unix Timestamp to timestamp format is
done in the setValue method

  public static void setValue(Parameterinfo p, Object value,
PreparedStatement ps)
      throws SQLException, SpRuntimeException {
    switch (p.type) {
      case INTEGER:
        ps.setInt(p.index, (Integer) value);
        break;
      case LONG:
        ps.setLong(p.index, (Long) value);
        break;
      case FLOAT:
        ps.setFloat(p.index, (Float) value);
        break;
      case DOUBLE:
        ps.setDouble(p.index, (Double) value);
        break;
      case BOOLEAN:
        ps.setBoolean(p.index, (Boolean) value);
        break;
      case STRING:
        ps.setString(p.index, value.toString());
        break;
      case TIMESTAMP:
        java.sql.Timestamp sqlTimestamp = new java.sql.Timestamp((Long)
value);
        ps.setString(p.index,  sqlTimestamp.toString());
      default:
        throw new SpRuntimeException("Unknown SQL datatype");
    }
  }

Greetings
Florian

Reply via email to