Java Code Examples for org.pentaho.di.core.Const#indexOfString()

The following examples show how to use org.pentaho.di.core.Const#indexOfString() . 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: ExcelInputDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void setEncodings() {
  // Encoding of the text file:
  if ( !gotEncodings ) {
    gotEncodings = true;

    wEncoding.removeAll();

    List<Charset> values = new ArrayList<Charset>( Charset.availableCharsets().values() );
    for ( int i = 0; i < values.size(); i++ ) {
      Charset charSet = values.get( i );
      wEncoding.add( charSet.displayName() );
    }

    // Now select the default!
    String defEncoding = Const.getEnvironmentVariable( "file.encoding", "UTF-8" );
    int idx = Const.indexOfString( defEncoding, wEncoding.getItems() );
    if ( idx >= 0 ) {
      wEncoding.select( idx );
    }
  }
}
 
Example 2
Source File: TextFileInputDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void setEncodings() {
  // Encoding of the text file:
  if ( !gotEncodings ) {
    gotEncodings = true;

    wEncoding.removeAll();
    List<Charset> values = new ArrayList<Charset>( Charset.availableCharsets().values() );
    for ( Charset charSet : values ) {
      wEncoding.add( charSet.displayName() );
    }

    // Now select the default!
    String defEncoding = Const.getEnvironmentVariable( "file.encoding", "UTF-8" );
    int idx = Const.indexOfString( defEncoding, wEncoding.getItems() );
    if ( idx >= 0 ) {
      wEncoding.select( idx );
    }
  }
}
 
Example 3
Source File: ParGzipCsvInputDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void setEncodings() {
  // Encoding of the text file:
  if ( !gotEncodings ) {
    gotEncodings = true;

    wEncoding.removeAll();
    List<Charset> values = new ArrayList<Charset>( Charset.availableCharsets().values() );
    for ( int i = 0; i < values.size(); i++ ) {
      Charset charSet = values.get( i );
      wEncoding.add( charSet.displayName() );
    }

    // Now select the default!
    String defEncoding = Const.getEnvironmentVariable( "file.encoding", "UTF-8" );
    int idx = Const.indexOfString( defEncoding, wEncoding.getItems() );
    if ( idx >= 0 ) {
      wEncoding.select( idx );
    }
  }
}
 
Example 4
Source File: ExcelOutputDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void setEncodings() {
  // Encoding of the text file:
  if ( !gotEncodings ) {
    gotEncodings = true;

    wEncoding.removeAll();
    List<Charset> values = new ArrayList<Charset>( Charset.availableCharsets().values() );
    for ( int i = 0; i < values.size(); i++ ) {
      Charset charSet = values.get( i );
      wEncoding.add( charSet.displayName() );
    }

    // Now select the default!
    String defEncoding = Const.getEnvironmentVariable( "file.encoding", "UTF-8" );
    int idx = Const.indexOfString( defEncoding, wEncoding.getItems() );
    if ( idx >= 0 ) {
      wEncoding.select( idx );
    }
  }
}
 
Example 5
Source File: TextFileInputDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void setEncodings() {
  // Encoding of the text file:
  if ( !gotEncodings ) {
    gotEncodings = true;

    wEncoding.removeAll();
    List<Charset> values = new ArrayList<>( Charset.availableCharsets().values() );
    for ( Charset charSet : values ) {
      wEncoding.add( charSet.displayName() );
    }

    // Now select the default!
    String defEncoding = Const.getEnvironmentVariable( "file.encoding", "UTF-8" );
    int idx = Const.indexOfString( defEncoding, wEncoding.getItems() );
    if ( idx >= 0 ) {
      wEncoding.select( idx );
    }
  }
}
 
Example 6
Source File: PropertyInputDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void setEncodings() {
  // Encoding of the text file:
  if ( !gotEncodings ) {
    gotEncodings = true;

    wEncoding.removeAll();
    ArrayList<Charset> values = new ArrayList<Charset>( Charset.availableCharsets().values() );
    for ( int i = 0; i < values.size(); i++ ) {
      Charset charSet = values.get( i );
      wEncoding.add( charSet.displayName() );
    }

    // Now select the default!
    String defEncoding = Const.getEnvironmentVariable( "file.encoding", PropertyInputMeta.DEFAULT_ENCODING );
    int idx = Const.indexOfString( defEncoding, wEncoding.getItems() );
    if ( idx >= 0 ) {
      wEncoding.select( idx );
    }
  }
}
 
Example 7
Source File: EnterMappingDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void add() {
  if ( wSource.getSelectionCount() == 1 && wTarget.getSelectionCount() == 1 ) {
    String sourceString = wSource.getSelection()[0];
    String targetString = wTarget.getSelection()[0];

    int srcIndex = Const.indexOfString( sourceString, sourceList );
    int tgtIndex = Const.indexOfString( targetString, targetList );

    if ( srcIndex >= 0 && tgtIndex >= 0 ) {
      // New mapping: add it to the list...
      SourceToTargetMapping mapping = new SourceToTargetMapping( srcIndex, tgtIndex );
      mappings.add( mapping );

      refreshMappings();
    }
  }
}
 
Example 8
Source File: JsonOutputDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void setEncodings() {
  // Encoding of the text file:
  if ( !gotEncodings ) {
    gotEncodings = true;

    wEncoding.removeAll();
    List<Charset> values = new ArrayList<Charset>( Charset.availableCharsets().values() );
    for ( int i = 0; i < values.size(); i++ ) {
      Charset charSet = values.get( i );
      wEncoding.add( charSet.displayName() );
    }

    // Now select the default!
    String defEncoding = Const.getEnvironmentVariable( "file.encoding", "UTF-8" );
    int idx = Const.indexOfString( defEncoding, wEncoding.getItems() );
    if ( idx >= 0 ) {
      wEncoding.select( idx );
    } else {
      wEncoding.select( Const.indexOfString( "UTF-8", wEncoding.getItems() ) );
    }
  }
}
 
Example 9
Source File: AbstractMethodProcessor.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void processForKnownSchema( String schemaName, PartitionSettings settings ) throws KettlePluginException {
  if ( schemaName != null ) {
    int idx = Const.indexOfString( schemaName, settings.getSchemaNames() );
    settings.updateSchema( settings.getSchemas().get( idx ) );
  } else {
    settings.rollback( settings.getBefore() );
  }
}
 
Example 10
Source File: StringUtil.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Search the string and report back on the variables used
 *
 * @param aString
 *          The string to search
 * @param open
 *          the open or "start of variable" characters ${ or %%
 * @param close
 *          the close or "end of variable" characters } or %%
 * @param list
 *          the list of variables to add to
 * @param includeSystemVariables
 *          also check for system variables.
 */
public static void getUsedVariables( String aString, String open, String close, List<String> list,
  boolean includeSystemVariables ) {
  if ( aString == null ) {
    return;
  }

  int p = 0;
  while ( p < aString.length() ) {
    // OK, we found something... : start of Unix variable
    if ( aString.substring( p ).startsWith( open ) ) {
      // See if it's closed...
      int from = p + open.length();
      int to = aString.indexOf( close, from + 1 );

      if ( to >= 0 ) {
        String variable = aString.substring( from, to );

        if ( Const.indexOfString( variable, list ) < 0 ) {
          // Either we include the system variables (all)
          // Or the variable is not a system variable
          // Or it's a system variable but the value has not been set (and we offer the user the option to set it)
          //
          if ( includeSystemVariables || !isSystemVariable( variable ) || System.getProperty( variable ) == null ) {
            list.add( variable );
          }
        }
        // OK, continue
        p = to + close.length();
      }
    }
    p++;
  }
}
 
Example 11
Source File: DataSetHelper.java    From pentaho-pdi-dataset with Apache License 2.0 5 votes vote down vote up
private String validateDataSetGroup( DataSetGroup dataSetGroup, String previousName, List<String> groupNames ) {

    String message = null;

    String newName = dataSetGroup.getName();
    if ( StringUtil.isEmpty( newName ) ) {
      message = BaseMessages.getString( PKG, "DataSetHelper.DataSetGroup.NoNameSpecified.Message" );
    } else if ( !StringUtil.isEmpty( previousName ) && !previousName.equals( newName ) ) {
      message = BaseMessages.getString( PKG, "DataSetHelper.DataSetGroup.RenamingOfADataSetNotSupported.Message" );
    } else if ( StringUtil.isEmpty( previousName ) && Const.indexOfString( newName, groupNames ) >= 0 ) {
      message = BaseMessages.getString( PKG, "DataSetHelper.DataSetGroup.AGroupWithNameExists.Message", newName );
    } else if ( dataSetGroup.getType() == null ) {
      message = BaseMessages.getString( PKG, "DataSetHelper.DataSetGroup.NoGroupTypeSpecified.Message" );
    } else {
      switch ( dataSetGroup.getType() ) {
        case Database:
          if ( dataSetGroup.getDatabaseMeta() == null ) {
            message = BaseMessages.getString( PKG, "DataSetHelper.DataSetGroup.NoDatabaseSpecified.Message" );
          }
          break;
        case CSV:
          break;
      }
    }

    return message;
  }
 
Example 12
Source File: FileLoggingEventListener.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public void eventAdded( KettleLoggingEvent event ) {

  try {
    Object messageObject = event.getMessage();
    if ( messageObject instanceof LogMessage ) {
      boolean logToFile = false;

      if ( logChannelId == null ) {
        logToFile = true;
      } else {
        LogMessage message = (LogMessage) messageObject;
        // This should be fast enough cause cached.
        List<String> logChannelChildren = LoggingRegistry.getInstance().getLogChannelChildren( logChannelId );
        // This could be non-optimal, consider keeping the list sorted in the logging registry
        logToFile = Const.indexOfString( message.getLogChannelId(), logChannelChildren ) >= 0;
      }

      if ( logToFile ) {
        String logText = layout.format( event );
        outputStream.write( logText.getBytes() );
        outputStream.write( Const.CR.getBytes() );
      }
    }
  } catch ( Exception e ) {
    exception = new KettleException( "Unable to write to logging event to file '" + filename + "'", e );
  }
}
 
Example 13
Source File: JobEntryTransDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void getParameters( TransMeta inputTransMeta ) {
  try {
    if ( inputTransMeta == null ) {
      JobEntryTrans jet = new JobEntryTrans();
      getInfo( jet );
      inputTransMeta = jet.getTransMeta( rep, metaStore, jobMeta );
    }
    String[] parameters = inputTransMeta.listParameters();

    String[] existing = wParameters.getItems( 1 );

    for ( int i = 0; i < parameters.length; i++ ) {
      if ( Const.indexOfString( parameters[ i ], existing ) < 0 ) {
        TableItem item = new TableItem( wParameters.table, SWT.NONE );
        item.setText( 1, parameters[ i ] );
      }
    }
    wParameters.removeEmptyRows();
    wParameters.setRowNums();
    wParameters.optWidth( true );
  } catch ( Exception e ) {
    new ErrorDialog( shell,
      BaseMessages.getString( PKG, "JobEntryTransDialog.Exception.UnableToLoadTransformation.Title" ),
      BaseMessages.getString( PKG, "JobEntryTransDialog.Exception.UnableToLoadTransformation.Message" ), e );
  }

}
 
Example 14
Source File: MSSQLServerDatabaseMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Verifies on the specified database connection if an index exists on the fields with the specified name.
 *
 * @param database
 *          a connected database
 * @param schemaName
 * @param tableName
 * @param idxFields
 * @return true if the index exists, false if it doesn't.
 * @throws KettleDatabaseException
 */
@Override
public boolean checkIndexExists( Database database, String schemaName, String tableName, String[] idxFields ) throws KettleDatabaseException {

  String tablename = database.getDatabaseMeta().getQuotedSchemaTableCombination( schemaName, tableName );

  boolean[] exists = new boolean[ idxFields.length];
  for ( int i = 0; i < exists.length; i++ ) {
    exists[i] = false;
  }

  try {
    //
    // Get the info from the data dictionary...
    //
    StringBuilder sql = new StringBuilder( 128 );
    sql.append( "select i.name table_name, c.name column_name " );
    sql.append( "from     sysindexes i, sysindexkeys k, syscolumns c " );
    sql.append( "where    i.name = '" + tablename + "' " );
    sql.append( "AND      i.id = k.id " );
    sql.append( "AND      i.id = c.id " );
    sql.append( "AND      k.colid = c.colid " );

    ResultSet res = null;
    try {
      res = database.openQuery( sql.toString() );
      if ( res != null ) {
        Object[] row = database.getRow( res );
        while ( row != null ) {
          String column = database.getReturnRowMeta().getString( row, "column_name", "" );
          int idx = Const.indexOfString( column, idxFields );
          if ( idx >= 0 ) {
            exists[idx] = true;
          }

          row = database.getRow( res );
        }
      } else {
        return false;
      }
    } finally {
      if ( res != null ) {
        database.closeQuery( res );
      }
    }

    // See if all the fields are indexed...
    boolean all = true;
    for ( int i = 0; i < exists.length && all; i++ ) {
      if ( !exists[i] ) {
        all = false;
      }
    }

    return all;
  } catch ( Exception e ) {
    throw new KettleDatabaseException( "Unable to determine if indexes exists on table [" + tablename + "]", e );
  }
}
 
Example 15
Source File: CombinationLookup.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException {
  Object[] r = getRow(); // Get row from input rowset & set row busy!
  // if no more input to be expected set done
  if ( r == null ) {
    setOutputDone();
    return false;
  }

  if ( first ) {
    first = false;

    data.outputRowMeta = getInputRowMeta().clone();
    meta.getFields( data.outputRowMeta, getStepname(), null, null, this, repository, metaStore );

    data.schemaTable =
      meta.getDatabaseMeta().getQuotedSchemaTableCombination( data.realSchemaName, data.realTableName );

    determineTechKeyCreation();

    // The indexes of the key values...
    //
    data.keynrs = new int[ meta.getKeyField().length ];

    for ( int i = 0; i < meta.getKeyField().length; i++ ) {
      data.keynrs[ i ] = getInputRowMeta().indexOfValue( meta.getKeyField()[ i ] );
      if ( data.keynrs[ i ] < 0 ) {
        // couldn't find field!
        throw new KettleStepException( BaseMessages.getString(
          PKG, "CombinationLookup.Exception.FieldNotFound", meta.getKeyField()[ i ] ) );
      }
    }

    // Determine for each input field if we want it removed or not.
    //
    data.removeField = new boolean[ getInputRowMeta().size() ];

    // Sort lookup values keys so that we
    //
    for ( int i = 0; i < getInputRowMeta().size(); i++ ) {
      ValueMetaInterface valueMeta = getInputRowMeta().getValueMeta( i );
      // Is this one of the keys?
      int idx = Const.indexOfString( valueMeta.getName(), meta.getKeyField() );
      data.removeField[ i ] = idx >= 0;
    }

    // Determine the metadata row to calculate hashcodes.
    //
    data.hashRowMeta = new RowMeta();
    for ( int i = 0; i < meta.getKeyField().length; i++ ) {
      data.hashRowMeta.addValueMeta( getInputRowMeta().getValueMeta( data.keynrs[ i ] ) ); // KEYi = ?
    }

    setCombiLookup( getInputRowMeta() );
    preloadCache( data.hashRowMeta );
  }

  try {
    Object[] outputRow = lookupValues( getInputRowMeta(), r ); // add new values to the row in rowset[0].
    putRow( data.outputRowMeta, outputRow ); // copy row to output rowset(s);

    if ( checkFeedback( getLinesRead() ) ) {
      if ( log.isBasic() ) {
        logBasic( BaseMessages.getString( PKG, "CombinationLookup.Log.LineNumber" ) + getLinesRead() );
      }
    }
  } catch ( KettleException e ) {
    if ( getStepMeta().isDoingErrorHandling() ) {
      putError( getInputRowMeta(), r, 1L, Const.getStackTracker( e ), null, "CBL001" );
    } else {
      logError( BaseMessages.getString( PKG, "CombinationLookup.Log.ErrorInStepRunning" ) + e.getMessage() );
      setErrors( 1 );
      stopAll();
      setOutputDone(); // signal end to receiver(s)
      return false;
    }
  }

  return true;
}
 
Example 16
Source File: LucidDBStreamingLoaderMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Builds the target column list for use in the INSERT statement INSERT INTO T1 <<columns>> ie, ("Col1", "Col2")
 *
 * @return
 */
private String buildTargetColumnsForInsert() {

  boolean suppress_comma = true;

  StringBuffer sb = new StringBuffer( 300 );
  sb.append( "(" );
  // Iterate over fieldTableForKeys[]

  for ( int i = 0; i < fieldTableForKeys.length; i++ ) {

    // Add comma to all except the first row
    if ( suppress_comma == true ) {
      suppress_comma = false;
    } else {
      sb.append( "," );
    }

    sb.append( databaseMeta.quoteField( fieldTableForKeys[i] ) );

  }

  // Iterate over fieldTableForFields[] (dedup)
  for ( int i = 0; i < fieldTableForFields.length; i++ ) {
    // Do not add if it's already in from keys
    if ( Const.indexOfString( fieldTableForFields[i], fieldTableForKeys ) < 0 ) {
      // Add comma to all except the first row
      if ( suppress_comma == true ) {
        suppress_comma = false;
      } else {
        sb.append( "," );
      }

      sb.append( databaseMeta.quoteField( fieldTableForFields[i] ) );
    }
  }
  sb.append( ")" );

  return sb.toString();

}
 
Example 17
Source File: OracleDatabaseMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Verifies on the specified database connection if an index exists on the fields with the specified name.
 *
 * @param database
 *          a connected database
 * @param schemaName
 * @param tableName
 * @param idxFields
 * @return true if the index exists, false if it doesn't.
 * @throws KettleDatabaseException
 */
@Override
public boolean checkIndexExists( Database database, String schemaName, String tableName, String[] idxFields ) throws KettleDatabaseException {

  String tablename = database.getDatabaseMeta().getQuotedSchemaTableCombination( schemaName, tableName );

  boolean[] exists = new boolean[ idxFields.length];
  for ( int i = 0; i < exists.length; i++ ) {
    exists[i] = false;
  }

  try {
    //
    // Get the info from the data dictionary...
    //
    String sql = "SELECT * FROM USER_IND_COLUMNS WHERE TABLE_NAME = '" + tableName + "'";
    ResultSet res = null;
    try {
      res = database.openQuery( sql );
      if ( res != null ) {
        Object[] row = database.getRow( res );
        while ( row != null ) {
          String column = database.getReturnRowMeta().getString( row, "COLUMN_NAME", "" );
          int idx = Const.indexOfString( column, idxFields );
          if ( idx >= 0 ) {
            exists[idx] = true;
          }

          row = database.getRow( res );
        }

      } else {
        return false;
      }
    } finally {
      if ( res != null ) {
        database.closeQuery( res );
      }
    }

    // See if all the fields are indexed...
    boolean all = true;
    for ( int i = 0; i < exists.length && all; i++ ) {
      if ( !exists[i] ) {
        all = false;
      }
    }

    return all;
  } catch ( Exception e ) {
    throw new KettleDatabaseException( "Unable to determine if indexes exists on table [" + tablename + "]", e );
  }
}
 
Example 18
Source File: ExcelInputDialog.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Processing excel workbook, filling fields
 *
 * @param fields   RowMetaInterface for filling fields
 * @param info     ExcelInputMeta
 * @param workbook excel workbook for processing
 * @throws KettlePluginException
 */
private void processingWorkbook( RowMetaInterface fields, ExcelInputMeta info, KWorkbook workbook )
  throws KettlePluginException {
  int nrSheets = workbook.getNumberOfSheets();
  for ( int j = 0; j < nrSheets; j++ ) {
    KSheet sheet = workbook.getSheet( j );

    // See if it's a selected sheet:
    int sheetIndex;
    if ( info.readAllSheets() ) {
      sheetIndex = 0;
    } else {
      sheetIndex = Const.indexOfString( sheet.getName(), info.getSheetName() );
    }
    if ( sheetIndex >= 0 ) {
      // We suppose it's the complete range we're looking for...
      //
      int rownr = 0;
      int startcol = 0;

      if ( info.readAllSheets() ) {
        if ( info.getStartColumn().length == 1 ) {
          startcol = info.getStartColumn()[ 0 ];
        }
        if ( info.getStartRow().length == 1 ) {
          rownr = info.getStartRow()[ 0 ];
        }
      } else {
        rownr = info.getStartRow()[ sheetIndex ];
        startcol = info.getStartColumn()[ sheetIndex ];
      }

      boolean stop = false;
      for ( int colnr = startcol; !stop; colnr++ ) {
        try {
          String fieldname = null;
          int fieldtype = ValueMetaInterface.TYPE_NONE;

          KCell cell = sheet.getCell( colnr, rownr );
          if ( cell == null ) {
            stop = true;
          } else {
            if ( cell.getType() != KCellType.EMPTY ) {
              // We found a field.
              fieldname = cell.getContents();
            }

            // System.out.println("Fieldname = "+fieldname);

            KCell below = sheet.getCell( colnr, rownr + 1 );

            if ( below != null ) {
              if ( below.getType() == KCellType.BOOLEAN ) {
                fieldtype = ValueMetaInterface.TYPE_BOOLEAN;
              } else if ( below.getType() == KCellType.DATE ) {
                fieldtype = ValueMetaInterface.TYPE_DATE;
              } else if ( below.getType() == KCellType.LABEL ) {
                fieldtype = ValueMetaInterface.TYPE_STRING;
              } else if ( below.getType() == KCellType.NUMBER ) {
                fieldtype = ValueMetaInterface.TYPE_NUMBER;
              } else {
                fieldtype = ValueMetaInterface.TYPE_STRING;
              }
            } else {
              fieldtype = ValueMetaInterface.TYPE_STRING;
            }

            if ( Utils.isEmpty( fieldname ) ) {
              stop = true;
            } else {
              if ( fieldtype != ValueMetaInterface.TYPE_NONE ) {
                ValueMetaInterface field = ValueMetaFactory.createValueMeta( fieldname, fieldtype );
                fields.addValueMeta( field );
              }
            }
          }
        } catch ( ArrayIndexOutOfBoundsException aioobe ) {
          // System.out.println("index out of bounds at column "+colnr+" : "+aioobe.toString());
          stop = true;
        }
      }
    }
  }
}
 
Example 19
Source File: FirebirdDatabaseMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public String getFieldDefinition( ValueMetaInterface v, String tk, String pk, boolean useAutoinc,
                                  boolean addFieldName, boolean addCr ) {
  String retval = "";

  String fieldname = v.getName();
  int length = v.getLength();
  int precision = v.getPrecision();

  if ( addFieldName ) {
    if ( Const.indexOfString( fieldname, getReservedWords() ) >= 0 ) {
      retval += getStartQuote() + fieldname + getEndQuote();
    } else {
      retval += fieldname + " ";
    }
  }

  int type = v.getType();
  switch ( type ) {
    case ValueMetaInterface.TYPE_TIMESTAMP:
    case ValueMetaInterface.TYPE_DATE:
      retval += "TIMESTAMP";
      break;
    case ValueMetaInterface.TYPE_BOOLEAN:
      if ( supportsBooleanDataType() ) {
        retval += "BIT";
      } else {
        retval += "CHAR(1)";
      }
      break;
    case ValueMetaInterface.TYPE_NUMBER:
    case ValueMetaInterface.TYPE_INTEGER:
    case ValueMetaInterface.TYPE_BIGNUMBER:
      if ( fieldname.equalsIgnoreCase( tk ) || // Technical key
        fieldname.equalsIgnoreCase( pk ) // Primary key
      ) {
        retval += "BIGINT NOT NULL PRIMARY KEY";
      } else {
        if ( length > 0 ) {
          if ( precision > 0 || length > 18 ) {
            retval += "DECIMAL(" + length;
            if ( precision > 0 ) {
              retval += ", " + precision;
            }
            retval += ")";
          } else {
            if ( length > 9 ) {
              retval += "BIGINT";
            } else {
              if ( length < 5 ) {
                retval += "SMALLINT";
              } else {
                retval += "INTEGER";
              }
            }
          }
        } else {
          retval += "DOUBLE";
        }
      }
      break;
    case ValueMetaInterface.TYPE_STRING:
      if ( length < 32720 ) {
        retval += "VARCHAR";
        if ( length > 0 ) {
          retval += "(" + length + ")";
        } else {
          retval += "(8000)"; // Maybe use some default DB String length?
        }
      } else {
        retval += "BLOB SUB_TYPE TEXT";
      }
      break;
    case ValueMetaInterface.TYPE_BINARY:
      retval += "BLOB";
      break;
    default:
      retval += "UNKNOWN";
      break;
  }

  if ( addCr ) {
    retval += Const.CR;
  }

  return retval;
}
 
Example 20
Source File: EnterListDialog.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void addToDestination( String string ) {
  int idxInput = Const.indexOfString( string, input );
  selection.put( Integer.valueOf( idxInput ), string );

  getData();
}