@Test public void testBooleanConversion() throws Exception { row = new RowMetaAndData( rowsMeta, null, true, null ); assertEquals( true, row.getAsJavaType( "bool", boolean.class, converter ) ); assertEquals( true, row.getAsJavaType( "bool", Boolean.class, converter ) ); assertEquals( 1, row.getAsJavaType( "bool", int.class, converter ) ); assertEquals( 1, row.getAsJavaType( "bool", Integer.class, converter ) ); assertEquals( 1L, row.getAsJavaType( "bool", long.class, converter ) ); assertEquals( 1L, row.getAsJavaType( "bool", Long.class, converter ) ); assertEquals( "Y", row.getAsJavaType( "bool", String.class, converter ) ); row = new RowMetaAndData( rowsMeta, null, false, null ); assertEquals( false, row.getAsJavaType( "bool", boolean.class, converter ) ); assertEquals( false, row.getAsJavaType( "bool", Boolean.class, converter ) ); assertEquals( 0, row.getAsJavaType( "bool", int.class, converter ) ); assertEquals( 0, row.getAsJavaType( "bool", Integer.class, converter ) ); assertEquals( 0L, row.getAsJavaType( "bool", long.class, converter ) ); assertEquals( 0L, row.getAsJavaType( "bool", Long.class, converter ) ); assertEquals( "N", row.getAsJavaType( "bool", String.class, converter ) ); row = new RowMetaAndData( rowsMeta, null, null, null ); assertEquals( null, row.getAsJavaType( "bool", String.class, converter ) ); assertEquals( null, row.getAsJavaType( "bool", Integer.class, converter ) ); assertEquals( null, row.getAsJavaType( "bool", Long.class, converter ) ); assertEquals( null, row.getAsJavaType( "bool", Boolean.class, converter ) ); }
public Object getAsJavaType( String valueName, Class<?> destinationType, InjectionTypeConverter converter ) throws KettleValueException { int idx = rowMeta.indexOfValue( valueName ); if ( idx < 0 ) { throw new KettleValueException( "Unknown column '" + valueName + "'" ); } ValueMetaInterface metaType = rowMeta.getValueMeta( idx ); switch ( metaType.getType() ) { case ValueMetaInterface.TYPE_STRING: String vs = rowMeta.getString( data, idx ); return getStringAsJavaType( vs, destinationType, converter ); case ValueMetaInterface.TYPE_BOOLEAN: Boolean vb = rowMeta.getBoolean( data, idx ); if ( String.class.isAssignableFrom( destinationType ) ) { return converter.boolean2string( vb ); } else if ( int.class.isAssignableFrom( destinationType ) ) { return converter.boolean2intPrimitive( vb ); } else if ( Integer.class.isAssignableFrom( destinationType ) ) { return converter.boolean2integer( vb ); } else if ( long.class.isAssignableFrom( destinationType ) ) { return converter.boolean2longPrimitive( vb ); } else if ( Long.class.isAssignableFrom( destinationType ) ) { return converter.boolean2long( vb ); } else if ( boolean.class.isAssignableFrom( destinationType ) ) { return converter.boolean2booleanPrimitive( vb ); } else if ( Boolean.class.isAssignableFrom( destinationType ) ) { return converter.boolean2boolean( vb ); } else if ( destinationType.isEnum() ) { return converter.boolean2enum( destinationType, vb ); } else { throw new RuntimeException( "Wrong value conversion to " + destinationType ); } case ValueMetaInterface.TYPE_INTEGER: Long vi = rowMeta.getInteger( data, idx ); if ( String.class.isAssignableFrom( destinationType ) ) { return converter.integer2string( vi ); } else if ( int.class.isAssignableFrom( destinationType ) ) { return converter.integer2intPrimitive( vi ); } else if ( Integer.class.isAssignableFrom( destinationType ) ) { return converter.integer2integer( vi ); } else if ( long.class.isAssignableFrom( destinationType ) ) { return converter.integer2longPrimitive( vi ); } else if ( Long.class.isAssignableFrom( destinationType ) ) { return converter.integer2long( vi ); } else if ( boolean.class.isAssignableFrom( destinationType ) ) { return converter.integer2booleanPrimitive( vi ); } else if ( Boolean.class.isAssignableFrom( destinationType ) ) { return converter.integer2boolean( vi ); } else if ( destinationType.isEnum() ) { return converter.integer2enum( destinationType, vi ); } else { throw new RuntimeException( "Wrong value conversion to " + destinationType ); } case ValueMetaInterface.TYPE_NUMBER: Double vn = rowMeta.getNumber( data, idx ); if ( String.class.isAssignableFrom( destinationType ) ) { return converter.number2string( vn ); } else if ( int.class.isAssignableFrom( destinationType ) ) { return converter.number2intPrimitive( vn ); } else if ( Integer.class.isAssignableFrom( destinationType ) ) { return converter.number2integer( vn ); } else if ( long.class.isAssignableFrom( destinationType ) ) { return converter.number2longPrimitive( vn ); } else if ( Long.class.isAssignableFrom( destinationType ) ) { return converter.number2long( vn ); } else if ( boolean.class.isAssignableFrom( destinationType ) ) { return converter.number2booleanPrimitive( vn ); } else if ( Boolean.class.isAssignableFrom( destinationType ) ) { return converter.number2boolean( vn ); } else if ( destinationType.isEnum() ) { return converter.number2enum( destinationType, vn ); } else { throw new RuntimeException( "Wrong value conversion to " + destinationType ); } } throw new KettleValueException( "Unknown conversion from " + metaType.getTypeDesc() + " into " + destinationType ); }
RowMetaAndData implements Cloneable { public Object getAsJavaType( String valueName, Class<?> destinationType, InjectionTypeConverter converter ) throws KettleValueException { int idx = rowMeta.indexOfValue( valueName ); if ( idx < 0 ) { throw new KettleValueException( "Unknown column '" + valueName + "'" ); } ValueMetaInterface metaType = rowMeta.getValueMeta( idx ); switch ( metaType.getType() ) { case ValueMetaInterface.TYPE_STRING: String vs = rowMeta.getString( data, idx ); return getStringAsJavaType( vs, destinationType, converter ); case ValueMetaInterface.TYPE_BOOLEAN: Boolean vb = rowMeta.getBoolean( data, idx ); if ( String.class.isAssignableFrom( destinationType ) ) { return converter.boolean2string( vb ); } else if ( int.class.isAssignableFrom( destinationType ) ) { return converter.boolean2intPrimitive( vb ); } else if ( Integer.class.isAssignableFrom( destinationType ) ) { return converter.boolean2integer( vb ); } else if ( long.class.isAssignableFrom( destinationType ) ) { return converter.boolean2longPrimitive( vb ); } else if ( Long.class.isAssignableFrom( destinationType ) ) { return converter.boolean2long( vb ); } else if ( boolean.class.isAssignableFrom( destinationType ) ) { return converter.boolean2booleanPrimitive( vb ); } else if ( Boolean.class.isAssignableFrom( destinationType ) ) { return converter.boolean2boolean( vb ); } else if ( destinationType.isEnum() ) { return converter.boolean2enum( destinationType, vb ); } else { throw new RuntimeException( "Wrong value conversion to " + destinationType ); } case ValueMetaInterface.TYPE_INTEGER: Long vi = rowMeta.getInteger( data, idx ); if ( String.class.isAssignableFrom( destinationType ) ) { return converter.integer2string( vi ); } else if ( int.class.isAssignableFrom( destinationType ) ) { return converter.integer2intPrimitive( vi ); } else if ( Integer.class.isAssignableFrom( destinationType ) ) { return converter.integer2integer( vi ); } else if ( long.class.isAssignableFrom( destinationType ) ) { return converter.integer2longPrimitive( vi ); } else if ( Long.class.isAssignableFrom( destinationType ) ) { return converter.integer2long( vi ); } else if ( boolean.class.isAssignableFrom( destinationType ) ) { return converter.integer2booleanPrimitive( vi ); } else if ( Boolean.class.isAssignableFrom( destinationType ) ) { return converter.integer2boolean( vi ); } else if ( destinationType.isEnum() ) { return converter.integer2enum( destinationType, vi ); } else { throw new RuntimeException( "Wrong value conversion to " + destinationType ); } case ValueMetaInterface.TYPE_NUMBER: Double vn = rowMeta.getNumber( data, idx ); if ( String.class.isAssignableFrom( destinationType ) ) { return converter.number2string( vn ); } else if ( int.class.isAssignableFrom( destinationType ) ) { return converter.number2intPrimitive( vn ); } else if ( Integer.class.isAssignableFrom( destinationType ) ) { return converter.number2integer( vn ); } else if ( long.class.isAssignableFrom( destinationType ) ) { return converter.number2longPrimitive( vn ); } else if ( Long.class.isAssignableFrom( destinationType ) ) { return converter.number2long( vn ); } else if ( boolean.class.isAssignableFrom( destinationType ) ) { return converter.number2booleanPrimitive( vn ); } else if ( Boolean.class.isAssignableFrom( destinationType ) ) { return converter.number2boolean( vn ); } else if ( destinationType.isEnum() ) { return converter.number2enum( destinationType, vn ); } else { throw new RuntimeException( "Wrong value conversion to " + destinationType ); } } throw new KettleValueException( "Unknown conversion from " + metaType.getTypeDesc() + " into " + destinationType ); } }
RowMetaAndData implements Cloneable { public Object getAsJavaType( String valueName, Class<?> destinationType, InjectionTypeConverter converter ) throws KettleValueException { int idx = rowMeta.indexOfValue( valueName ); if ( idx < 0 ) { throw new KettleValueException( "Unknown column '" + valueName + "'" ); } ValueMetaInterface metaType = rowMeta.getValueMeta( idx ); switch ( metaType.getType() ) { case ValueMetaInterface.TYPE_STRING: String vs = rowMeta.getString( data, idx ); return getStringAsJavaType( vs, destinationType, converter ); case ValueMetaInterface.TYPE_BOOLEAN: Boolean vb = rowMeta.getBoolean( data, idx ); if ( String.class.isAssignableFrom( destinationType ) ) { return converter.boolean2string( vb ); } else if ( int.class.isAssignableFrom( destinationType ) ) { return converter.boolean2intPrimitive( vb ); } else if ( Integer.class.isAssignableFrom( destinationType ) ) { return converter.boolean2integer( vb ); } else if ( long.class.isAssignableFrom( destinationType ) ) { return converter.boolean2longPrimitive( vb ); } else if ( Long.class.isAssignableFrom( destinationType ) ) { return converter.boolean2long( vb ); } else if ( boolean.class.isAssignableFrom( destinationType ) ) { return converter.boolean2booleanPrimitive( vb ); } else if ( Boolean.class.isAssignableFrom( destinationType ) ) { return converter.boolean2boolean( vb ); } else if ( destinationType.isEnum() ) { return converter.boolean2enum( destinationType, vb ); } else { throw new RuntimeException( "Wrong value conversion to " + destinationType ); } case ValueMetaInterface.TYPE_INTEGER: Long vi = rowMeta.getInteger( data, idx ); if ( String.class.isAssignableFrom( destinationType ) ) { return converter.integer2string( vi ); } else if ( int.class.isAssignableFrom( destinationType ) ) { return converter.integer2intPrimitive( vi ); } else if ( Integer.class.isAssignableFrom( destinationType ) ) { return converter.integer2integer( vi ); } else if ( long.class.isAssignableFrom( destinationType ) ) { return converter.integer2longPrimitive( vi ); } else if ( Long.class.isAssignableFrom( destinationType ) ) { return converter.integer2long( vi ); } else if ( boolean.class.isAssignableFrom( destinationType ) ) { return converter.integer2booleanPrimitive( vi ); } else if ( Boolean.class.isAssignableFrom( destinationType ) ) { return converter.integer2boolean( vi ); } else if ( destinationType.isEnum() ) { return converter.integer2enum( destinationType, vi ); } else { throw new RuntimeException( "Wrong value conversion to " + destinationType ); } case ValueMetaInterface.TYPE_NUMBER: Double vn = rowMeta.getNumber( data, idx ); if ( String.class.isAssignableFrom( destinationType ) ) { return converter.number2string( vn ); } else if ( int.class.isAssignableFrom( destinationType ) ) { return converter.number2intPrimitive( vn ); } else if ( Integer.class.isAssignableFrom( destinationType ) ) { return converter.number2integer( vn ); } else if ( long.class.isAssignableFrom( destinationType ) ) { return converter.number2longPrimitive( vn ); } else if ( Long.class.isAssignableFrom( destinationType ) ) { return converter.number2long( vn ); } else if ( boolean.class.isAssignableFrom( destinationType ) ) { return converter.number2booleanPrimitive( vn ); } else if ( Boolean.class.isAssignableFrom( destinationType ) ) { return converter.number2boolean( vn ); } else if ( destinationType.isEnum() ) { return converter.number2enum( destinationType, vn ); } else { throw new RuntimeException( "Wrong value conversion to " + destinationType ); } } throw new KettleValueException( "Unknown conversion from " + metaType.getTypeDesc() + " into " + destinationType ); } RowMetaAndData();  RowMetaAndData( RowMetaInterface rowMeta, Object... data ); }
RowMetaAndData implements Cloneable { public Object getAsJavaType( String valueName, Class<?> destinationType, InjectionTypeConverter converter ) throws KettleValueException { int idx = rowMeta.indexOfValue( valueName ); if ( idx < 0 ) { throw new KettleValueException( "Unknown column '" + valueName + "'" ); } ValueMetaInterface metaType = rowMeta.getValueMeta( idx ); switch ( metaType.getType() ) { case ValueMetaInterface.TYPE_STRING: String vs = rowMeta.getString( data, idx ); return getStringAsJavaType( vs, destinationType, converter ); case ValueMetaInterface.TYPE_BOOLEAN: Boolean vb = rowMeta.getBoolean( data, idx ); if ( String.class.isAssignableFrom( destinationType ) ) { return converter.boolean2string( vb ); } else if ( int.class.isAssignableFrom( destinationType ) ) { return converter.boolean2intPrimitive( vb ); } else if ( Integer.class.isAssignableFrom( destinationType ) ) { return converter.boolean2integer( vb ); } else if ( long.class.isAssignableFrom( destinationType ) ) { return converter.boolean2longPrimitive( vb ); } else if ( Long.class.isAssignableFrom( destinationType ) ) { return converter.boolean2long( vb ); } else if ( boolean.class.isAssignableFrom( destinationType ) ) { return converter.boolean2booleanPrimitive( vb ); } else if ( Boolean.class.isAssignableFrom( destinationType ) ) { return converter.boolean2boolean( vb ); } else if ( destinationType.isEnum() ) { return converter.boolean2enum( destinationType, vb ); } else { throw new RuntimeException( "Wrong value conversion to " + destinationType ); } case ValueMetaInterface.TYPE_INTEGER: Long vi = rowMeta.getInteger( data, idx ); if ( String.class.isAssignableFrom( destinationType ) ) { return converter.integer2string( vi ); } else if ( int.class.isAssignableFrom( destinationType ) ) { return converter.integer2intPrimitive( vi ); } else if ( Integer.class.isAssignableFrom( destinationType ) ) { return converter.integer2integer( vi ); } else if ( long.class.isAssignableFrom( destinationType ) ) { return converter.integer2longPrimitive( vi ); } else if ( Long.class.isAssignableFrom( destinationType ) ) { return converter.integer2long( vi ); } else if ( boolean.class.isAssignableFrom( destinationType ) ) { return converter.integer2booleanPrimitive( vi ); } else if ( Boolean.class.isAssignableFrom( destinationType ) ) { return converter.integer2boolean( vi ); } else if ( destinationType.isEnum() ) { return converter.integer2enum( destinationType, vi ); } else { throw new RuntimeException( "Wrong value conversion to " + destinationType ); } case ValueMetaInterface.TYPE_NUMBER: Double vn = rowMeta.getNumber( data, idx ); if ( String.class.isAssignableFrom( destinationType ) ) { return converter.number2string( vn ); } else if ( int.class.isAssignableFrom( destinationType ) ) { return converter.number2intPrimitive( vn ); } else if ( Integer.class.isAssignableFrom( destinationType ) ) { return converter.number2integer( vn ); } else if ( long.class.isAssignableFrom( destinationType ) ) { return converter.number2longPrimitive( vn ); } else if ( Long.class.isAssignableFrom( destinationType ) ) { return converter.number2long( vn ); } else if ( boolean.class.isAssignableFrom( destinationType ) ) { return converter.number2booleanPrimitive( vn ); } else if ( Boolean.class.isAssignableFrom( destinationType ) ) { return converter.number2boolean( vn ); } else if ( destinationType.isEnum() ) { return converter.number2enum( destinationType, vn ); } else { throw new RuntimeException( "Wrong value conversion to " + destinationType ); } } throw new KettleValueException( "Unknown conversion from " + metaType.getTypeDesc() + " into " + destinationType ); } RowMetaAndData();  RowMetaAndData( RowMetaInterface rowMeta, Object... data ); @Override RowMetaAndData clone(); @Override String toString(); Object[] getData(); void setData( Object[] data ); RowMetaInterface getRowMeta(); void setRowMeta( RowMetaInterface rowMeta ); @Override int hashCode(); @Override boolean equals( Object obj ); void addValue( ValueMetaInterface valueMeta, Object valueData ); void addValue( String valueName, int valueType, Object valueData ); void clear(); long getInteger( String valueName, long def ); long getInteger( int index, long def ); Long getInteger( String valueName ); Long getInteger( int index ); double getNumber( String valueName, double def ); double getNumber( int index, double def ); Date getDate( String valueName, Date def ); Date getDate( int index, Date def ); BigDecimal getBigNumber( String valueName, BigDecimal def ); BigDecimal getBigNumber( int index, BigDecimal def ); boolean getBoolean( String valueName, boolean def ); boolean getBoolean( int index, boolean def ); String getString( String valueName, String def ); String getString( int index, String def ); byte[] getBinary( String valueName, byte[] def ); byte[] getBinary( int index, byte[] def ); int compare( RowMetaAndData compare, int[] is, boolean[] bs ); boolean isNumeric( int index ); int size(); ValueMetaInterface getValueMeta( int index ); boolean isEmptyValue( String valueName ); static Object getStringAsJavaType( String vs, Class<?> destinationType, InjectionTypeConverter converter ); Object getAsJavaType( String valueName, Class<?> destinationType, InjectionTypeConverter converter ); void removeValue( String valueName ); void removeValue( int index ); }
RowMetaAndData implements Cloneable { public Object getAsJavaType( String valueName, Class<?> destinationType, InjectionTypeConverter converter ) throws KettleValueException { int idx = rowMeta.indexOfValue( valueName ); if ( idx < 0 ) { throw new KettleValueException( "Unknown column '" + valueName + "'" ); } ValueMetaInterface metaType = rowMeta.getValueMeta( idx ); switch ( metaType.getType() ) { case ValueMetaInterface.TYPE_STRING: String vs = rowMeta.getString( data, idx ); return getStringAsJavaType( vs, destinationType, converter ); case ValueMetaInterface.TYPE_BOOLEAN: Boolean vb = rowMeta.getBoolean( data, idx ); if ( String.class.isAssignableFrom( destinationType ) ) { return converter.boolean2string( vb ); } else if ( int.class.isAssignableFrom( destinationType ) ) { return converter.boolean2intPrimitive( vb ); } else if ( Integer.class.isAssignableFrom( destinationType ) ) { return converter.boolean2integer( vb ); } else if ( long.class.isAssignableFrom( destinationType ) ) { return converter.boolean2longPrimitive( vb ); } else if ( Long.class.isAssignableFrom( destinationType ) ) { return converter.boolean2long( vb ); } else if ( boolean.class.isAssignableFrom( destinationType ) ) { return converter.boolean2booleanPrimitive( vb ); } else if ( Boolean.class.isAssignableFrom( destinationType ) ) { return converter.boolean2boolean( vb ); } else if ( destinationType.isEnum() ) { return converter.boolean2enum( destinationType, vb ); } else { throw new RuntimeException( "Wrong value conversion to " + destinationType ); } case ValueMetaInterface.TYPE_INTEGER: Long vi = rowMeta.getInteger( data, idx ); if ( String.class.isAssignableFrom( destinationType ) ) { return converter.integer2string( vi ); } else if ( int.class.isAssignableFrom( destinationType ) ) { return converter.integer2intPrimitive( vi ); } else if ( Integer.class.isAssignableFrom( destinationType ) ) { return converter.integer2integer( vi ); } else if ( long.class.isAssignableFrom( destinationType ) ) { return converter.integer2longPrimitive( vi ); } else if ( Long.class.isAssignableFrom( destinationType ) ) { return converter.integer2long( vi ); } else if ( boolean.class.isAssignableFrom( destinationType ) ) { return converter.integer2booleanPrimitive( vi ); } else if ( Boolean.class.isAssignableFrom( destinationType ) ) { return converter.integer2boolean( vi ); } else if ( destinationType.isEnum() ) { return converter.integer2enum( destinationType, vi ); } else { throw new RuntimeException( "Wrong value conversion to " + destinationType ); } case ValueMetaInterface.TYPE_NUMBER: Double vn = rowMeta.getNumber( data, idx ); if ( String.class.isAssignableFrom( destinationType ) ) { return converter.number2string( vn ); } else if ( int.class.isAssignableFrom( destinationType ) ) { return converter.number2intPrimitive( vn ); } else if ( Integer.class.isAssignableFrom( destinationType ) ) { return converter.number2integer( vn ); } else if ( long.class.isAssignableFrom( destinationType ) ) { return converter.number2longPrimitive( vn ); } else if ( Long.class.isAssignableFrom( destinationType ) ) { return converter.number2long( vn ); } else if ( boolean.class.isAssignableFrom( destinationType ) ) { return converter.number2booleanPrimitive( vn ); } else if ( Boolean.class.isAssignableFrom( destinationType ) ) { return converter.number2boolean( vn ); } else if ( destinationType.isEnum() ) { return converter.number2enum( destinationType, vn ); } else { throw new RuntimeException( "Wrong value conversion to " + destinationType ); } } throw new KettleValueException( "Unknown conversion from " + metaType.getTypeDesc() + " into " + destinationType ); } RowMetaAndData();  RowMetaAndData( RowMetaInterface rowMeta, Object... data ); @Override RowMetaAndData clone(); @Override String toString(); Object[] getData(); void setData( Object[] data ); RowMetaInterface getRowMeta(); void setRowMeta( RowMetaInterface rowMeta ); @Override int hashCode(); @Override boolean equals( Object obj ); void addValue( ValueMetaInterface valueMeta, Object valueData ); void addValue( String valueName, int valueType, Object valueData ); void clear(); long getInteger( String valueName, long def ); long getInteger( int index, long def ); Long getInteger( String valueName ); Long getInteger( int index ); double getNumber( String valueName, double def ); double getNumber( int index, double def ); Date getDate( String valueName, Date def ); Date getDate( int index, Date def ); BigDecimal getBigNumber( String valueName, BigDecimal def ); BigDecimal getBigNumber( int index, BigDecimal def ); boolean getBoolean( String valueName, boolean def ); boolean getBoolean( int index, boolean def ); String getString( String valueName, String def ); String getString( int index, String def ); byte[] getBinary( String valueName, byte[] def ); byte[] getBinary( int index, byte[] def ); int compare( RowMetaAndData compare, int[] is, boolean[] bs ); boolean isNumeric( int index ); int size(); ValueMetaInterface getValueMeta( int index ); boolean isEmptyValue( String valueName ); static Object getStringAsJavaType( String vs, Class<?> destinationType, InjectionTypeConverter converter ); Object getAsJavaType( String valueName, Class<?> destinationType, InjectionTypeConverter converter ); void removeValue( String valueName ); void removeValue( int index );  }