Java Code Examples for org.pentaho.di.core.RowMetaAndData#getInteger()

The following examples show how to use org.pentaho.di.core.RowMetaAndData#getInteger() . 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: KettleDatabaseRepository.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public synchronized void insertStepDatabase( ObjectId id_transformation, ObjectId id_step, ObjectId id_database ) throws KettleException {
  // First check if the relationship is already there.
  // There is no need to store it twice!
  RowMetaAndData check = getStepDatabase( id_step );
  if ( check.getInteger( 0 ) == null ) {
    RowMetaAndData table = new RowMetaAndData();

    table.addValue(
      new ValueMetaInteger(
        KettleDatabaseRepository.FIELD_STEP_DATABASE_ID_TRANSFORMATION ),
      id_transformation );
    table.addValue( new ValueMetaInteger(
      KettleDatabaseRepository.FIELD_STEP_DATABASE_ID_STEP ), id_step );
    table
      .addValue(
        new ValueMetaInteger(
          KettleDatabaseRepository.FIELD_STEP_DATABASE_ID_DATABASE ),
        id_database );

    connectionDelegate.insertTableRow( KettleDatabaseRepository.TABLE_R_STEP_DATABASE, table );
  }
}
 
Example 2
Source File: KettleDatabaseRepositoryJobEntryDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public void loadJobEntryBase( JobEntryBase jobEntryBase, ObjectId id_jobentry, List<DatabaseMeta> databases,
  List<SlaveServer> slaveServers ) throws KettleException {
  try {
    RowMetaAndData r = getJobEntry( id_jobentry );
    if ( r != null ) {
      jobEntryBase.setName( r.getString( "NAME", null ) );

      jobEntryBase.setDescription( r.getString( "DESCRIPTION", null ) );
      long id_jobentry_type = r.getInteger( "ID_JOBENTRY_TYPE", 0 );
      RowMetaAndData jetrow = getJobEntryType( new LongObjectId( id_jobentry_type ) );
      if ( jetrow != null ) {
        jobEntryBase.setPluginId( jetrow.getString( "CODE", null ) );
      }
    }
  } catch ( KettleDatabaseException dbe ) {
    throw new KettleException( "Unable to load base job entry information from the repository for id_jobentry="
      + id_jobentry, dbe );
  }
}
 
Example 3
Source File: KettleDatabaseRepositoryTransDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public TransDependency loadTransDependency( ObjectId id_dependency, List<DatabaseMeta> databases ) throws KettleException {
  TransDependency transDependency = new TransDependency();

  try {
    transDependency.setObjectId( id_dependency );

    RowMetaAndData r = getTransDependency( id_dependency );

    if ( r != null ) {
      long id_connection = r.getInteger( "ID_DATABASE", 0 );
      transDependency.setDatabase( DatabaseMeta.findDatabase( databases, new LongObjectId( id_connection ) ) );
      transDependency.setTablename( r.getString( "TABLE_NAME", null ) );
      transDependency.setFieldname( r.getString( "FIELD_NAME", null ) );
    }

    return transDependency;
  } catch ( KettleException dbe ) {
    throw new KettleException( BaseMessages.getString(
      PKG, "TransDependency.Exception.UnableToLoadTransformationDependency" )
      + id_dependency, dbe );
  }
}
 
Example 4
Source File: KettleDatabaseRepositoryMetaStoreDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private KDBRMetaStoreAttribute parseAttribute( ObjectId elementId, RowMetaAndData attributeRow ) throws KettleException {
  try {
    Long attributeId =
      attributeRow.getInteger( KettleDatabaseRepository.FIELD_ELEMENT_ATTRIBUTE_ID_ELEMENT_ATTRIBUTE );
    String key = attributeRow.getString( KettleDatabaseRepository.FIELD_ELEMENT_ATTRIBUTE_KEY, null );
    String value = attributeRow.getString( KettleDatabaseRepository.FIELD_ELEMENT_ATTRIBUTE_VALUE, null );

    Object object = parseAttributeValue( value );

    KDBRMetaStoreAttribute attribute = new KDBRMetaStoreAttribute( this, key, object );
    attribute.setObjectId( new LongObjectId( attributeId ) );
    return attribute;
  } catch ( Exception e ) {
    throw new KettleException( "Unable to parse attribute from attribute row: " + attributeRow.toString(), e );
  }

}
 
Example 5
Source File: KettleDatabaseRepositoryDatabaseDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public synchronized int getNrDatabases( ObjectId id_transformation ) throws KettleException {
  int retval = 0;

  RowMetaAndData transIdRow = repository.connectionDelegate.getParameterMetaData( id_transformation );
  String sql =
    "SELECT COUNT(*) FROM "
      + quoteTable( KettleDatabaseRepository.TABLE_R_STEP_DATABASE ) + " WHERE "
      + quote( KettleDatabaseRepository.FIELD_STEP_DATABASE_ID_TRANSFORMATION ) + " = ? ";
  RowMetaAndData r =
    repository.connectionDelegate.getOneRow( sql, transIdRow.getRowMeta(), transIdRow.getData() );
  if ( r != null ) {
    retval = (int) r.getInteger( 0, 0L );
  }

  return retval;
}
 
Example 6
Source File: KettleDatabaseRepositoryConnectionDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public synchronized void updateTableRow( String tablename, String idfield, RowMetaAndData values )
  throws KettleException {
  long id = values.getInteger( idfield, 0L );
  values.removeValue( idfield );
  String[] sets = new String[ values.size() ];
  for ( int i = 0; i < values.size(); i++ ) {
    sets[ i ] = values.getValueMeta( i ).getName();
  }
  String[] codes = new String[] { idfield };
  String[] condition = new String[] { "=" };

  database.prepareUpdate( tablename, codes, condition, sets );

  values.addValue( new ValueMetaInteger( idfield ), new Long( id ) );

  database.setValuesUpdate( values.getRowMeta(), values.getData() );
  database.updateRow();
}
 
Example 7
Source File: KettleDatabaseRepositoryConnectionDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private synchronized LongObjectId getNextTableID( String tablename, String idfield ) throws KettleException {
  LongObjectId retval = null;


  RowMetaAndData r = callRead( () -> database.getOneRow( "SELECT MAX(" + idfield + ") FROM " + tablename ) );
  if ( r != null ) {
    Long id = r.getInteger( 0 );

    if ( id == null ) {
      if ( log.isDebug() ) {
        log.logDebug( "no max(" + idfield + ") found in table " + tablename );
      }
      retval = new LongObjectId( 1 );
    } else {
      if ( log.isDebug() ) {
        log.logDebug( "max(" + idfield + ") found in table " + tablename + " --> " + idfield + " number: " + id );
      }
      retval = new LongObjectId( id.longValue() + 1L );
    }
  }
  return retval;
}
 
Example 8
Source File: KettleDatabaseRepositoryDatabaseDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public synchronized int getNrDatabases() throws KettleException {
  int retval = 0;

  String sql = "SELECT COUNT(*) FROM " + quoteTable( KettleDatabaseRepository.TABLE_R_DATABASE );
  RowMetaAndData r = repository.connectionDelegate.getOneRow( sql );
  if ( r != null ) {
    retval = (int) r.getInteger( 0, 0L );
  }

  return retval;
}
 
Example 9
Source File: KettleDatabaseRepositoryStepDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public synchronized int getNrStepAttributes( ObjectId id_step ) throws KettleException {
  int retval = 0;

  RowMetaAndData par = repository.connectionDelegate.getParameterMetaData( id_step );
  String sql =
    "SELECT COUNT(*) FROM "
      + quoteTable( KettleDatabaseRepository.TABLE_R_STEP_ATTRIBUTE ) + " WHERE "
      + quote( KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_ID_STEP ) + " = ? ";
  RowMetaAndData r = repository.connectionDelegate.getOneRow( sql, par.getRowMeta(), par.getData() );
  if ( r != null ) {
    retval = (int) r.getInteger( 0, 0L );
  }

  return retval;
}
 
Example 10
Source File: KettleDatabaseRepositoryMetaStoreDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public Collection<RowMetaAndData> getNamespaces() throws KettleDatabaseException, KettleValueException {
  List<RowMetaAndData> attrs = new ArrayList<RowMetaAndData>();

  String sql = "SELECT * FROM " + quoteTable( KettleDatabaseRepository.TABLE_R_NAMESPACE );

  List<Object[]> rows = repository.connectionDelegate.getRows( sql, 0 );
  for ( Object[] row : rows ) {
    RowMetaAndData rowWithMeta = new RowMetaAndData( repository.connectionDelegate.getReturnRowMeta(), row );
    long id = rowWithMeta.getInteger( quote( KettleDatabaseRepository.FIELD_NAMESPACE_ID_NAMESPACE ), 0 );
    if ( id > 0 ) {
      attrs.add( rowWithMeta );
    }
  }
  return attrs;
}
 
Example 11
Source File: KettleDatabaseRepositoryTransDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public synchronized int getNrTransDependencies( ObjectId id_transformation ) throws KettleException {
  int retval = 0;

  RowMetaAndData par = repository.connectionDelegate.getParameterMetaData( id_transformation );
  String sql =
    "SELECT COUNT(*) FROM "
      + quoteTable( KettleDatabaseRepository.TABLE_R_DEPENDENCY ) + " WHERE "
      + quote( KettleDatabaseRepository.FIELD_DEPENDENCY_ID_TRANSFORMATION ) + " = ? ";
  RowMetaAndData r = repository.connectionDelegate.getOneRow( sql, par.getRowMeta(), par.getData() );
  if ( r != null ) {
    retval = (int) r.getInteger( 0, 0L );
  }

  return retval;
}
 
Example 12
Source File: KettleDatabaseRepositoryStepDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public synchronized int getNrSteps( ObjectId id_transformation ) throws KettleException {
  int retval = 0;

  RowMetaAndData par = repository.connectionDelegate.getParameterMetaData( id_transformation );
  String sql =
    "SELECT COUNT(*) FROM "
      + quoteTable( KettleDatabaseRepository.TABLE_R_STEP ) + " WHERE "
      + quote( KettleDatabaseRepository.FIELD_STEP_ID_TRANSFORMATION ) + " = ? ";
  RowMetaAndData r = repository.connectionDelegate.getOneRow( sql, par.getRowMeta(), par.getData() );
  if ( r != null ) {
    retval = (int) r.getInteger( 0, 0L );
  }

  return retval;
}
 
Example 13
Source File: KettleDatabaseRepository.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public synchronized ObjectId getRootDirectoryID() throws KettleException {
  RowMetaAndData result =
    connectionDelegate.getOneRow( "SELECT "
      + quote( KettleDatabaseRepository.FIELD_DIRECTORY_ID_DIRECTORY ) + " FROM "
      + quoteTable( KettleDatabaseRepository.TABLE_R_DIRECTORY ) + " WHERE "
      + quote( KettleDatabaseRepository.FIELD_DIRECTORY_ID_DIRECTORY_PARENT ) + " = 0" );
  if ( result != null && result.isNumeric( 0 ) ) {
    return new LongObjectId( result.getInteger( 0, -1 ) );
  }
  return null;
}
 
Example 14
Source File: KettleDatabaseRepositoryMetaStoreDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public KDBRMetaStoreElementType parseElementType( String namespace, ObjectId namespaceId,
  RowMetaAndData elementTypeRow ) throws KettleValueException {

  Long id = elementTypeRow.getInteger( KettleDatabaseRepository.FIELD_ELEMENT_TYPE_ID_ELEMENT_TYPE );
  String name = elementTypeRow.getString( KettleDatabaseRepository.FIELD_ELEMENT_TYPE_NAME, null );
  String description = elementTypeRow.getString( KettleDatabaseRepository.FIELD_ELEMENT_TYPE_DESCRIPTION, null );

  KDBRMetaStoreElementType type = new KDBRMetaStoreElementType( this, namespace, namespaceId, name, description );
  type.setId( new LongObjectId( id ) );

  return type;
}
 
Example 15
Source File: MetaInject.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * package-local visibility for testing purposes
 */
static void setEntryValue( StepInjectionMetaEntry entry, RowMetaAndData row, SourceStepField source )
  throws KettleValueException {
  // A standard attribute, a single row of data...
  //
  Object value = null;
  switch ( entry.getValueType() ) {
    case ValueMetaInterface.TYPE_STRING:
      value = row.getString( source.getField(), null );
      break;
    case ValueMetaInterface.TYPE_BOOLEAN:
      value = row.getBoolean( source.getField(), false );
      break;
    case ValueMetaInterface.TYPE_INTEGER:
      value = row.getInteger( source.getField(), 0L );
      break;
    case ValueMetaInterface.TYPE_NUMBER:
      value = row.getNumber( source.getField(), 0.0D );
      break;
    case ValueMetaInterface.TYPE_DATE:
      value = row.getDate( source.getField(), null );
      break;
    case ValueMetaInterface.TYPE_BIGNUMBER:
      value = row.getBigNumber( source.getField(), null );
      break;
    default:
      break;
  }
  entry.setValue( value );
}
 
Example 16
Source File: KettleDatabaseRepositoryJobDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public JobHopMeta loadJobHopMeta( ObjectId id_job_hop, List<JobEntryCopy> jobcopies ) throws KettleException {
  JobHopMeta jobHopMeta = new JobHopMeta();
  try {
    RowMetaAndData r = getJobHop( id_job_hop );
    if ( r != null ) {
      long id_jobentry_copy_from = r.getInteger( "ID_JOBENTRY_COPY_FROM", -1L );
      long id_jobentry_copy_to = r.getInteger( "ID_JOBENTRY_COPY_TO", -1L );

      jobHopMeta.setEnabled( r.getBoolean( "ENABLED", true ) );
      jobHopMeta.setEvaluation( r.getBoolean( "EVALUATION", true ) );
      jobHopMeta.setConditional();
      if ( r.getBoolean( "UNCONDITIONAL", !jobHopMeta.getEvaluation() ) ) {
        jobHopMeta.setUnconditional();
      }

      jobHopMeta.setFromEntry( JobMeta.findJobEntryCopy( jobcopies, new LongObjectId( id_jobentry_copy_from ) ) );
      jobHopMeta.setToEntry( JobMeta.findJobEntryCopy( jobcopies, new LongObjectId( id_jobentry_copy_to ) ) );

      return jobHopMeta;
    } else {
      throw new KettleException( "Unable to find job hop with ID : " + id_job_hop );
    }
  } catch ( KettleDatabaseException dbe ) {
    throw new KettleException( BaseMessages.getString( PKG, "JobHopMeta.Exception.UnableToLoadHopInfoRep", ""
      + id_job_hop ), dbe );

  }
}
 
Example 17
Source File: KettleDatabaseRepositoryConnectionDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public synchronized long getTransAttributeInteger( ObjectId id_transformation, int nr, String code )
  throws KettleException {
  RowMetaAndData r = null;
  r = getTransAttributeRow( id_transformation, nr, code );
  if ( r == null ) {
    return 0L;
  }
  return r.getInteger( KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_VALUE_NUM, 0L );
}
 
Example 18
Source File: KettleDatabaseRepositoryNotePadDelegate.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public NotePadMeta loadNotePadMeta( ObjectId id_note ) throws KettleException {
  NotePadMeta note = new NotePadMeta();
  try {
    note.setObjectId( id_note );

    RowMetaAndData r = getNote( id_note );
    if ( r != null ) {
      note.setNote( r.getString( "VALUE_STR", "" ) );
      int x = (int) r.getInteger( "GUI_LOCATION_X", 0L );
      int y = (int) r.getInteger( "GUI_LOCATION_Y", 0L );
      note.setLocation( new Point( x, y ) );
      note.setWidth( (int) r.getInteger( "GUI_LOCATION_WIDTH", 0L ) );
      note.setHeight( (int) r.getInteger( "GUI_LOCATION_HEIGHT", 0L ) );
      note.setSelected( false );

      // Font
      note.setFontName( r.getString( "FONT_NAME", null ) );
      note.setFontSize( (int) r.getInteger( "FONT_SIZE", -1 ) );
      note.setFontBold( r.getBoolean( "FONT_BOLD", false ) );
      note.setFontItalic( r.getBoolean( "FONT_ITALIC", false ) );

      // Font color
      note.setFontColorRed( (int) r.getInteger( "FONT_COLOR_RED", NotePadMeta.COLOR_RGB_BLACK_BLUE ) );
      note.setFontColorGreen( (int) r.getInteger( "FONT_COLOR_GREEN", NotePadMeta.COLOR_RGB_BLACK_GREEN ) );
      note.setFontColorBlue( (int) r.getInteger( "FONT_COLOR_BLUE", NotePadMeta.COLOR_RGB_BLACK_BLUE ) );

      // Background color
      note.setBackGroundColorRed( (int) r.getInteger(
        "FONT_BACK_GROUND_COLOR_RED", NotePadMeta.COLOR_RGB_DEFAULT_BG_RED ) );
      note.setBackGroundColorGreen( (int) r.getInteger(
        "FONT_BACK_GROUND_COLOR_GREEN", NotePadMeta.COLOR_RGB_DEFAULT_BG_GREEN ) );
      note.setBackGroundColorBlue( (int) r.getInteger(
        "FONT_BACK_GROUND_COLOR_BLUE", NotePadMeta.COLOR_RGB_DEFAULT_BG_BLUE ) );

      // Border color
      note.setBorderColorRed( (int) r.getInteger(
        "FONT_BORDER_COLOR_RED", NotePadMeta.COLOR_RGB_DEFAULT_BORDER_RED ) );
      note.setBorderColorGreen( (int) r.getInteger(
        "FONT_BORDER_COLOR_GREEN", NotePadMeta.COLOR_RGB_DEFAULT_BORDER_GREEN ) );
      note.setBorderColorBlue( (int) r.getInteger(
        "FONT_BORDER_COLOR_BLUE", NotePadMeta.COLOR_RGB_DEFAULT_BORDER_BLUE ) );
      note.setDrawShadow( r.getBoolean( "DRAW_SHADOW", true ) );

      // Done!
      return note;
    } else {
      note.setObjectId( null );
      throw new KettleException( "I couldn't find Notepad with id_note=" + id_note + " in the repository." );
    }
  } catch ( KettleDatabaseException dbe ) {
    note.setObjectId( null );
    throw new KettleException( "Unable to load Notepad from repository (id_note=" + id_note + ")", dbe );
  }
}
 
Example 19
Source File: KettleDatabaseRepositoryConditionDelegate.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 *
 * Read a condition from the repository.
 *
 * @param id_condition
 *          The condition id
 * @throws KettleException
 *           if something goes wrong.
 */
public Condition loadCondition( ObjectId id_condition ) throws KettleException {
  Condition condition = new Condition();

  try {
    RowMetaAndData r = getCondition( id_condition );
    if ( r != null ) {
      condition.setNegated( r.getBoolean( "NEGATED", false ) );
      condition.setOperator( Condition.getOperator( r.getString( "OPERATOR", null ) ) );

      long conditionId = r.getInteger( "ID_CONDITION", -1L );
      if ( conditionId > 0 ) {
        condition.setObjectId( new LongObjectId( conditionId ) );
      } else {
        condition.setObjectId( null );
      }

      ObjectId[] subids = repository.getSubConditionIDs( condition.getObjectId() );
      if ( subids.length == 0 ) {
        condition.setLeftValuename( r.getString( "LEFT_NAME", null ) );
        condition.setFunction( Condition.getFunction( r.getString( "CONDITION_FUNCTION", null ) ) );
        condition.setRightValuename( r.getString( "RIGHT_NAME", null ) );

        long id_value = r.getInteger( "ID_VALUE_RIGHT", -1L );
        if ( id_value > 0 ) {
          ValueMetaAndData v = repository.loadValueMetaAndData( new LongObjectId( id_value ) );
          condition.setRightExact( v );
        }
      } else {
        for ( int i = 0; i < subids.length; i++ ) {
          condition.addCondition( loadCondition( subids[i] ) );
        }
      }

      return condition;
    } else {
      throw new KettleException( "Condition with id_condition="
        + id_condition + " could not be found in the repository" );
    }
  } catch ( KettleException dbe ) {
    throw new KettleException(
      "Error loading condition from the repository (id_condition=" + id_condition + ")", dbe );
  }
}
 
Example 20
Source File: KettleFileTableModel.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public static String getLastExecutionResult( LogChannelInterface log, LoggingObjectInterface parentObject,
  ReportSubjectLocation filename ) throws KettleException {

  LogTableInterface logTable = null;
  if ( filename.isTransformation() ) {
    TransMeta transMeta = TransformationInformation.getInstance().getTransMeta( filename );
    logTable = transMeta.getTransLogTable();
  } else {
    JobMeta jobMeta = JobInformation.getInstance().getJobMeta( filename );
    logTable = jobMeta.getJobLogTable();
  }
  if ( logTable != null && logTable.isDefined() ) {
    DatabaseMeta dbMeta = logTable.getDatabaseMeta();
    Database database = new Database( parentObject, dbMeta );
    try {
      database.connect();
      String sql = "SELECT ";
      sql += dbMeta.quoteField( logTable.getStatusField().getFieldName() ) + ", ";
      sql += dbMeta.quoteField( logTable.getLogDateField().getFieldName() ) + ", ";
      sql += dbMeta.quoteField( logTable.getErrorsField().getFieldName() ) + "";
      sql += " FROM ";
      sql += dbMeta.getQuotedSchemaTableCombination( logTable.getSchemaName(), logTable.getTableName() );
      sql += " ORDER BY " + dbMeta.quoteField( logTable.getLogDateField().getFieldName() ) + " DESC";

      RowMetaAndData oneRow = database.getOneRow( sql );
      String status = oneRow.getString( 0, "?" );
      Date date = oneRow.getDate( 1, null );
      Long nrErrors = oneRow.getInteger( 2 );

      String evaluation;
      if ( status.equalsIgnoreCase( LogStatus.END.getStatus() ) ) {
        evaluation = "Ended";
      } else if ( status.equalsIgnoreCase( LogStatus.START.getStatus() ) ) {
        evaluation = "Started";
      } else if ( status.equalsIgnoreCase( LogStatus.STOP.getStatus() ) ) {
        evaluation = "Stopped";
      } else if ( status.equalsIgnoreCase( LogStatus.RUNNING.getStatus() ) ) {
        evaluation = "Running";
      } else if ( status.equalsIgnoreCase( LogStatus.PAUSED.getStatus() ) ) {
        evaluation = "Paused";
      } else if ( status.equalsIgnoreCase( LogStatus.ERROR.getStatus() ) ) {
        evaluation = "Failed";
      } else {
        evaluation = "Unknown";
      }
      if ( nrErrors > 0 ) {
        evaluation += " with errors";
      } else {
        evaluation += " with success";
      }

      return evaluation + " at " + XMLHandler.date2string( date );

    } catch ( Exception e ) {
      log.logBasic( "Unable to get logging information from log table" + logTable );
    } finally {
      database.disconnect();
    }
  }
  return null;
}