Java Code Examples for org.pentaho.di.trans.TransMeta#getPrevStepFields()

The following examples show how to use org.pentaho.di.trans.TransMeta#getPrevStepFields() . 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: BaseStepDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Gets unused fields from previous steps and inserts them as rows into a table view.
 *
 * @param transMeta       the transformation metadata
 * @param stepMeta        the step metadata
 * @param tableView       the table view
 * @param keyColumn       the key column
 * @param nameColumn      the name column
 * @param dataTypeColumn  the data type column
 * @param lengthColumn    the length column
 * @param precisionColumn the precision column
 * @param listener        a listener for tables insert events
 */
public static final void getFieldsFromPrevious( TransMeta transMeta, StepMeta stepMeta, TableView tableView,
                                                int keyColumn, int[] nameColumn, int[] dataTypeColumn,
                                                int lengthColumn, int precisionColumn,
                                                TableItemInsertListener listener ) {
  try {
    RowMetaInterface row = transMeta.getPrevStepFields( stepMeta );
    if ( row != null ) {
      getFieldsFromPrevious(
        row, tableView, keyColumn, nameColumn, dataTypeColumn, lengthColumn, precisionColumn, listener );
    }
  } catch ( KettleException ke ) {
    new ErrorDialog( tableView.getShell(),
      BaseMessages.getString( PKG, "BaseStepDialog.FailedToGetFields.Title" ),
      BaseMessages.getString( PKG, "BaseStepDialog.FailedToGetFields.Message", stepMeta.getName() ), ke );
  }
}
 
Example 2
Source File: MonetDBBulkLoaderMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public SQLStatement getTableDdl( TransMeta transMeta, String stepname, boolean autoSchema,
    MonetDBBulkLoaderData data, boolean safeMode ) throws KettleException {

  String name = stepname; // new name might not yet be linked to other steps!
  StepMeta stepMeta =
      new StepMeta( BaseMessages.getString( PKG, "MonetDBBulkLoaderDialog.StepMeta.Title" ), name, this );
  RowMetaInterface prev = transMeta.getPrevStepFields( stepname );

  SQLStatement sql = getSQLStatements( transMeta, stepMeta, prev, autoSchema, data, safeMode );
  return sql;
}
 
Example 3
Source File: BaseStepXulDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Gets fields from previous steps and populate a ComboVar.
 *
 * @param comboVar
 *          the comboVar to populate
 * @param TransMeta
 *          the source transformation
 * @param StepMeta
 *          the source step
 */
public static final void getFieldsFromPrevious( ComboVar comboVar, TransMeta transMeta, StepMeta stepMeta ) {
  String selectedField = null;
  int indexField = -1;
  try {
    RowMetaInterface r = transMeta.getPrevStepFields( stepMeta );
    selectedField = comboVar.getText();
    comboVar.removeAll();

    if ( r != null && !r.isEmpty() ) {
      r.getFieldNames();
      comboVar.setItems( r.getFieldNames() );
      indexField = r.indexOfValue( selectedField );
    }
    // Select value if possible...
    if ( indexField > -1 ) {
      comboVar.select( indexField );
    } else {
      if ( selectedField != null ) {
        comboVar.setText( selectedField );
      }
    }

  } catch ( KettleException ke ) {
    new ErrorDialog( comboVar.getShell(),
      BaseMessages.getString( PKG, "BaseStepDialog.FailedToGetFieldsPrevious.DialogTitle" ),
      BaseMessages.getString( PKG, "BaseStepDialog.FailedToGetFieldsPrevious.DialogMessage" ), ke );
  }
}
 
Example 4
Source File: BaseStepDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Gets fields from previous steps and populate a ComboVar.
 *
 * @param comboVar  the Combo Box (with Variables) to populate
 * @param transMeta the transformation metadata
 * @param stepMeta  the step metadata
 */
public static final void getFieldsFromPrevious( ComboVar comboVar, TransMeta transMeta, StepMeta stepMeta ) {
  String selectedField = null;
  int indexField = -1;
  try {
    RowMetaInterface r = transMeta.getPrevStepFields( stepMeta );
    selectedField = comboVar.getText();
    comboVar.removeAll();

    if ( r != null && !r.isEmpty() ) {
      r.getFieldNames();
      comboVar.setItems( r.getFieldNames() );
      indexField = r.indexOfValue( selectedField );
    }
    // Select value if possible...
    if ( indexField > -1 ) {
      comboVar.select( indexField );
    } else {
      if ( selectedField != null ) {
        comboVar.setText( selectedField );
      }
    }
  } catch ( KettleException ke ) {
    new ErrorDialog( comboVar.getShell(),
      BaseMessages.getString( PKG, "BaseStepDialog.FailedToGetFieldsPrevious.DialogTitle" ),
      BaseMessages.getString( PKG, "BaseStepDialog.FailedToGetFieldsPrevious.DialogMessage" ), ke );
  }
}
 
Example 5
Source File: WidgetUtils.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * creates a ComboVar populated with fields from the previous step.
 * @param parentComposite - the composite in which the widget will be placed
 * @param props - PropsUI props for L&F
 * @param stepMeta - stepMeta of the current step
 * @param formData - FormData to use for placement
 */
public static ComboVar createFieldDropDown(
  Composite parentComposite, PropsUI props, BaseStepMeta stepMeta, FormData formData ) {
  TransMeta transMeta = stepMeta.getParentStepMeta().getParentTransMeta();
  ComboVar fieldDropDownCombo = new ComboVar( transMeta, parentComposite, SWT.SINGLE | SWT.LEFT | SWT.BORDER );
  props.setLook( fieldDropDownCombo );
  fieldDropDownCombo.addModifyListener( e -> stepMeta.setChanged() );

  fieldDropDownCombo.setLayoutData( formData );
  Listener focusListener = e -> {
    String current = fieldDropDownCombo.getText();
    fieldDropDownCombo.getCComboWidget().removeAll();
    fieldDropDownCombo.setText( current );

    try {
      RowMetaInterface rmi = transMeta.getPrevStepFields( stepMeta.getParentStepMeta().getName() );
      List ls = rmi.getValueMetaList();
      for ( Object l : ls ) {
        ValueMetaBase vmb = (ValueMetaBase) l;
        fieldDropDownCombo.add( vmb.getName() );
      }
    } catch ( KettleStepException ex ) {
      // can be ignored, since previous step may not be set yet.
      stepMeta.logDebug( ex.getMessage(), ex );
    }
  };
  fieldDropDownCombo.getCComboWidget().addListener( SWT.FocusIn, focusListener );
  return fieldDropDownCombo;
}
 
Example 6
Source File: TableAgileMart.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public boolean adjustSchema() {
  TableOutputMeta meta = getMeta();
  TableOutputData data = getData();
  TransMeta transMeta = getTransMeta();
  StepMeta stepMeta = meta.getParentStepMeta();
  DBCache dbcache = transMeta.getDbCache();
  StringBuilder messageBuffer = new StringBuilder();

  try {
    RowMetaInterface prev = transMeta.getPrevStepFields( stepMeta.getName() );
    if ( log.isDetailed() ) {
      logDetailed( "Attempting to auto adjust table structure" );
    }

    if ( log.isDetailed() ) {
      logDetailed( "getTransMeta: " + getTransMeta() );
    }
    if ( log.isDetailed() ) {
      logDetailed( "getStepname: " + getStepname() );
    }

    SQLStatement statement = meta.getSQLStatements( transMeta, stepMeta, prev, repository, metaStore );

    if ( log.isDetailed() ) {
      logDetailed( "Statement: " + statement );
    }
    if ( log.isDetailed() && statement != null ) {
      logDetailed( "Statement has SQL: " + statement.hasSQL() );
    }

    if ( statement != null && statement.hasSQL() ) {
      String sql = statement.getSQL();
      if ( log.isDetailed() ) {
        logDetailed( "Trying: " + sql );
      }

      try {
        log.logDetailed( "Executing SQL: " + Const.CR + sql );
        data.db.execStatement( sql );

        // Clear the database cache, in case we're using one...
        if ( dbcache != null ) {
          dbcache.clear( data.databaseMeta.getName() );
        }
      } catch ( Exception dbe ) {
        String error = BaseMessages.getString( PKG, "SQLEditor.Log.SQLExecError", sql, dbe.toString() );
        messageBuffer.append( error ).append( Const.CR );
        return false;
      }

      if ( log.isDetailed() ) {
        logDetailed( "Successfull: " + sql );
      }
    } else if ( statement.getError() == null ) {
      // there were no changes to be made
      return true;
    } else {
      this.message = statement.getError();
      logError( statement.getError() );
      return false;
    }
  } catch ( Exception e ) {
    logError( "An error ocurred trying to adjust the table schema", e );
  }
  return true;
}
 
Example 7
Source File: MonetDBBulkLoaderMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public RowMetaInterface updateFields( TransMeta transMeta, String stepname, MonetDBBulkLoaderData data ) throws KettleStepException {

    RowMetaInterface prev = transMeta.getPrevStepFields( stepname );
    return updateFields( prev, data );
  }