Java Code Examples for org.pentaho.di.core.Result#setNrLinesRead()

The following examples show how to use org.pentaho.di.core.Result#setNrLinesRead() . 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: Trans.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Gets the result of the transformation. The Result object contains such measures as the number of errors, number of
 * lines read/written/input/output/updated/rejected, etc.
 *
 * @return the Result object containing resulting measures from execution of the transformation
 */
public Result getResult() {
  if ( steps == null ) {
    return null;
  }

  Result result = new Result();
  result.setNrErrors( errors.longValue() );
  result.setResult( errors.longValue() == 0 );
  TransLogTable transLogTable = transMeta.getTransLogTable();

  for ( int i = 0; i < steps.size(); i++ ) {
    StepMetaDataCombi sid = steps.get( i );
    StepInterface step = sid.step;

    result.setNrErrors( result.getNrErrors() + sid.step.getErrors() );
    result.getResultFiles().putAll( step.getResultFiles() );

    if ( step.isSafeStopped() ) {
      result.setSafeStop( step.isSafeStopped() );
    }

    if ( step.getStepname().equals( transLogTable.getSubjectString( TransLogTable.ID.LINES_READ ) ) ) {
      result.setNrLinesRead( result.getNrLinesRead() + step.getLinesRead() );
    }
    if ( step.getStepname().equals( transLogTable.getSubjectString( TransLogTable.ID.LINES_INPUT ) ) ) {
      result.setNrLinesInput( result.getNrLinesInput() + step.getLinesInput() );
    }
    if ( step.getStepname().equals( transLogTable.getSubjectString( TransLogTable.ID.LINES_WRITTEN ) ) ) {
      result.setNrLinesWritten( result.getNrLinesWritten() + step.getLinesWritten() );
    }
    if ( step.getStepname().equals( transLogTable.getSubjectString( TransLogTable.ID.LINES_OUTPUT ) ) ) {
      result.setNrLinesOutput( result.getNrLinesOutput() + step.getLinesOutput() );
    }
    if ( step.getStepname().equals( transLogTable.getSubjectString( TransLogTable.ID.LINES_UPDATED ) ) ) {
      result.setNrLinesUpdated( result.getNrLinesUpdated() + step.getLinesUpdated() );
    }
    if ( step.getStepname().equals( transLogTable.getSubjectString( TransLogTable.ID.LINES_REJECTED ) ) ) {
      result.setNrLinesRejected( result.getNrLinesRejected() + step.getLinesRejected() );
    }
  }

  result.setRows( resultRows );
  if ( !Utils.isEmpty( resultFiles ) ) {
    result.setResultFiles( new HashMap<String, ResultFile>() );
    for ( ResultFile resultFile : resultFiles ) {
      result.getResultFiles().put( resultFile.toString(), resultFile );
    }
  }
  result.setStopped( isStopped() );
  result.setLogChannelId( log.getLogChannelId() );

  return result;
}
 
Example 2
Source File: Database.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Execute a series of SQL statements, separated by ;
 * <p/>
 * We are already connected...
 * <p/>
 * Multiple statements have to be split into parts We use the ";" to separate statements...
 * <p/>
 * We keep the results in Result object from Jobs
 *
 * @param script The SQL script to be execute
 * @param params Parameters Meta
 * @param data   Parameters value
 * @return A result with counts of the number or records updates, inserted, deleted or read.
 * @throws KettleDatabaseException In case an error occurs
 */
public Result execStatements( String script, RowMetaInterface params, Object[] data ) throws KettleDatabaseException {
  Result result = new Result();

  SqlScriptParser sqlScriptParser = databaseMeta.getDatabaseInterface().createSqlScriptParser();
  List<String> statements = sqlScriptParser.split( script );
  int nrstats = 0;

  if ( statements != null ) {
    for ( String stat : statements ) {
      // Deleting all the single-line and multi-line comments from the string
      stat = sqlScriptParser.removeComments( stat );

      if ( !Const.onlySpaces( stat ) ) {
        String sql = Const.trim( stat );
        if ( sql.toUpperCase().startsWith( "SELECT" ) ) {
          // A Query
          if ( log.isDetailed() ) {
            log.logDetailed( "launch SELECT statement: " + Const.CR + sql );
          }

          nrstats++;
          ResultSet rs = null;
          try {
            rs = openQuery( sql, params, data );
            if ( rs != null ) {
              Object[] row = getRow( rs );
              while ( row != null ) {
                result.setNrLinesRead( result.getNrLinesRead() + 1 );
                if ( log.isDetailed() ) {
                  log.logDetailed( rowMeta.getString( row ) );
                }
                row = getRow( rs );
              }

            } else {
              if ( log.isDebug() ) {
                log.logDebug( "Error executing query: " + Const.CR + sql );
              }
            }
          } catch ( KettleValueException e ) {
            throw new KettleDatabaseException( e ); // just pass the error
            // upwards.
          } finally {
            try {
              if ( rs != null ) {
                rs.close();
              }
            } catch ( SQLException ex ) {
              if ( log.isDebug() ) {
                log.logDebug( "Error closing query: " + Const.CR + sql );
              }
            }
          }
        } else {
          // any kind of statement
          if ( log.isDetailed() ) {
            log.logDetailed( "launch DDL statement: " + Const.CR + sql );
          }

          // A DDL statement
          nrstats++;
          Result res = execStatement( sql, params, data );
          result.add( res );
        }
      }
    }
  }

  if ( log.isDetailed() ) {
    log.logDetailed( nrstats + " statement" + ( nrstats == 1 ? "" : "s" ) + " executed" );
  }

  return result;
}