Object data ) throws KettleDatabaseException { try { switch ( getType() ) { case ValueMetaInterface.TYPE_NUMBER: if ( !isNull( data ) ) { double num = getNumber( data ).doubleValue(); if ( databaseMeta.supportsFloatRoundingOnUpdate() && getPrecision() >= 0 ) { num = Const.round( num, getPrecision() ); if ( !isNull( data ) ) { if ( databaseMeta.supportsSetLong() ) { preparedStatement.setLong( index, getInteger( data ).longValue() ); } else { double d = getNumber( data ).doubleValue(); if ( databaseMeta.supportsFloatRoundingOnUpdate() && getPrecision() >= 0 ) { preparedStatement.setDouble( index, d ); } else { preparedStatement.setDouble( index, Const.round( d, getPrecision() ) ); if ( !isNull( data ) ) { if ( getLength() == DatabaseMeta.CLOB_LENGTH ) { setLength( databaseMeta.getMaxTextFieldLength() ); if ( getLength() <= databaseMeta.getMaxTextFieldLength() ) { preparedStatement.setString( index, getString( data ) ); } else { String string = getString( data ); log.logMinimal( String.format( "Truncating %d symbols of original message in '%s' field", begin, getName() ) );
private boolean isNullValueAllowed( int valueMetaType ) { //Check if retro compatibility is set or not, to guaranty compatibility with older versions. //In 6.1 null values were written with string "null". Since then the attribute is not written. String val = getVariable( Const.KETTLE_COMPATIBILITY_XML_OUTPUT_NULL_VALUES, "N" ); return ValueMetaBase.convertStringToBoolean( Const.NVL( val, "N" ) ) && valueMetaType == ValueMetaInterface.TYPE_STRING; }
StringBuilder retval = new StringBuilder( getTypeDesc() ); switch ( getType() ) { case TYPE_STRING: if ( getLength() > 0 ) { retval.append( '(' ).append( getLength() ).append( ')' ); if ( getLength() > 0 ) { retval.append( '(' ).append( getLength() ); if ( getPrecision() > 0 ) { retval.append( ", " ).append( getPrecision() ); if ( getLength() > 0 ) { retval.append( '(' ).append( getLength() ).append( ')' ); if ( !isStorageNormal() ) { retval.append( "<" ).append( getStorageTypeDesc() ).append( ">" );
protected void setDefaultConversionMask() { // Set some sensible default mask on the numbers // switch ( getType() ) { case TYPE_INTEGER: setConversionMask( DEFAULT_INTEGER_FORMAT_MASK ); break; case TYPE_NUMBER: setConversionMask( DEFAULT_NUMBER_FORMAT_MASK ); break; case TYPE_BIGNUMBER: setConversionMask( DEFAULT_BIG_NUMBER_FORMAT_MASK ); setGroupingSymbol( null ); setDecimalSymbol( "." ); // For backward compatibility reasons! break; default: // does nothing } }
switch ( getType() ) { case TYPE_STRING: return readString( inputStream ); case TYPE_NUMBER: return readNumber( inputStream ); case TYPE_INTEGER: return readInteger( inputStream ); case TYPE_DATE: return readDate( inputStream ); case TYPE_BIGNUMBER: return readBigNumber( inputStream ); case TYPE_BOOLEAN: return readBoolean( inputStream ); case TYPE_BINARY: return readBinary( inputStream ); case TYPE_INET: return InetAddress.getByAddress( readBinary( inputStream ) ); default: throw new KettleFileException( toString() + " : Unable to de-serialize data of type " + getType() ); return readBinaryString( inputStream ); return readSmallInteger( inputStream ); // just an index: 4-bytes should throw new KettleFileException( toString() + " : Unknown storage type " + getStorageType() ); throw e; } catch ( IOException e ) { throw new KettleFileException( toString() + " : Unable to read value data from input stream", e );
xml.append( XMLHandler.addTagValue( "type", getTypeDesc() ) ); xml.append( XMLHandler.addTagValue( "storagetype", getStorageTypeCode( getStorageType() ) ) ); break; default: throw new IOException( toString() + " : Unable to serialize index storage type to XML for data type " + getType() ); throw new RuntimeException( toString() + " : There was a data type error: the data type of " + index[i].getClass().getName() + " object [" + index[i] + "] does not correspond to value meta [" + toStringMeta() + "]" ); xml.append( XMLHandler.addTagValue( "grouping_symbol", groupingSymbol ) ); xml.append( XMLHandler.addTagValue( "currency_symbol", currencySymbol ) ); xml.append( XMLHandler.addTagValue( "trim_type", getTrimTypeCode( trimType ) ) ); xml.append( XMLHandler.addTagValue( "case_insensitive", caseInsensitive ) ); xml.append( XMLHandler.addTagValue( "collator_disabled", collatorDisabled ) );
switch ( getType() ) { case TYPE_STRING: writeString( outputStream, (String) object ); break; case TYPE_NUMBER: writeNumber( outputStream, (Double) object ); break; case TYPE_INTEGER: writeInteger( outputStream, (Long) object ); break; case TYPE_DATE: writeDate( outputStream, (Date) object ); break; case TYPE_BIGNUMBER: writeBigNumber( outputStream, (BigDecimal) object ); break; case TYPE_BOOLEAN: writeBoolean( outputStream, (Boolean) object ); break; case TYPE_BINARY: writeBinary( outputStream, (byte[]) object ); break; case TYPE_INET: writeBinary( outputStream, ( (InetAddress) object ).getAddress() ); break; default: throw new KettleFileException( toString() + " : Unable to serialize data type " + getType() ); writeBinaryString( outputStream, (byte[]) object );
switch ( type ) { case TYPE_STRING: index[i] = readString( inputStream ); break; case TYPE_NUMBER: index[i] = readNumber( inputStream ); break; case TYPE_INTEGER: index[i] = readInteger( inputStream ); break; case TYPE_DATE: index[i] = readDate( inputStream ); break; case TYPE_BIGNUMBER: index[i] = readBigNumber( inputStream ); break; case TYPE_BOOLEAN: index[i] = readBoolean( inputStream ); break; case TYPE_BINARY: index[i] = readBinary( inputStream ); break; default: throw new KettleFileException( toString() + " : Unable to de-serialize indexed storage type for data type " + getType() ); storageMetadata = new ValueMetaBase( inputStream ); name = readString( inputStream );
@Override public int string2intPrimitive( String v ) throws KettleValueException { return ValueMetaBase.getType( v ); } }
@Override public void writeMeta( DataOutputStream outputStream ) throws KettleFileException { try { int type = getType(); switch ( type ) { case TYPE_STRING: writeString( outputStream, (String) index[i] ); break; case TYPE_NUMBER: writeNumber( outputStream, (Double) index[i] ); break; case TYPE_INTEGER: writeInteger( outputStream, (Long) index[i] ); break; case TYPE_DATE: writeDate( outputStream, (Date) index[i] ); break; case TYPE_BIGNUMBER: writeBigNumber( outputStream, (BigDecimal) index[i] ); break; case TYPE_BOOLEAN: writeBoolean( outputStream, (Boolean) index[i] ); break; case TYPE_BINARY: writeBinary( outputStream, (byte[]) index[i] ); break; default: throw new KettleFileException( toString() + " : Unable to serialize indexe storage type for data type " + getType() );
/** * Return the type of a value in a textual form: "String", "Number", "Integer", "Boolean", "Date", ... * * @return A String describing the type of value. */ @Override public String getTypeDesc() { return getTypeDesc( type ); }
public ValueMetaBase( Node node ) throws KettleException { this(); type = getType( XMLHandler.getTagValue( node, "type" ) ); storageType = getStorageType( XMLHandler.getTagValue( node, "storagetype" ) ); break; default: throw new KettleException( toString() + " : Unable to de-serialize index storage type from XML for data type " + getType() ); Node storageValueMetaNode = XMLHandler.getSubNode( storageMetaNode, XML_META_TAG ); if ( storageValueMetaNode != null ) { storageMetadata = new ValueMetaBase( storageValueMetaNode ); groupingSymbol = XMLHandler.getTagValue( node, "grouping_symbol" ); currencySymbol = XMLHandler.getTagValue( node, "currency_symbol" ); trimType = getTrimTypeByCode( XMLHandler.getTagValue( node, "trim_type" ) ); caseInsensitive = "Y".equalsIgnoreCase( XMLHandler.getTagValue( node, "case_insensitive" ) ); collatorDisabled = "Y".equalsIgnoreCase( XMLHandler.getTagValue( node, "collator_disabled" ) );
if ( isNull( data ) ) { value.setNull(); } else { switch ( value.getType() ) { case TYPE_STRING: value.setValue( getString( data ) ); break; case TYPE_NUMBER: value.setValue( getNumber( data ).doubleValue() ); break; case TYPE_INTEGER: value.setValue( getInteger( data ).longValue() ); break; case TYPE_DATE: value.setValue( getDate( data ) ); break; case TYPE_BOOLEAN: value.setValue( getBoolean( data ).booleanValue() ); break; case TYPE_BIGNUMBER: value.setValue( getBigNumber( data ) ); break; case TYPE_BINARY: value.setValue( getBinary( data ) ); break; default: throw new KettleValueException( toString() + " : We can't convert data type " + getTypeDesc() + " to an original (V2) Value" );
private int typeCompare( Object data1, Object data2 ) throws KettleValueException { int cmp = 0; switch ( getType() ) { case TYPE_STRING: String one = getString( data1 ); String two = getString( data2 ); cmp = getInteger( data1 ).compareTo( getInteger( data2 ) ); break; cmp = Double.compare( getNumber( data1 ).doubleValue(), getNumber( data2 ).doubleValue() ); break; cmp = Long.valueOf( getDate( data1 ).getTime() ).compareTo( Long.valueOf( getDate( data2 ).getTime() ) ); break; cmp = getBigNumber( data1 ).compareTo( getBigNumber( data2 ) ); break; if ( getBoolean( data1 ).booleanValue() == getBoolean( data2 ).booleanValue() ) { cmp = 0; // true == true, false == false } else if ( getBoolean( data1 ).booleanValue() && !getBoolean( data2 ).booleanValue() ) { cmp = 1; // true > false } else { throw new KettleValueException( toString() + " : Comparing values can not be done with data type : " + getType() );
int hash = 0; if ( isNull( object ) ) { switch ( getType() ) { case TYPE_BOOLEAN: hash ^= 1; switch ( getType() ) { case TYPE_BOOLEAN: hash ^= getBoolean( object ).hashCode(); break; case TYPE_DATE: hash ^= getDate( object ).hashCode(); break; case TYPE_INTEGER: hash ^= getInteger( object ).hashCode(); break; case TYPE_NUMBER: hash ^= getNumber( object ).hashCode(); break; case TYPE_STRING: hash ^= getString( object ).hashCode(); break; case TYPE_BIGNUMBER: hash ^= getBigNumber( object ).hashCode(); break; case TYPE_BINARY:
int outValueType = getType(); Object emptyValue = isStringValue ? Const.NULL_STRING : null; Boolean isEmptyAndNullDiffer = convertStringToBoolean( Const.NVL( System.getProperty( Const.KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL, "N" ), "N" ) ); return convertData( convertMeta, pol );
public int compare( Object data1, ValueMetaInterface meta2, Object data2 ) throws KettleValueException { if ( meta2 == null ) { throw new KettleValueException( toStringMeta() + " : Second meta data (meta2) is null, please check one of the previous steps." ); if ( getType() == meta2.getType() ) { if ( getStorageType() == meta2.getStorageType() ) { return compare( data1, data2 ); switch ( getStorageType() ) { case STORAGE_TYPE_NORMAL: return compare( data1, meta2.convertToNormalStorageType( data2 ) ); case STORAGE_TYPE_BINARY_STRING: if ( storageMetadata != null && storageMetadata.getConversionMask() != null && !meta2.isNumber() ) { return compare( data1, meta2StorageMask.convertToBinaryStringStorageType( data2 ) ); } else { return compare( data1, meta2.convertToBinaryStringStorageType( data2 ) ); return compare( data1, data2 ); // not accessible, just to make sure. case STORAGE_TYPE_NORMAL: return -meta2.compare( data2, convertToNormalStorageType( data1 ) ); case STORAGE_TYPE_BINARY_STRING: return -meta2.compare( data2, convertToBinaryStringStorageType( data1 ) ); default: throw new KettleValueException( meta2.toStringMeta() + " : Unknown storage type : " throw new KettleValueException( toStringMeta() + " : Unknown storage type : " + getStorageType() );
return (Boolean) object; case STORAGE_TYPE_BINARY_STRING: return (Boolean) convertBinaryStringToNativeType( (byte[]) object ); case STORAGE_TYPE_INDEXED: return (Boolean) index[( (Integer) object ).intValue()]; default: throw new KettleValueException( toString() + " : Unknown storage type " + storageType + " specified." ); return convertStringToBoolean( trim( (String) object ) ); case STORAGE_TYPE_BINARY_STRING: return convertStringToBoolean( trim( (String) convertBinaryStringToNativeType( (byte[]) object ) ) ); case STORAGE_TYPE_INDEXED: return convertStringToBoolean( trim( (String) index[( (Integer) object ).intValue()] ) ); default: throw new KettleValueException( toString() + " : Unknown storage type " + storageType + " specified." ); return convertIntegerToBoolean( (Long) object ); case STORAGE_TYPE_BINARY_STRING: return convertIntegerToBoolean( (Long) convertBinaryStringToNativeType( (byte[]) object ) ); case STORAGE_TYPE_INDEXED: return convertIntegerToBoolean( (Long) index[( (Integer) object ).intValue()] ); default: throw new KettleValueException( toString() + " : Unknown storage type " + storageType + " specified." ); return convertNumberToBoolean( (Double) object ); case STORAGE_TYPE_BINARY_STRING: return convertNumberToBoolean( (Double) convertBinaryStringToNativeType( (byte[]) object ) ); case STORAGE_TYPE_INDEXED: return convertNumberToBoolean( (Double) index[( (Integer) object ).intValue()] );