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

The following examples show how to use org.pentaho.di.core.RowMetaAndData#addValue() . 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: KettleDatabaseRepositoryConnectionDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public synchronized List<Object[]> getJobAttributesWithPrefix( ObjectId jobId, String codePrefix )
  throws KettleException {
  String sql =
    "SELECT *"
      + " FROM "
      + databaseMeta.getQuotedSchemaTableCombination( null, KettleDatabaseRepository.TABLE_R_JOB_ATTRIBUTE )
      + " WHERE " + quote( KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_ID_JOB ) + " = ?" + " AND "
      + quote( KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_CODE ) + " LIKE '" + codePrefix + "%'";

  RowMetaAndData table = new RowMetaAndData();
  table.addValue(
    new ValueMetaInteger( KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_ID_JOB ),
    new LongObjectId( jobId ) );

  return callRead(
    () -> database.getRows( sql, table.getRowMeta(), table.getData(), ResultSet.FETCH_FORWARD, false, 0, null ) );
}
 
Example 2
Source File: KettleDatabaseRepository.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public synchronized ObjectId insertTransformationCluster( ObjectId id_transformation, ObjectId id_cluster ) throws KettleException {
  ObjectId id = connectionDelegate.getNextTransformationClusterID();

  RowMetaAndData table = new RowMetaAndData();

  table.addValue( new ValueMetaInteger(
    KettleDatabaseRepository.FIELD_TRANS_CLUSTER_ID_TRANS_CLUSTER ), id );
  table.addValue(
    new ValueMetaInteger(
      KettleDatabaseRepository.FIELD_TRANS_CLUSTER_ID_TRANSFORMATION ),
    id_transformation );
  table.addValue( new ValueMetaInteger(
    KettleDatabaseRepository.FIELD_TRANS_CLUSTER_ID_CLUSTER ), id_cluster );

  connectionDelegate.insertTableRow( KettleDatabaseRepository.TABLE_R_TRANS_CLUSTER, table );

  return id;
}
 
Example 3
Source File: KettleDatabaseRepositoryConnectionDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public synchronized List<Object[]> getJobAttributes( ObjectId id_job, String code, long nr ) throws KettleException {
  String sql =
    "SELECT *"
      + " FROM "
      + databaseMeta.getQuotedSchemaTableCombination( null, KettleDatabaseRepository.TABLE_R_JOB_ATTRIBUTE )
      + " WHERE " + quote( KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_ID_JOB ) + " = ? AND "
      + quote( KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_CODE ) + " = ? AND "
      + quote( KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_NR ) + " = ?" + " ORDER BY "
      + quote( KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_VALUE_NUM );

  RowMetaAndData table = new RowMetaAndData();
  table.addValue( new ValueMetaInteger(
    KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_ID_JOB ), id_job );
  table.addValue( new ValueMetaString(
    KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_CODE ), code );
  table.addValue( new ValueMetaInteger(
    KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_NR ), new Long( nr ) );

  return callRead(
    () -> database.getRows( sql, table.getRowMeta(), table.getData(), ResultSet.FETCH_FORWARD, false, 0, null ) );
}
 
Example 4
Source File: KettleDatabaseRepositoryConnectionDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public synchronized List<Object[]> getJobEntryAttributesWithPrefix( ObjectId jobId, ObjectId jobEntryId,
                                                                    String codePrefix ) throws KettleException {
  String sql =
    "SELECT *"
      + " FROM "
      + databaseMeta.getQuotedSchemaTableCombination(
      null, KettleDatabaseRepository.TABLE_R_JOBENTRY_ATTRIBUTE ) + " WHERE "
      + quote( KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_ID_JOB ) + " = ?" + " AND "
      + quote( KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_ID_JOBENTRY ) + " = ?" + " AND "
      + quote( KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_CODE ) + " LIKE '" + codePrefix + "%'";

  RowMetaAndData table = new RowMetaAndData();
  table
    .addValue(
      new ValueMetaInteger(
        KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_ID_JOB ),
      new LongObjectId( jobId ) );
  table.addValue(
    new ValueMetaInteger(
      KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_ID_JOBENTRY ),
    new LongObjectId( jobEntryId ) );

  return callRead(
    () -> database.getRows( sql, table.getRowMeta(), table.getData(), ResultSet.FETCH_FORWARD, false, 0, null ) );
}
 
Example 5
Source File: KettleDatabaseRepositoryConnectionDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public synchronized ObjectId getIDWithValue( String tablename, String idfield, String[] lookupkey, ObjectId[] key )
  throws KettleException {
  RowMetaAndData par = new RowMetaAndData();
  String sql = "SELECT " + idfield + " FROM " + tablename + " ";

  for ( int i = 0; i < lookupkey.length; i++ ) {
    if ( i == 0 ) {
      sql += "WHERE ";
    } else {
      sql += "AND   ";
    }
    par.addValue( new ValueMetaInteger( lookupkey[ i ] ), new LongObjectId( key[ i ] ) );
    sql += lookupkey[ i ] + " = ? ";
  }
  RowMetaAndData result = getOneRow( sql, par.getRowMeta(), par.getData() );
  if ( result != null && result.getRowMeta() != null && result.getData() != null && result.isNumeric( 0 ) ) {
    return new LongObjectId( result.getInteger( 0, 0 ) );
  }
  return null;
}
 
Example 6
Source File: KettleDatabaseRepositoryConnectionDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public synchronized int countNrJobAttributes( ObjectId id_job, String code ) throws KettleException {
  String sql =
    "SELECT COUNT(*) FROM "
      + databaseMeta.getQuotedSchemaTableCombination( null, KettleDatabaseRepository.TABLE_R_JOB_ATTRIBUTE )
      + " WHERE " + quote( KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_ID_JOB ) + " = ? AND "
      + quote( KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_CODE ) + " = ?";
  RowMetaAndData table = new RowMetaAndData();
  table.addValue( new ValueMetaInteger(
    KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_ID_JOB ), id_job );
  table.addValue( new ValueMetaString(
    KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_CODE ), code );
  RowMetaAndData r = callRead( () -> database.getOneRow( sql, table.getRowMeta(), table.getData() ) );
  if ( r == null || r.getData() == null ) {
    return 0;
  }

  return (int) r.getInteger( 0, 0L );
}
 
Example 7
Source File: KettleDatabaseRepository.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public synchronized ObjectId insertLogEntry( String description ) throws KettleException {
  ObjectId id = connectionDelegate.getNextLogID();

  RowMetaAndData table = new RowMetaAndData();
  table.addValue( new ValueMetaInteger(
    KettleDatabaseRepository.FIELD_REPOSITORY_LOG_ID_REPOSITORY_LOG ), id );
  table.addValue( new ValueMetaString(
    KettleDatabaseRepository.FIELD_REPOSITORY_LOG_REP_VERSION ), getVersion() );
  table.addValue( new ValueMetaDate(
    KettleDatabaseRepository.FIELD_REPOSITORY_LOG_LOG_DATE ), new Date() );
  table.addValue(
    new ValueMetaString( KettleDatabaseRepository.FIELD_REPOSITORY_LOG_LOG_USER ),
    getUserInfo() != null ? getUserInfo().getLogin() : "admin" );
  table.addValue(
    new ValueMetaString(
      KettleDatabaseRepository.FIELD_REPOSITORY_LOG_OPERATION_DESC ),
    description );

  connectionDelegate.insertTableRow( KettleDatabaseRepository.TABLE_R_REPOSITORY_LOG, table );

  return id;
}
 
Example 8
Source File: KettleDatabaseRepositoryDirectoryDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private synchronized ObjectId insertDirectory( ObjectId id_directory_parent, RepositoryDirectoryInterface dir ) throws KettleException {
  ObjectId id = repository.connectionDelegate.getNextDirectoryID();

  String tablename = KettleDatabaseRepository.TABLE_R_DIRECTORY;
  RowMetaAndData table = new RowMetaAndData();
  table.addValue( new ValueMetaInteger(
    KettleDatabaseRepository.FIELD_DIRECTORY_ID_DIRECTORY ), id );
  table.addValue(
    new ValueMetaInteger(
      KettleDatabaseRepository.FIELD_DIRECTORY_ID_DIRECTORY_PARENT ),
    id_directory_parent );
  table.addValue( new ValueMetaString(
    KettleDatabaseRepository.FIELD_DIRECTORY_DIRECTORY_NAME ), dir.getName() );

  repository.connectionDelegate.getDatabase().prepareInsert( table.getRowMeta(), tablename );
  repository.connectionDelegate.getDatabase().setValuesInsert( table );
  repository.connectionDelegate.getDatabase().insertRow();
  repository.connectionDelegate.getDatabase().closeInsert();

  return id;
}
 
Example 9
Source File: KettleDatabaseRepositoryConnectionDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public RowMetaAndData getTransAttributeRow( ObjectId id_transformation, int nr, String code ) throws KettleException {
  RowMetaAndData par = new RowMetaAndData();
  par.addValue(
    new ValueMetaInteger(
      KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_ID_TRANSFORMATION ),
    id_transformation );
  par.addValue( new ValueMetaString(
    KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_CODE ), code );
  par.addValue( new ValueMetaInteger(
    KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_NR ), new Long( nr ) );

  if ( psTransAttributesLookup == null ) {
    setLookupTransAttribute();
  }
  database.setValues( par, psTransAttributesLookup );
  return callRead( new Callable<RowMetaAndData>() {
    @Override public RowMetaAndData call() throws Exception {
      Object[] r = database.getLookup( psTransAttributesLookup );
      if ( r == null ) {
        return null;
      }
      return new RowMetaAndData( database.getReturnRowMeta(), r );
    }
  } );
}
 
Example 10
Source File: KettleDatabaseRepositoryClusterSchemaDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public synchronized void updateCluster( ClusterSchema clusterSchema ) throws KettleException {
  RowMetaAndData table = new RowMetaAndData();

  table.addValue( new ValueMetaInteger(
    KettleDatabaseRepository.FIELD_CLUSTER_ID_CLUSTER ), clusterSchema
    .getObjectId() );
  table.addValue(
    new ValueMetaString( KettleDatabaseRepository.FIELD_CLUSTER_NAME ),
    clusterSchema.getName() );
  table.addValue( new ValueMetaString(
    KettleDatabaseRepository.FIELD_CLUSTER_BASE_PORT ), clusterSchema
    .getBasePort() );
  table
    .addValue(
      new ValueMetaString(
        KettleDatabaseRepository.FIELD_CLUSTER_SOCKETS_BUFFER_SIZE ),
      clusterSchema.getSocketsBufferSize() );
  table.addValue(
    new ValueMetaString(
      KettleDatabaseRepository.FIELD_CLUSTER_SOCKETS_FLUSH_INTERVAL ),
    clusterSchema.getSocketsFlushInterval() );
  table.addValue( new ValueMetaBoolean(
    KettleDatabaseRepository.FIELD_CLUSTER_SOCKETS_COMPRESSED ), Boolean
    .valueOf( clusterSchema.isSocketsCompressed() ) );
  table.addValue(
    new ValueMetaBoolean( KettleDatabaseRepository.FIELD_CLUSTER_DYNAMIC ), Boolean
      .valueOf( clusterSchema.isDynamic() ) );

  repository.connectionDelegate.updateTableRow(
    KettleDatabaseRepository.TABLE_R_CLUSTER, KettleDatabaseRepository.FIELD_CLUSTER_ID_CLUSTER, table,
    clusterSchema.getObjectId() );
}
 
Example 11
Source File: XMLInputFieldsImportProgressDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void setAttributeField( Attribute attribute, IProgressMonitor monitor ) {
  // Get Attribute Name
  String attributname = attribute.getName();
  String attributnametxt = cleanString( attribute.getPath() );
  if ( !Utils.isEmpty( attributnametxt ) && !list.contains( attribute.getPath() ) ) {
    nr++;
    monitor.subTask( BaseMessages.getString( PKG, "GetXMLDataXMLInputFieldsImportProgressDialog.Task.FetchFields",
        String.valueOf( nr ) ) );
    monitor.subTask( BaseMessages.getString( PKG, "GetXMLDataXMLInputFieldsImportProgressDialog.Task.AddingField",
        attributname ) );

    RowMetaAndData row = new RowMetaAndData();
    row.addValue( VALUE_NAME, Value.VALUE_TYPE_STRING, attributname );
    row.addValue( VALUE_PATH, Value.VALUE_TYPE_STRING, attributnametxt );
    row.addValue( VALUE_ELEMENT, Value.VALUE_TYPE_STRING, GetXMLDataField.ElementTypeDesc[1] );
    row.addValue( VALUE_RESULT, Value.VALUE_TYPE_STRING, GetXMLDataField.ResultTypeDesc[0] );

    // Get attribute value
    String valueAttr = attribute.getText();

    // Try to get the Type

    if ( IsDate( valueAttr ) ) {
      row.addValue( VALUE_TYPE, Value.VALUE_TYPE_STRING, "Date" );
      row.addValue( VALUE_FORMAT, Value.VALUE_TYPE_STRING, "yyyy/MM/dd" );
    } else if ( IsInteger( valueAttr ) ) {
      row.addValue( VALUE_TYPE, Value.VALUE_TYPE_STRING, "Integer" );
      row.addValue( VALUE_FORMAT, Value.VALUE_TYPE_STRING, null );
    } else if ( IsNumber( valueAttr ) ) {
      row.addValue( VALUE_TYPE, Value.VALUE_TYPE_STRING, "Number" );
      row.addValue( VALUE_FORMAT, Value.VALUE_TYPE_STRING, null );
    } else {
      row.addValue( VALUE_TYPE, Value.VALUE_TYPE_STRING, "String" );
      row.addValue( VALUE_FORMAT, Value.VALUE_TYPE_STRING, null );
    }
    list.add( attribute.getPath() );
  } // end if

}
 
Example 12
Source File: KettleDatabaseRepositoryMetaStoreDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public ObjectId insertElementType( KDBRMetaStoreElementType type ) throws KettleException {
  ObjectId idType =
    repository.connectionDelegate.getNextID(
      quoteTable( KettleDatabaseRepository.TABLE_R_ELEMENT_TYPE ),
      quote( KettleDatabaseRepository.FIELD_ELEMENT_TYPE_ID_ELEMENT_TYPE ) );
  RowMetaAndData table = new RowMetaAndData();

  table.addValue( new ValueMetaInteger(
    KettleDatabaseRepository.FIELD_ELEMENT_TYPE_ID_ELEMENT_TYPE ), idType );
  table.addValue( new ValueMetaInteger(
    KettleDatabaseRepository.FIELD_ELEMENT_TYPE_ID_NAMESPACE ), type
    .getNamespaceId() );
  table.addValue( new ValueMetaString(
    KettleDatabaseRepository.FIELD_ELEMENT_TYPE_NAME ), type.getName() );
  table.addValue( new ValueMetaString(
    KettleDatabaseRepository.FIELD_ELEMENT_TYPE_DESCRIPTION ), type
    .getDescription() );

  repository.connectionDelegate.getDatabase().prepareInsert(
    table.getRowMeta(), KettleDatabaseRepository.TABLE_R_ELEMENT_TYPE );
  repository.connectionDelegate.getDatabase().setValuesInsert( table );
  repository.connectionDelegate.getDatabase().insertRow();
  repository.connectionDelegate.getDatabase().closeInsert();

  type.setId( new LongObjectId( idType ) );

  if ( log.isDebug() ) {
    log.logDebug( "Saved element type [" + type.getName() + "]" );
  }

  return idType;
}
 
Example 13
Source File: KettleDatabaseRepositoryJobEntryDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public synchronized ObjectId insertJobEntry( ObjectId id_job, JobEntryBase jobEntryBase ) throws KettleException {
  ObjectId id = repository.connectionDelegate.getNextJobEntryID();

  ObjectId id_jobentry_type = getJobEntryTypeID( jobEntryBase.getPluginId() );

  log.logDebug( "ID_JobEntry_type = " + id_jobentry_type + " for type = [" + jobEntryBase.getPluginId() + "]" );

  RowMetaAndData table = new RowMetaAndData();

  table.addValue( new ValueMetaInteger(
    KettleDatabaseRepository.FIELD_JOBENTRY_ID_JOBENTRY ), id );
  table.addValue(
    new ValueMetaInteger( KettleDatabaseRepository.FIELD_JOBENTRY_ID_JOB ), id_job );
  table
    .addValue(
      new ValueMetaInteger(
        KettleDatabaseRepository.FIELD_JOBENTRY_ID_JOBENTRY_TYPE ),
      id_jobentry_type );
  table.addValue(
    new ValueMetaString( KettleDatabaseRepository.FIELD_JOBENTRY_NAME ),
    jobEntryBase.getName() );
  table.addValue( new ValueMetaString(
    KettleDatabaseRepository.FIELD_JOBENTRY_DESCRIPTION ), jobEntryBase
    .getDescription() );

  repository.connectionDelegate.getDatabase().prepareInsert(
    table.getRowMeta(), KettleDatabaseRepository.TABLE_R_JOBENTRY );
  repository.connectionDelegate.getDatabase().setValuesInsert( table );
  repository.connectionDelegate.getDatabase().insertRow();
  repository.connectionDelegate.getDatabase().closeInsert();

  jobEntryBase.setObjectId( id );

  return id;
}
 
Example 14
Source File: KettleDatabaseRepositoryStepDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public synchronized ObjectId insertStep( ObjectId id_transformation, String name, String description,
  String steptype, boolean distribute, long copies, long gui_location_x, long gui_location_y,
  boolean gui_draw, String copiesString ) throws KettleException {
  ObjectId id = repository.connectionDelegate.getNextStepID();

  ObjectId id_step_type = getStepTypeID( steptype );

  RowMetaAndData table = new RowMetaAndData();

  table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_STEP_ID_STEP ), id );
  table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_STEP_ID_TRANSFORMATION ), id_transformation );
  table.addValue( new ValueMetaString( KettleDatabaseRepository.FIELD_STEP_NAME ), name );
  table.addValue( new ValueMetaString( KettleDatabaseRepository.FIELD_STEP_DESCRIPTION ), description );
  table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_STEP_ID_STEP_TYPE ), id_step_type );
  table.addValue( new ValueMetaBoolean( KettleDatabaseRepository.FIELD_STEP_DISTRIBUTE ), Boolean.valueOf( distribute ) );
  table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_STEP_COPIES ), new Long( copies ) );
  table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_STEP_GUI_LOCATION_X ), new Long( gui_location_x ) );
  table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_STEP_GUI_LOCATION_Y ), new Long( gui_location_y ) );
  table.addValue( new ValueMetaBoolean( KettleDatabaseRepository.FIELD_STEP_GUI_DRAW ), Boolean.valueOf( gui_draw ) );
  table.addValue( new ValueMetaString( KettleDatabaseRepository.FIELD_STEP_COPIES_STRING ), copiesString );

  repository.connectionDelegate.getDatabase().prepareInsert( table.getRowMeta(), KettleDatabaseRepository.TABLE_R_STEP );
  repository.connectionDelegate.getDatabase().setValuesInsert( table );
  repository.connectionDelegate.getDatabase().insertRow();
  repository.connectionDelegate.getDatabase().closeInsert();

  return id;
}
 
Example 15
Source File: KettleDatabaseRepositoryTransDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private synchronized ObjectId insertDependency( ObjectId id_transformation, ObjectId id_database,
  String tablename, String fieldname ) throws KettleException {
  ObjectId id = repository.connectionDelegate.getNextDepencencyID();

  RowMetaAndData table = new RowMetaAndData();

  table.addValue( new ValueMetaInteger(
    KettleDatabaseRepository.FIELD_DEPENDENCY_ID_DEPENDENCY ), id );
  table.addValue(
    new ValueMetaInteger(
      KettleDatabaseRepository.FIELD_DEPENDENCY_ID_TRANSFORMATION ),
    id_transformation );
  table.addValue( new ValueMetaInteger(
    KettleDatabaseRepository.FIELD_DEPENDENCY_ID_DATABASE ), id_database );
  table.addValue( new ValueMetaString(
    KettleDatabaseRepository.FIELD_DEPENDENCY_TABLE_NAME ), tablename );
  table.addValue( new ValueMetaString(
    KettleDatabaseRepository.FIELD_DEPENDENCY_FIELD_NAME ), fieldname );

  repository.connectionDelegate.getDatabase().prepareInsert(
    table.getRowMeta(), KettleDatabaseRepository.TABLE_R_DEPENDENCY );
  repository.connectionDelegate.getDatabase().setValuesInsert( table );
  repository.connectionDelegate.getDatabase().insertRow();
  repository.connectionDelegate.getDatabase().closeInsert();

  return id;
}
 
Example 16
Source File: Database.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void cleanupLogRecords( LogTableCoreInterface logTable ) throws KettleDatabaseException {
  double timeout = Const.toDouble( Const.trim( environmentSubstitute( logTable.getTimeoutInDays() ) ), 0.0 );
  if ( timeout < 0.000001 ) {
    // The timeout has to be at least a few seconds, otherwise we don't
    // bother
    return;
  }

  String schemaTable =
    databaseMeta.getQuotedSchemaTableCombination( environmentSubstitute( logTable.getActualSchemaName() ),
      environmentSubstitute( logTable.getActualTableName() ) );

  if ( schemaTable.isEmpty() ) {
    //we can't process without table name
    DatabaseLogExceptionFactory.getExceptionStrategy( logTable )
      .registerException( log, PKG, "DatabaseMeta.Error.LogTableNameNotFound" );
  }

  LogTableField logField = logTable.getLogDateField();
  if ( logField == null ) {
    //can't stand without logField
    DatabaseLogExceptionFactory.getExceptionStrategy( logTable )
      .registerException( log, PKG, "Database.Exception.LogTimeoutDefinedOnTableWithoutLogField" );
  }

  String sql =
    "DELETE FROM " + schemaTable + " WHERE " + databaseMeta.quoteField( logField.getFieldName() ) + " < ?";
  long now = System.currentTimeMillis();
  long limit = now - Math.round( timeout * 24 * 60 * 60 * 1000 );
  RowMetaAndData row = new RowMetaAndData();
  row.addValue( logField.getFieldName(), ValueMetaInterface.TYPE_DATE, new Date( limit ) );

  try {
    //fire database
    execStatement( sql, row.getRowMeta(), row.getData() );
  } catch ( Exception e ) {
    DatabaseLogExceptionFactory.getExceptionStrategy( logTable )
      .registerException( log, PKG, "Database.Exception.UnableToCleanUpOlderRecordsFromLogTable",
        environmentSubstitute( logTable.getActualTableName() ) );
  }
}
 
Example 17
Source File: KettleDatabaseRepositoryNotePadDelegate.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public synchronized ObjectId insertNote( String note, long gui_location_x, long gui_location_y,
  long gui_location_width, long gui_location_height, String fontname, long fontsize, boolean fontbold,
  boolean fontitalic, long fontcolorred, long fontcolorgreen, long fontcolorblue, long fontbackcolorred,
  long fontbackcolorgreen, long fontbackcolorblue, long fontbordercolorred, long fontbordercolorgreen,
  long fontbordercolorblue, boolean drawshadow ) throws KettleException {
  ObjectId id = repository.connectionDelegate.getNextNoteID();

  RowMetaAndData table = new RowMetaAndData();

  table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_NOTE_ID_NOTE ), id );
  table.addValue( new ValueMetaString( KettleDatabaseRepository.FIELD_NOTE_VALUE_STR ), note );
  table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_NOTE_GUI_LOCATION_X ), new Long( gui_location_x ) );
  table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_NOTE_GUI_LOCATION_Y ), new Long( gui_location_y ) );
  table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_NOTE_GUI_LOCATION_WIDTH ), new Long( gui_location_width ) );
  table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_NOTE_GUI_LOCATION_HEIGHT ), new Long( gui_location_height ) );
  // Font
  table.addValue( new ValueMetaString( KettleDatabaseRepository.FIELD_NOTE_FONT_NAME ), fontname );
  table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_NOTE_FONT_SIZE ), fontsize );
  table.addValue( new ValueMetaBoolean( KettleDatabaseRepository.FIELD_NOTE_FONT_BOLD ), Boolean.valueOf( fontbold ) );
  table.addValue( new ValueMetaBoolean( KettleDatabaseRepository.FIELD_NOTE_FONT_ITALIC ), Boolean.valueOf( fontitalic ) );
  // Font color
  table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_NOTE_COLOR_RED ), new Long( fontcolorred ) );
  table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_NOTE_COLOR_GREEN ), new Long( fontcolorgreen ) );
  table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_NOTE_COLOR_BLUE ), new Long( fontcolorblue ) );
  // Font background color
  table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_NOTE_BACK_GROUND_COLOR_RED ), new Long( fontbackcolorred ) );
  table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_NOTE_BACK_GROUND_COLOR_GREEN ), new Long( fontbackcolorgreen ) );
  table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_NOTE_BACK_GROUND_COLOR_BLUE ), new Long( fontbackcolorblue ) );
  // Font border color
  table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_NOTE_BORDER_COLOR_RED ), new Long( fontbordercolorred ) );
  table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_NOTE_BORDER_COLOR_GREEN ), new Long( fontbordercolorgreen ) );
  table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_NOTE_BORDER_COLOR_BLUE ), new Long( fontbordercolorblue ) );
  table.addValue( new ValueMetaBoolean( KettleDatabaseRepository.FIELD_NOTE_DRAW_SHADOW ), Boolean.valueOf( drawshadow ) );

  repository.connectionDelegate.getDatabase().prepareInsert( table.getRowMeta(), KettleDatabaseRepository.TABLE_R_NOTE );
  repository.connectionDelegate.getDatabase().setValuesInsert( table );
  repository.connectionDelegate.getDatabase().insertRow();
  repository.connectionDelegate.getDatabase().closeInsert();

  return id;
}
 
Example 18
Source File: KettleDatabaseRepositoryConditionDelegate.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public synchronized ObjectId insertCondition( ObjectId id_condition_parent, Condition condition ) throws KettleException {
  ObjectId id = repository.connectionDelegate.getNextConditionID();

  String tablename = KettleDatabaseRepository.TABLE_R_CONDITION;
  RowMetaAndData table = new RowMetaAndData();
  table.addValue( new ValueMetaInteger(
    KettleDatabaseRepository.FIELD_CONDITION_ID_CONDITION ), id );
  table.addValue(
    new ValueMetaInteger(
      KettleDatabaseRepository.FIELD_CONDITION_ID_CONDITION_PARENT ),
    id_condition_parent );
  table.addValue( new ValueMetaBoolean(
    KettleDatabaseRepository.FIELD_CONDITION_NEGATED ), Boolean
    .valueOf( condition.isNegated() ) );
  table.addValue( new ValueMetaString(
    KettleDatabaseRepository.FIELD_CONDITION_OPERATOR ), condition
    .getOperatorDesc() );
  table.addValue( new ValueMetaString(
    KettleDatabaseRepository.FIELD_CONDITION_LEFT_NAME ), condition
    .getLeftValuename() );
  table.addValue( new ValueMetaString(
    KettleDatabaseRepository.FIELD_CONDITION_CONDITION_FUNCTION ), condition
    .getFunctionDesc() );
  table.addValue( new ValueMetaString(
    KettleDatabaseRepository.FIELD_CONDITION_RIGHT_NAME ), condition
    .getRightValuename() );

  ObjectId id_value = null;
  ValueMetaAndData v = condition.getRightExact();

  if ( v != null ) {

    // We have to make sure that all data is saved irrespective of locale differences.
    // Here is where we force that
    //
    ValueMetaInterface valueMeta = v.getValueMeta();
    valueMeta.setDecimalSymbol( ValueMetaAndData.VALUE_REPOSITORY_DECIMAL_SYMBOL );
    valueMeta.setGroupingSymbol( ValueMetaAndData.VALUE_REPOSITORY_GROUPING_SYMBOL );
    switch ( valueMeta.getType() ) {
      case ValueMetaInterface.TYPE_NUMBER:
        valueMeta.setConversionMask( ValueMetaAndData.VALUE_REPOSITORY_NUMBER_CONVERSION_MASK );
        break;
      case ValueMetaInterface.TYPE_INTEGER:
        valueMeta.setConversionMask( ValueMetaAndData.VALUE_REPOSITORY_INTEGER_CONVERSION_MASK );
        break;
      case ValueMetaInterface.TYPE_DATE:
        valueMeta.setConversionMask( ValueMetaAndData.VALUE_REPOSITORY_DATE_CONVERSION_MASK );
        break;
      default:
        break;
    }
    String stringValue = valueMeta.getString( v.getValueData() );

    id_value =
      insertValue( valueMeta.getName(), valueMeta.getTypeDesc(), stringValue, valueMeta.isNull( v
        .getValueData() ), condition.getRightExactID() );
    condition.setRightExactID( id_value );
  }
  table.addValue( new ValueMetaInteger(
    KettleDatabaseRepository.FIELD_CONDITION_ID_VALUE_RIGHT ), id_value );

  repository.connectionDelegate.getDatabase().prepareInsert( table.getRowMeta(), tablename );
  repository.connectionDelegate.getDatabase().setValuesInsert( table );
  repository.connectionDelegate.getDatabase().insertRow();
  repository.connectionDelegate.getDatabase().closeInsert();

  return id;
}
 
Example 19
Source File: PerformanceLogTable.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * This method calculates all the values that are required
 *
 * @param id
 *          the id to use or -1 if no id is needed
 * @param status
 *          the log status to use
 */
public RowMetaAndData getLogRecord( LogStatus status, Object subject, Object parent ) {
  if ( subject == null || subject instanceof StepPerformanceSnapShot ) {
    StepPerformanceSnapShot snapShot = (StepPerformanceSnapShot) subject;

    RowMetaAndData row = new RowMetaAndData();

    for ( LogTableField field : fields ) {
      if ( field.isEnabled() ) {
        Object value = null;
        if ( subject != null ) {
          switch ( ID.valueOf( field.getId() ) ) {

            case ID_BATCH:
              value = new Long( snapShot.getBatchId() );
              break;
            case SEQ_NR:
              value = new Long( snapShot.getSeqNr() );
              break;
            case LOGDATE:
              value = snapShot.getDate();
              break;
            case TRANSNAME:
              value = snapShot.getTransName();
              break;
            case STEPNAME:
              value = snapShot.getStepName();
              break;
            case STEP_COPY:
              value = new Long( snapShot.getStepCopy() );
              break;
            case LINES_READ:
              value = new Long( snapShot.getLinesRead() );
              break;
            case LINES_WRITTEN:
              value = new Long( snapShot.getLinesWritten() );
              break;
            case LINES_INPUT:
              value = new Long( snapShot.getLinesInput() );
              break;
            case LINES_OUTPUT:
              value = new Long( snapShot.getLinesOutput() );
              break;
            case LINES_UPDATED:
              value = new Long( snapShot.getLinesUpdated() );
              break;
            case LINES_REJECTED:
              value = new Long( snapShot.getLinesRejected() );
              break;
            case ERRORS:
              value = new Long( snapShot.getErrors() );
              break;
            case INPUT_BUFFER_ROWS:
              value = new Long( snapShot.getInputBufferSize() );
              break;
            case OUTPUT_BUFFER_ROWS:
              value = new Long( snapShot.getOutputBufferSize() );
              break;
            default:
              break;
          }
        }

        row.addValue( field.getFieldName(), field.getDataType(), value );
        row.getRowMeta().getValueMeta( row.size() - 1 ).setLength( field.getLength() );
      }
    }

    return row;
  } else {
    return null;
  }
}
 
Example 20
Source File: KettleDatabaseRepositoryDatabaseDelegate.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public synchronized ObjectId insertDatabase( String name, String type, String access, String host,
  String dbname, String port, String user, String pass, String servername, String data_tablespace,
  String index_tablespace ) throws KettleException {

  ObjectId id = repository.connectionDelegate.getNextDatabaseID();

  ObjectId id_database_type = getDatabaseTypeID( type );
  if ( id_database_type == null ) {
    // New support database type: add it!

    id_database_type = repository.connectionDelegate.getNextDatabaseTypeID();

    String tablename = KettleDatabaseRepository.TABLE_R_DATABASE_TYPE;
    RowMetaInterface tableMeta = new RowMeta();

    tableMeta.addValueMeta( new ValueMetaInteger(
      KettleDatabaseRepository.FIELD_DATABASE_TYPE_ID_DATABASE_TYPE, 5, 0 ) );
    tableMeta.addValueMeta( new ValueMetaString( KettleDatabaseRepository.FIELD_DATABASE_TYPE_CODE,
      KettleDatabaseRepository.REP_STRING_CODE_LENGTH, 0 ) );
    tableMeta.addValueMeta( new ValueMetaString( KettleDatabaseRepository.FIELD_DATABASE_TYPE_DESCRIPTION,
      KettleDatabaseRepository.REP_STRING_LENGTH, 0 ) );

    repository.connectionDelegate.getDatabase().prepareInsert( tableMeta, tablename );

    Object[] tableData = new Object[3];
    int tableIndex = 0;

    tableData[tableIndex++] = new LongObjectId( id_database_type ).longValue();
    tableData[tableIndex++] = type;
    tableData[tableIndex++] = type;

    repository.connectionDelegate.getDatabase().setValuesInsert( tableMeta, tableData );
    repository.connectionDelegate.getDatabase().insertRow();
    repository.connectionDelegate.getDatabase().closeInsert();
  }

  ObjectId id_database_contype = getDatabaseConTypeID( access );

  RowMetaAndData table = new RowMetaAndData();
  table.addValue( new ValueMetaInteger(
    KettleDatabaseRepository.FIELD_DATABASE_ID_DATABASE ), id );
  table.addValue(
    new ValueMetaString( KettleDatabaseRepository.FIELD_DATABASE_NAME ), name );
  table
    .addValue(
      new ValueMetaInteger(
        KettleDatabaseRepository.FIELD_DATABASE_ID_DATABASE_TYPE ),
      id_database_type );
  table.addValue(
    new ValueMetaInteger(
      KettleDatabaseRepository.FIELD_DATABASE_ID_DATABASE_CONTYPE ),
    id_database_contype );
  table.addValue( new ValueMetaString(
    KettleDatabaseRepository.FIELD_DATABASE_HOST_NAME ), host );
  table.addValue( new ValueMetaString(
    KettleDatabaseRepository.FIELD_DATABASE_DATABASE_NAME ), dbname );
  table.addValue(
    new ValueMetaInteger( KettleDatabaseRepository.FIELD_DATABASE_PORT ), Long.valueOf(
      Const.toLong( port, -1 ) ) );
  table.addValue( new ValueMetaString(
    KettleDatabaseRepository.FIELD_DATABASE_USERNAME ), user );
  table.addValue( new ValueMetaString(
    KettleDatabaseRepository.FIELD_DATABASE_PASSWORD ), Encr
    .encryptPasswordIfNotUsingVariables( pass ) );
  table.addValue( new ValueMetaString(
    KettleDatabaseRepository.FIELD_DATABASE_SERVERNAME ), servername );
  table.addValue( new ValueMetaString(
    KettleDatabaseRepository.FIELD_DATABASE_DATA_TBS ), data_tablespace );
  table.addValue( new ValueMetaString(
    KettleDatabaseRepository.FIELD_DATABASE_INDEX_TBS ), index_tablespace );

  repository.connectionDelegate.getDatabase().prepareInsert(
    table.getRowMeta(), KettleDatabaseRepository.TABLE_R_DATABASE );
  repository.connectionDelegate.getDatabase().setValuesInsert( table );
  repository.connectionDelegate.getDatabase().insertRow();
  repository.connectionDelegate.getDatabase().closeInsert();

  return id;
}