public Value last_day() throws KettleValueException { if ( getType() == VALUE_TYPE_DATE ) { Calendar cal = Calendar.getInstance(); cal.setTime( getDate() ); int last_day = cal.getActualMaximum( Calendar.DAY_OF_MONTH ); cal.set( Calendar.DAY_OF_MONTH, last_day ); setValue( cal.getTime() ); } else { throw new KettleValueException( "Function last_day only works on a date" ); } return this; }
switch ( getType() ) { case VALUE_TYPE_STRING: if ( getLength() > 0 ) {
public Value first_day() throws KettleValueException { if ( getType() == VALUE_TYPE_DATE ) { Calendar cal = Calendar.getInstance(); cal.setTime( getDate() ); cal.set( Calendar.DAY_OF_MONTH, 1 ); setValue( cal.getTime() ); } else { throw new KettleValueException( "Function first_day only works on a date" ); } return this; }
public Value add_months( int months ) throws KettleValueException { if ( getType() == VALUE_TYPE_DATE ) { if ( !isNull() && getDate() != null ) { Calendar cal = Calendar.getInstance(); cal.setTime( getDate() ); int year = cal.get( Calendar.YEAR ); int month = cal.get( Calendar.MONTH ); int day = cal.get( Calendar.DAY_OF_MONTH ); month += months; int newyear = year + (int) Math.floor( month / 12 ); int newmonth = month % 12; cal.set( newyear, newmonth, 1 ); int newday = cal.getActualMaximum( Calendar.DAY_OF_MONTH ); if ( newday < day ) { cal.set( Calendar.DAY_OF_MONTH, newday ); } else { cal.set( Calendar.DAY_OF_MONTH, day ); } setValue( cal.getTime() ); } } else { throw new KettleValueException( "Function add_months only works on a date!" ); } return this; }
/** * Add a number of days to a Date value. * * @param days * The number of days to add to the current date value * @return The resulting value * @throws KettleValueException */ public Value add_days( long days ) throws KettleValueException { if ( getType() == VALUE_TYPE_DATE ) { if ( !isNull() && getDate() != null ) { Calendar cal = Calendar.getInstance(); cal.setTime( getDate() ); cal.add( Calendar.DAY_OF_YEAR, (int) days ); setValue( cal.getTime() ); } } else { throw new KettleValueException( "Function add_days only works on a date!" ); } return this; }
public Value length() throws KettleValueException { if ( isNull() ) { setType( VALUE_TYPE_INTEGER ); setValue( 0L ); return this; } if ( getType() == VALUE_TYPE_STRING ) { setValue( (double) getString().length() ); } else { throw new KettleValueException( "Function LENGTH only works with a string" ); } return this; }
public Value lpad( int len, String padstr ) { if ( isNull() ) { setType( VALUE_TYPE_STRING ); } else { if ( getType() != VALUE_TYPE_STRING ) { // also lpad other types! setValue( getString() ); } if ( getString() != null ) { StringBuilder result = new StringBuilder( getString() ); int pad = len; int l = ( pad - result.length() ) / padstr.length() + 1; int i; for ( i = 0; i < l; i++ ) { result.insert( 0, padstr ); } // Maybe we added one or two too many! i = result.length(); while ( i > pad && pad > 0 ) { result.deleteCharAt( 0 ); i--; } setValue( result.toString() ); } else { setNull(); } } setLength( len ); return this; }
public Value rpad( int len, String padstr ) { if ( isNull() ) { setType( VALUE_TYPE_STRING ); } else { if ( getType() != VALUE_TYPE_STRING ) { // also rpad other types! setValue( getString() ); } if ( getString() != null ) { StringBuilder result = new StringBuilder( getString() ); int pad = len; int l = ( pad - result.length() ) / padstr.length() + 1; int i; for ( i = 0; i < l; i++ ) { result.append( padstr ); } // Maybe we added one or two too many! i = result.length(); while ( i > pad && pad > 0 ) { result.deleteCharAt( i - 1 ); i--; } setValue( result.toString() ); } else { setNull(); } } setLength( len ); return this; }
public Value dat2str( String arg0, String arg1 ) throws KettleValueException { if ( isNull() ) { setType( VALUE_TYPE_STRING ); } else { if ( getType() == VALUE_TYPE_DATE ) { SimpleDateFormat df = new SimpleDateFormat(); DateFormatSymbols dfs = new DateFormatSymbols(); if ( arg1 != null ) { dfs.setLocalPatternChars( arg1 ); } if ( arg0 != null ) { df.applyPattern( arg0 ); } try { setValue( df.format( getDate() ) ); } catch ( Exception e ) { setType( VALUE_TYPE_STRING ); setNull(); throw new KettleValueException( "TO_CHAR Couldn't convert Date to String " + e.toString() ); } } else { throw new KettleValueException( "Function DAT2STR only works on a date" ); } } return this; }
/** * Returns whether "types" of the values are exactly the same: type, name, length, precision. * * @param v * Value to compare type against. * * @return == true when types are the same == false when the types differ */ public boolean equalValueType( Value v, boolean checkTypeOnly ) { if ( v == null ) { return false; } if ( getType() != v.getType() ) { return false; } if ( !checkTypeOnly ) { if ( ( getName() == null && v.getName() != null ) || ( getName() != null && v.getName() == null ) || !( getName().equals( v.getName() ) ) ) { return false; } if ( getLength() != v.getLength() ) { return false; } if ( getPrecision() != v.getPrecision() ) { return false; } } return true; }
public Value rtrim() { if ( isNull() ) { setType( VALUE_TYPE_STRING ); } else { String s; if ( getType() == VALUE_TYPE_STRING ) { s = Const.rtrim( getString() ); } else { s = Const.rtrim( toString() ); } setValue( s ); } return this; }
public Value minus( Value v ) throws KettleValueException { switch ( getType() ) { case VALUE_TYPE_BIGNUMBER: value.setBigNumber( getBigNumber().subtract( v.getBigNumber() ) ); break; case VALUE_TYPE_NUMBER: value.setNumber( getNumber() - v.getNumber() ); break; case VALUE_TYPE_INTEGER: value.setInteger( getInteger() - v.getInteger() ); break; case VALUE_TYPE_BOOLEAN: case VALUE_TYPE_STRING: default: throw new KettleValueException( "Subtraction can only be done with numbers!" ); } return this; }
public Value v_if( Value[] args ) throws KettleValueException { if ( getType() == VALUE_TYPE_BOOLEAN ) { if ( args.length == 1 ) { if ( getBoolean() ) { setValue( args[0] ); } else { setNull(); } } else if ( args.length == 2 ) { if ( getBoolean() ) { setValue( args[0] ); } else { setValue( args[1] ); } } } else { throw new KettleValueException( "Function DECODE can't have " + args.length + " arguments!" ); } return this; }
public Value dat2num() throws KettleValueException { if ( isNull() ) { setType( VALUE_TYPE_INTEGER ); return this; } if ( getType() == VALUE_TYPE_DATE ) { if ( getString() == null ) { setNull(); setValue( 0L ); } else { setValue( getInteger() ); } } else { throw new KettleValueException( "Function DAT2NUM works only on dates" ); } return this; }
public Value ltrim() { if ( isNull() ) { setType( VALUE_TYPE_STRING ); } else { if ( getString() != null ) { String s; if ( getType() == VALUE_TYPE_STRING ) { s = Const.ltrim( getString() ); } else { s = Const.ltrim( toString() ); } setValue( s ); } else { setNull(); } } return this; }
String retval; switch ( getType() ) { case VALUE_TYPE_STRING: retval = toStringString( pad );
public Value divide( Value v ) throws KettleValueException { if ( isNull() || v.isNull() ) { setNull(); } else { switch ( getType() ) { case VALUE_TYPE_BIGNUMBER: setValue( getBigNumber().divide( v.getBigNumber(), BigDecimal.ROUND_HALF_UP ) ); break; case VALUE_TYPE_NUMBER: setValue( getNumber() / v.getNumber() ); break; case VALUE_TYPE_INTEGER: setValue( getInteger() / v.getInteger() ); break; case VALUE_TYPE_BOOLEAN: case VALUE_TYPE_STRING: default: throw new KettleValueException( "Division can only be done with numeric data!" ); } } return this; }
public Value plus( Value v ) { switch ( getType() ) { case VALUE_TYPE_BIGNUMBER: setValue( getBigNumber().add( v.getBigNumber() ) ); break; case VALUE_TYPE_NUMBER: setValue( getNumber() + v.getNumber() ); break; case VALUE_TYPE_INTEGER: setValue( getInteger() + v.getInteger() ); break; case VALUE_TYPE_BOOLEAN: setValue( getBoolean() | v.getBoolean() ); break; case VALUE_TYPE_STRING: setValue( getString() + v.getString() ); break; default: break; } return this; }
try { String valname = XMLHandler.getTagValue( valnode, "name" ); int valtype = getType( XMLHandler.getTagValue( valnode, "type" ) ); String text = XMLHandler.getTagValue( valnode, "text" ); boolean isnull = "Y".equalsIgnoreCase( XMLHandler.getTagValue( valnode, "isnull" ) );