Java Code Examples for org.pentaho.di.core.row.ValueMetaInterface#setDateFormatLocale()

The following examples show how to use org.pentaho.di.core.row.ValueMetaInterface#setDateFormatLocale() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ValueMetaFactory.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static void cloneInfo( ValueMetaInterface source, ValueMetaInterface target ) throws KettlePluginException {
  target.setConversionMask( source.getConversionMask() );
  target.setDecimalSymbol( source.getDecimalSymbol() );
  target.setGroupingSymbol( source.getGroupingSymbol() );
  target.setStorageType( source.getStorageType() );
  if ( source.getStorageMetadata() != null ) {
    target.setStorageMetadata( cloneValueMeta( source.getStorageMetadata(), source
      .getStorageMetadata().getType() ) );
  }
  target.setStringEncoding( source.getStringEncoding() );
  target.setTrimType( source.getTrimType() );
  target.setDateFormatLenient( source.isDateFormatLenient() );
  target.setDateFormatLocale( source.getDateFormatLocale() );
  target.setDateFormatTimeZone( source.getDateFormatTimeZone() );
  target.setLenientStringToNumber( source.isLenientStringToNumber() );
  target.setLargeTextField( source.isLargeTextField() );
  target.setComments( source.getComments() );
  target.setCaseInsensitive( source.isCaseInsensitive() );
  target.setCollatorDisabled( source.isCollatorDisabled() );
  target.setCollatorStrength( source.getCollatorStrength() );
  target.setIndex( source.getIndex() );

  target.setOrigin( source.getOrigin() );

  target.setOriginalAutoIncrement( source.isOriginalAutoIncrement() );
  target.setOriginalColumnType( source.getOriginalColumnType() );
  target.setOriginalColumnTypeName( source.getOriginalColumnTypeName() );
  target.setOriginalNullable( source.isOriginalNullable() );
  target.setOriginalPrecision( source.getOriginalPrecision() );
  target.setOriginalScale( source.getOriginalScale() );
  target.setOriginalSigned( source.isOriginalSigned() );
}
 
Example 2
Source File: ValueMetaBaseSetPreparedStmntValueTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testXMLParsingWithNoDataFormatLocale() throws IOException {
  ValueMetaInterface r1 = new ValueMetaString( "value" );
  r1.setDateFormatLocale( null );
  RowMetaInterface row = new RowMeta();
  row.setValueMetaList( new ArrayList<ValueMetaInterface>( Arrays.asList( r1 ) ) );

  row.getMetaXML();
}
 
Example 3
Source File: SelectValuesMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void getMetadataFields( RowMetaInterface inputRowMeta, String name, VariableSpace space ) throws KettlePluginException {
  if ( meta != null && meta.length > 0 ) {
    // METADATA mode: change the meta-data of the values mentioned...

    for ( int i = 0; i < meta.length; i++ ) {
      SelectMetadataChange metaChange = meta[i];

      int idx = inputRowMeta.indexOfValue( metaChange.getName() );
      boolean metaTypeChangeUsesNewTypeDefaults = false; // Normal behavior as of 5.x or so
      if ( space != null ) {
        metaTypeChangeUsesNewTypeDefaults = ValueMetaBase.convertStringToBoolean(
            space.getVariable( Const.KETTLE_COMPATIBILITY_SELECT_VALUES_TYPE_CHANGE_USES_TYPE_DEFAULTS, "N" ) );
      }
      if ( idx >= 0 ) { // We found the value

        // This is the value we need to change:
        ValueMetaInterface v = inputRowMeta.getValueMeta( idx );

        // Do we need to rename ?
        if ( !v.getName().equals( metaChange.getRename() ) && !Utils.isEmpty( metaChange.getRename() ) ) {
          v.setName( metaChange.getRename() );
          v.setOrigin( name );
          // need to reinsert to check name conflicts
          inputRowMeta.setValueMeta( idx, v );
        }
        // Change the type?
        if ( metaChange.getType() != ValueMetaInterface.TYPE_NONE && v.getType() != metaChange.getType() ) {
          // Fix for PDI-16388 - clone copies over the conversion mask instead of using the default for the new type
          if ( !metaTypeChangeUsesNewTypeDefaults ) {
            v = ValueMetaFactory.cloneValueMeta( v, metaChange.getType() );
          } else {
            v = ValueMetaFactory.createValueMeta( v.getName(), metaChange.getType() );
          }

          // This is now a copy, replace it in the row!
          //
          inputRowMeta.setValueMeta( idx, v );

          // This also moves the data to normal storage type
          //
          v.setStorageType( ValueMetaInterface.STORAGE_TYPE_NORMAL );
        }
        if ( metaChange.getLength() != UNDEFINED ) {
          v.setLength( metaChange.getLength() );
          v.setOrigin( name );
        }
        if ( metaChange.getPrecision() != UNDEFINED ) {
          v.setPrecision( metaChange.getPrecision() );
          v.setOrigin( name );
        }
        if ( metaChange.getStorageType() >= 0 ) {
          v.setStorageType( metaChange.getStorageType() );
          v.setOrigin( name );
        }
        if ( !Utils.isEmpty( metaChange.getConversionMask() ) ) {
          v.setConversionMask( metaChange.getConversionMask() );
          v.setOrigin( name );
        }

        v.setDateFormatLenient( metaChange.isDateFormatLenient() );
        v.setDateFormatLocale( EnvUtil.createLocale( metaChange.getDateFormatLocale() ) );
        v.setDateFormatTimeZone( EnvUtil.createTimeZone( metaChange.getDateFormatTimeZone() ) );
        v.setLenientStringToNumber( metaChange.isLenientStringToNumber() );

        if ( !Utils.isEmpty( metaChange.getEncoding() ) ) {
          v.setStringEncoding( metaChange.getEncoding() );
          v.setOrigin( name );
        }
        if ( !Utils.isEmpty( metaChange.getDecimalSymbol() ) ) {
          v.setDecimalSymbol( metaChange.getDecimalSymbol() );
          v.setOrigin( name );
        }
        if ( !Utils.isEmpty( metaChange.getGroupingSymbol() ) ) {
          v.setGroupingSymbol( metaChange.getGroupingSymbol() );
          v.setOrigin( name );
        }
        if ( !Utils.isEmpty( metaChange.getCurrencySymbol() ) ) {
          v.setCurrencySymbol( metaChange.getCurrencySymbol() );
          v.setOrigin( name );
        }
      }
    }
  }
}
 
Example 4
Source File: SelectValues.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Change the meta-data of certain fields.
 * <p/>
 * This, we can do VERY fast.
 * <p/>
 *
 * @param row The row to manipulate
 * @return the altered RowData array
 * @throws KettleValueException
 */
@VisibleForTesting
synchronized Object[] metadataValues( RowMetaInterface rowMeta, Object[] rowData ) throws KettleException {
  if ( data.firstmetadata ) {
    data.firstmetadata = false;

    data.metanrs = new int[ meta.getMeta().length ];
    for ( int i = 0; i < data.metanrs.length; i++ ) {
      data.metanrs[ i ] = rowMeta.indexOfValue( meta.getMeta()[ i ].getName() );
      if ( data.metanrs[ i ] < 0 ) {
        logError( BaseMessages
          .getString( PKG, "SelectValues.Log.CouldNotFindField", meta.getMeta()[ i ].getName() ) );
        setErrors( 1 );
        stopAll();
        return null;
      }
    }

    // Check for doubles in the selected fields...
    int[] cnt = new int[ meta.getMeta().length ];
    for ( int i = 0; i < meta.getMeta().length; i++ ) {
      cnt[ i ] = 0;
      for ( int j = 0; j < meta.getMeta().length; j++ ) {
        if ( meta.getMeta()[ i ].getName().equals( meta.getMeta()[ j ].getName() ) ) {
          cnt[ i ]++;
        }

        if ( cnt[ i ] > 1 ) {
          logError( BaseMessages.getString( PKG, "SelectValues.Log.FieldCouldNotSpecifiedMoreThanTwice2", meta
            .getMeta()[ i ].getName() ) );
          setErrors( 1 );
          stopAll();
          return null;
        }
      }
    }

    // Also apply the metadata on the row meta to allow us to convert the data correctly, with the correct mask.
    //
    for ( int i = 0; i < data.metanrs.length; i++ ) {
      SelectMetadataChange change = meta.getMeta()[ i ];
      ValueMetaInterface valueMeta = rowMeta.getValueMeta( data.metanrs[ i ] );
      if ( !Utils.isEmpty( change.getConversionMask() ) ) {
        valueMeta.setConversionMask( change.getConversionMask() );
      }

      valueMeta.setDateFormatLenient( change.isDateFormatLenient() );
      valueMeta.setDateFormatLocale( EnvUtil.createLocale( change.getDateFormatLocale() ) );
      valueMeta.setDateFormatTimeZone( EnvUtil.createTimeZone( change.getDateFormatTimeZone() ) );
      valueMeta.setLenientStringToNumber( change.isLenientStringToNumber() );

      if ( !Utils.isEmpty( change.getEncoding() ) ) {
        valueMeta.setStringEncoding( change.getEncoding() );
      }
      if ( !Utils.isEmpty( change.getDecimalSymbol() ) ) {
        valueMeta.setDecimalSymbol( change.getDecimalSymbol() );
      }
      if ( !Utils.isEmpty( change.getGroupingSymbol() ) ) {
        valueMeta.setGroupingSymbol( change.getGroupingSymbol() );
      }
      if ( !Utils.isEmpty( change.getCurrencySymbol() ) ) {
        valueMeta.setCurrencySymbol( change.getCurrencySymbol() );
      }
    }
  }

  //
  // Change the data too
  //
  for ( int i = 0; i < data.metanrs.length; i++ ) {
    int index = data.metanrs[ i ];
    ValueMetaInterface fromMeta = rowMeta.getValueMeta( index );
    ValueMetaInterface toMeta = data.metadataRowMeta.getValueMeta( index );

    // If we need to change from BINARY_STRING storage type to NORMAL...
    //
    try {
      if ( fromMeta.isStorageBinaryString()
        && meta.getMeta()[ i ].getStorageType() == ValueMetaInterface.STORAGE_TYPE_NORMAL ) {
        rowData[ index ] = fromMeta.convertBinaryStringToNativeType( (byte[]) rowData[ index ] );
      }
      if ( meta.getMeta()[ i ].getType() != ValueMetaInterface.TYPE_NONE && fromMeta.getType() != toMeta.getType() ) {
        rowData[ index ] = toMeta.convertData( fromMeta, rowData[ index ] );
      }
    } catch ( KettleValueException e ) {
      throw new KettleConversionException( e.getMessage(), Collections.<Exception>singletonList( e ),
        Collections.singletonList( toMeta ), rowData );
    }
  }

  return rowData;
}