@Override public Date getDate( Object object ) throws KettleValueException { Timestamp timestamp = getTimestamp( object ); if ( timestamp == null ) { return null; } return timestamp; }
public Timestamp getTimestamp( Object[] dataRow ) throws KettleValueException { return ( (ValueMetaTimestamp) meta ).getTimestamp( dataRow[index] ); }
@Override public Long getInteger( Object object ) throws KettleValueException { Timestamp timestamp = getTimestamp( object ); if ( timestamp == null ) { return null; } long ms = timestamp.getTime(); return ms; }
@Override public Double getNumber( Object object ) throws KettleValueException { Timestamp timestamp = getTimestamp( object ); if ( timestamp == null ) { return null; } long ms = timestamp.getTime(); return Long.valueOf( ms ).doubleValue(); }
@Override public Object cloneValueData( Object object ) throws KettleValueException { Timestamp timestamp = getTimestamp( object ); if ( timestamp == null ) { return null; } Timestamp clone = new Timestamp( timestamp.getTime() ); clone.setNanos( timestamp.getNanos() ); return clone; }
@Override public BigDecimal getBigNumber( Object object ) throws KettleValueException { Timestamp timestamp = getTimestamp( object ); if ( timestamp == null ) { return null; } BigDecimal nanos = BigDecimal.valueOf( timestamp.getTime() ).multiply( BigDecimal.valueOf( 1000000000L ) ).add( BigDecimal.valueOf( timestamp.getNanos() ) ); return nanos; }
@Override public String getString( Object object ) throws KettleValueException { return convertTimestampToString( getTimestamp( object ) ); }
public int compare( Object data1, Object data2 ) throws KettleValueException { Timestamp timestamp1 = getTimestamp( data1 ); Timestamp timestamp2 = getTimestamp( data2 ); int cmp = 0; if ( timestamp1 == null ) { if ( timestamp2 == null ) { cmp = 0; } else { cmp = -1; } } else if ( timestamp2 == null ) { cmp = 1; } else { cmp = timestamp1.compareTo( timestamp2 ); } if ( isSortedDescending() ) { return -cmp; } else { return cmp; } }
@Override public void setPreparedStatementValue( DatabaseMeta databaseMeta, PreparedStatement preparedStatement, int index, Object data ) throws KettleDatabaseException { try { if ( data != null ) { preparedStatement.setTimestamp( index, getTimestamp( data ) ); } else { preparedStatement.setNull( index, java.sql.Types.TIMESTAMP ); } } catch ( Exception e ) { throw new KettleDatabaseException( toStringMeta() + " : Unable to set value on prepared statement on index " + index, e ); } }
/** * Convert the specified data to the data type specified in this object. * * @param meta2 * the metadata of the object to be converted * @param data2 * the data of the object to be converted * @return the object in the data type of this value metadata object * @throws KettleValueException * in case there is a data conversion error */ @Override public Object convertData( ValueMetaInterface meta2, Object data2 ) throws KettleValueException { switch ( meta2.getType() ) { case TYPE_TIMESTAMP: return ( (ValueMetaTimestamp) meta2 ).getTimestamp( data2 ); case TYPE_STRING: return convertStringToTimestamp( meta2.getString( data2 ) ); case TYPE_INTEGER: return convertIntegerToTimestamp( meta2.getInteger( data2 ) ); case TYPE_NUMBER: return convertNumberToTimestamp( meta2.getNumber( data2 ) ); case TYPE_DATE: return convertDateToTimestamp( meta2.getDate( data2 ) ); case TYPE_BIGNUMBER: return convertBigNumberToTimestamp( meta2.getBigNumber( data2 ) ); default: throw new KettleValueException( meta2.toStringMeta() + " : can't be converted to a timestamp" ); } }
Timestamp ts = vmTimestamp.getTimestamp(r[i]); RubyTime rubyTime = data.runtime.newTime(ts.getTime()/1000*1000); rubyTime.setNSec(ts.getNanos());