Java Code Examples for org.pentaho.di.core.Const#CR

The following examples show how to use org.pentaho.di.core.Const#CR . 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: LoadFileInputField.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public String getXML() {
  String retval = "";

  retval += "      <field>" + Const.CR;
  retval += "        " + XMLHandler.addTagValue( "name", getName() );
  retval += "        " + XMLHandler.addTagValue( "element_type", getElementTypeCode() );
  retval += "        " + XMLHandler.addTagValue( "type", getTypeDesc() );
  retval += "        " + XMLHandler.addTagValue( "format", getFormat() );
  retval += "        " + XMLHandler.addTagValue( "currency", getCurrencySymbol() );
  retval += "        " + XMLHandler.addTagValue( "decimal", getDecimalSymbol() );
  retval += "        " + XMLHandler.addTagValue( "group", getGroupSymbol() );
  retval += "        " + XMLHandler.addTagValue( "length", getLength() );
  retval += "        " + XMLHandler.addTagValue( "precision", getPrecision() );
  retval += "        " + XMLHandler.addTagValue( "trim_type", getTrimTypeCode() );
  retval += "        " + XMLHandler.addTagValue( "repeat", isRepeated() );

  retval += "        </field>" + Const.CR;

  return retval;
}
 
Example 2
Source File: KettleVersionException.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * get the messages back to it's origin cause.
 */
@Override
public String getMessage() {
  String retval = Const.CR;
  retval += super.getMessage() + Const.CR;

  Throwable cause = getCause();
  if ( cause != null ) {
    String message = cause.getMessage();
    if ( message != null ) {
      retval += message + Const.CR;
    } else {
      // Add with stack trace elements of cause...
      StackTraceElement[] ste = cause.getStackTrace();
      for ( int i = ste.length - 1; i >= 0; i-- ) {
        retval +=
          " at "
            + ste[i].getClassName() + "." + ste[i].getMethodName() + " (" + ste[i].getFileName() + ":"
            + ste[i].getLineNumber() + ")" + Const.CR;
      }
    }
  }

  return retval;
}
 
Example 3
Source File: InformixDatabaseMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public String getSQLLockTables( String[] tableNames ) {
  String sql = "";
  for ( int i = 0; i < tableNames.length; i++ ) {
    sql += "LOCK TABLE " + tableNames[i] + " IN EXCLUSIVE MODE;" + Const.CR;
  }
  return sql;
}
 
Example 4
Source File: DatabaseMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public String getModifyColumnStatement( String tablename, ValueMetaInterface v, String tk, boolean use_autoinc,
  String pk, boolean semicolon ) {
  String retval = databaseInterface.getModifyColumnStatement( tablename, v, tk, use_autoinc, pk, semicolon );
  retval += Const.CR;
  if ( semicolon ) {
    retval += ";" + Const.CR;
  }

  return retval;
}
 
Example 5
Source File: SpoonTabsDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Rename the tabs
 */
public void renameTabs() {
  List<TabMapEntry> list = new ArrayList<TabMapEntry>( tabMap );
  for ( TabMapEntry entry : list ) {
    if ( entry.getTabItem().isDisposed() ) {
      // this should not be in the map, get rid of it.
      tabMap.remove( entry.getObjectName() );
      continue;
    }

    // TabItem before = entry.getTabItem();
    // PDI-1683: need to get the String here, otherwise using only the "before" instance below, the reference gets
    // changed and result is always the same
    // String beforeText=before.getText();
    //
    Object managedObject = entry.getObject().getManagedObject();
    if ( managedObject != null ) {
      if ( entry.getObject() instanceof AbstractGraph ) {
        AbstractMeta meta = (AbstractMeta) managedObject;
        String tabText = makeTabName( meta, entry.isShowingLocation() );
        entry.getTabItem().setText( tabText );
        String toolTipText = BaseMessages.getString( PKG, "Spoon.TabTrans.Tooltip", tabText );
        if ( entry.getObject() instanceof JobGraph ) {
          toolTipText = BaseMessages.getString( PKG, "Spoon.TabJob.Tooltip", tabText );
        }
        if ( Const.isWindows() && !Utils.isEmpty( meta.getFilename() ) ) {
          toolTipText += Const.CR + Const.CR + meta.getFilename();
        }
        entry.getTabItem().setToolTipText( toolTipText );
      }
    }
  }
  spoon.setShellText();
}
 
Example 6
Source File: Stream.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public String toString() {
  if ( stepMeta == null ) {
    return "Stream type " + streamType + Const.CR + description;
  } else {
    return "Stream type " + streamType + " for step '" + stepMeta.getName() + "'" + Const.CR + description;
  }
}
 
Example 7
Source File: Neo4JOutputDialog.java    From knowbi-pentaho-pdi-neo4j-output with Apache License 2.0 4 votes vote down vote up
private void validateAndWarn( Neo4JOutputMeta input ) {
  StringBuffer message = new StringBuffer();

  // Warn about running too many small UNWIND statements when using dynamic labels
  //
  boolean dynamicFrom = input.dynamicFromLabels() && input.isUsingCreate();
  if ( dynamicFrom ) {
    message.append( Const.CR );
    message.append( BaseMessages.getString( PKG, "Neo4JOutputDialog.Warning.SortDynamicFromLabels", Const.CR ) );
  }
  boolean dynamicTo = input.dynamicToLabels() && input.isUsingCreate();
  if ( dynamicTo ) {
    message.append( Const.CR );
    message.append( BaseMessages.getString( PKG, "Neo4JOutputDialog.Warning.SortDynamicToLabels", Const.CR ) );
  }
  if ( input.isOnlyCreatingRelationships() && input.isCreatingRelationships() && ( input.dynamicFromLabels() || input.dynamicToLabels() ) ) {
    message.append( Const.CR );
    message.append( BaseMessages.getString( PKG, "Neo4JOutputDialog.Warning.SortDynamicRelationshipLabel", Const.CR ) );
  }

  // Verify that the defined connection is available
  //
  try {
    MetaStoreFactory<NeoConnection> factory = new MetaStoreFactory<>( NeoConnection.class, metaStore, Neo4jDefaults.NAMESPACE );
    NeoConnection connection = factory.loadElement( input.getConnection() );
    if ( connection == null ) {
      message.append( Const.CR );
      message.append( BaseMessages.getString( PKG, "Neo4JOutputDialog.Warning.ReferencedNeo4jConnectionDoesntExist", input.getConnection(), Const.CR ) );
    }
  } catch ( Exception e ) {
    message.append( "There was an error verifying the existence of the used Neo4j connection" )
      .append( Const.CR )
      .append( Const.getStackTracker( e ) )
      .append( Const.CR );
  }

  // Warn people about the "Create indexes" button
  //
  if ( input.isCreatingIndexes() && ( input.dynamicFromLabels() || input.dynamicToLabels() ) ) {
    message.append( Const.CR );
    message.append( BaseMessages.getString( PKG, "Neo4JOutputDialog.Warning.CreateIndexesIsLimited", Const.CR ) );
  }

  if ( message.length() > 0 && "Y".equalsIgnoreCase( props.getCustomParameter( STRING_DYNAMIC_LABELS_WARNING, "Y" ) ) ) {

    MessageDialogWithToggle md =
      new MessageDialogWithToggle( shell,
        BaseMessages.getString( PKG, "Neo4JOutputDialog.DynamicLabelsWarning.DialogTitle" ), null,
        message.toString() + Const.CR,
        MessageDialog.WARNING,
        new String[] { BaseMessages.getString( PKG, "Neo4JOutputDialog.DynamicLabelsWarning.Understood" ) },
        0,
        BaseMessages.getString( PKG, "Neo4JOutputDialog.DynamicLabelsWarning.HideNextTime" ), "N".equalsIgnoreCase(
        props.getCustomParameter( STRING_DYNAMIC_LABELS_WARNING, "Y" ) ) );
    MessageDialogWithToggle.setDefaultImage( GUIResource.getInstance().getImageSpoon() );
    md.open();
    props.setCustomParameter( STRING_DYNAMIC_LABELS_WARNING, md.getToggleState() ? "N" : "Y" );
    props.saveProps();
  }

}
 
Example 8
Source File: IngresDatabaseMeta.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 ) {
    retval += fieldname + " ";
  }

  int type = v.getType();
  switch ( type ) {
    case ValueMetaInterface.TYPE_TIMESTAMP:
      retval += "TIMESTAMP";
      break;
    case ValueMetaInterface.TYPE_DATE:
      retval += "DATE";
      break;
    case ValueMetaInterface.TYPE_BOOLEAN:
      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
      ) {
        if ( useAutoinc ) {
          retval += "BIGINT PRIMARY KEY IDENTITY(0,1)";
        } else {
          retval += "BIGINT PRIMARY KEY NOT NULL";
        }
      } else {
        if ( precision == 0 ) { // integer numbers
          if ( length > 9 ) {
            retval += "BIGINT";
          } else {
            if ( length > 4 ) {
              retval += "INTEGER";
            } else {
              if ( length > 2 ) {
                retval += "SMALLINT";
              } else {
                retval += "INTEGER1";
              }
            }
          }
        } else {
          retval += "FLOAT";
        }
      }
      break;
    case ValueMetaInterface.TYPE_STRING:
      // Maybe use some default DB String length in case length<=0
      if ( length > 0 ) {
        retval += "VARCHAR(" + length + ")";
      } else {
        retval += "VARCHAR(2000)";
      }
      break;
    default:
      retval += " UNKNOWN";
      break;
  }

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

  return retval;
}
 
Example 9
Source File: DB2DatabaseMeta.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 ) {
    retval += fieldname + " ";
  }

  int type = v.getType();
  switch ( type ) {
    case ValueMetaInterface.TYPE_TIMESTAMP:
    case ValueMetaInterface.TYPE_DATE:
      retval += "TIMESTAMP";
      break;
    case ValueMetaInterface.TYPE_BOOLEAN:
      retval += "CHARACTER(1)";
      break;
    case ValueMetaInterface.TYPE_NUMBER:
    case ValueMetaInterface.TYPE_BIGNUMBER:
      if ( fieldname.equalsIgnoreCase( tk ) && useAutoinc ) { // Technical key: auto increment field!
        retval += "BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 0, INCREMENT BY 1, NOCACHE)";
      } else {
        if ( length > 0 ) {
          retval += "DECIMAL(" + length;
          if ( precision > 0 ) {
            retval += ", " + precision;
          }
          retval += ")";
        } else {
          retval += "FLOAT";
        }
      }
      break;
    case ValueMetaInterface.TYPE_INTEGER:
      if ( fieldname.equalsIgnoreCase( tk ) && useAutoinc ) { // Technical key: auto increment field!
        retval += "INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 0, INCREMENT BY 1, NOCACHE)";
      } else {
        retval += "INTEGER";
      }
      break;
    case ValueMetaInterface.TYPE_STRING:
      if ( length > getMaxVARCHARLength() || length >= DatabaseMeta.CLOB_LENGTH ) {
        retval += "CLOB";
      } else {
        retval += "VARCHAR";
        if ( length > 0 ) {
          retval += "(" + length;
        } else {
          retval += "("; // Maybe use some default DB String length?
        }
        retval += ")";

      }
      break;
    case ValueMetaInterface.TYPE_BINARY:
      if ( length > getMaxVARCHARLength() || length >= DatabaseMeta.CLOB_LENGTH ) {
        retval += "BLOB(" + length + ")";
      } else {
        if ( length > 0 ) {
          retval += "CHAR(" + length + ") FOR BIT DATA";
        } else {
          retval += "BLOB"; // not going to work, but very close
        }
      }
      break;
    default:
      retval += " UNKNOWN";
      break;
  }

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

  return retval;
}
 
Example 10
Source File: GetTableNames.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
void processIncludeTable( Object[] outputRow )
  throws KettleDatabaseException, KettleStepException, KettleValueException {
  if ( meta.isIncludeTable() ) {
    // Tables

    String[] tableNames = data.db.getTablenames( data.realSchemaName, meta.isAddSchemaInOut() );
    String[] tableNamesWithoutSchema = data.db.getTablenames( data.realSchemaName, false );

    String ObjectType = BaseMessages.getString( PKG, "GetTableNamesDialog.ObjectType.Table" );

    for ( int i = 0; i < tableNames.length && !isStopped(); i++ ) {
      Object[] outputRowTable = outputRow.clone();

      int outputIndex = data.totalpreviousfields;

      String tableName = tableNames[i];
      String tableNameWithoutSchema = tableNamesWithoutSchema[i];
      outputRowTable[outputIndex++] = tableName;

      if ( !Utils.isEmpty( data.realObjectTypeFieldName ) ) {
        outputRowTable[outputIndex++] = ObjectType;
      }
      if ( !Utils.isEmpty( data.realIsSystemObjectFieldName ) ) {
        outputRowTable[outputIndex++] = Boolean.valueOf( data.db.isSystemTable( tableNameWithoutSchema ) );
      }
      // Get primary key
      String pk = null;
      String[] pkc = data.db.getPrimaryKeyColumnNames( tableNameWithoutSchema );
      if ( pkc != null && pkc.length == 1 ) {
        pk = pkc[0];
      }
      // return sql creation
      // handle simple primary key (one field)
      String sql =
        data.db
          .getCreateTableStatement(
            tableName,
            data.db.getTableFieldsMeta( data.realSchemaName, tableNameWithoutSchema ),
            null, false, pk, true );

      if ( pkc != null && pkc.length > 0 ) {
        // add composite primary key (several fields in primary key)
        int IndexOfLastClosedBracket = sql.lastIndexOf( ")" );
        if ( IndexOfLastClosedBracket > -1 ) {
          sql = sql.substring( 0, IndexOfLastClosedBracket );
          sql += ", PRIMARY KEY (";
          for ( int k = 0; k < pkc.length; k++ ) {
            if ( k > 0 ) {
              sql += ", ";
            }
            sql += pkc[k];
          }
          sql += ")" + Const.CR + ")" + Const.CR + ";";
        }
      }
      if ( !Utils.isEmpty( data.realSQLCreationFieldName ) ) {
        outputRowTable[outputIndex++] = sql;
      }

      data.rownr++;
      putRow( data.outputRowMeta, outputRowTable ); // copy row to output rowset(s);

      logInfo( outputRowTable );
    }
  }
}
 
Example 11
Source File: MonetDBBulkLoader.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public boolean init( StepMetaInterface smi, StepDataInterface sdi ) {
  meta = (MonetDBBulkLoaderMeta) smi;
  data = (MonetDBBulkLoaderData) sdi;

  if ( super.init( smi, sdi ) ) {

    try {
      verifyDatabaseConnection();
    } catch ( KettleException ex ) {
      logError( ex.getMessage() );
      return false;
    }

    data.quote = environmentSubstitute( meta.getFieldEnclosure() );
    data.separator = environmentSubstitute( meta.getFieldSeparator() );

    String nulls = environmentSubstitute( meta.getNULLrepresentation() );
    if ( nulls == null ) {
      data.nullrepresentation = new String();
    } else {
      data.nullrepresentation = nulls;
    }
    data.newline = Const.CR;

    String encoding = environmentSubstitute( meta.getEncoding() );

    data.monetDateMeta = new ValueMetaDate( "dateMeta" );
    data.monetDateMeta.setConversionMask( "yyyy/MM/dd" );
    data.monetDateMeta.setStringEncoding( encoding );

    data.monetTimestampMeta = new ValueMetaDate( "timestampMeta" );
    data.monetTimestampMeta.setConversionMask( "yyyy/MM/dd HH:mm:ss" );
    data.monetTimestampMeta.setStringEncoding( encoding );

    data.monetTimeMeta = new ValueMetaDate( "timeMeta" );
    data.monetTimeMeta.setConversionMask( "HH:mm:ss" );
    data.monetTimeMeta.setStringEncoding( encoding );

    data.monetNumberMeta = new ValueMetaNumber( "numberMeta" );
    data.monetNumberMeta.setConversionMask( "#.#" );
    data.monetNumberMeta.setGroupingSymbol( "," );
    data.monetNumberMeta.setDecimalSymbol( "." );
    data.monetNumberMeta.setStringEncoding( encoding );

    data.bufferSize = Const.toInt( environmentSubstitute( meta.getBufferSize() ), 100000 );

    // Allocate the buffer
    //
    data.rowBuffer = new String[data.bufferSize]; // new byte[data.bufferSize][];
    data.bufferIndex = 0;

    // Make sure our database connection settings are consistent with our dialog settings by
    // altering the connection with an updated answer depending on the dialog setting.
    meta.getDatabaseMeta().setQuoteAllFields(  meta.isFullyQuoteSQL() );

    // Support parameterized database connection names
    String connectionName = meta.getDbConnectionName();
    if ( !Utils.isEmpty( connectionName ) && connectionName.startsWith( "${" ) && connectionName.endsWith( "}" ) ) {
      meta.setDatabaseMeta( localTransMeta.findDatabase( environmentSubstitute( connectionName ) ) );
    }

    // Schema-table combination...
    data.schemaTable =
        meta.getDatabaseMeta( this ).getQuotedSchemaTableCombination(
            environmentSubstitute( meta.getSchemaName() ), environmentSubstitute( meta.getTableName() ) );

    return true;
  }
  return false;
}
 
Example 12
Source File: CombinationLookup.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Preload the cache
 *
 * @param hashRowMeta The RowMeta of the hashRow
 * @throws KettleDatabaseException If something went wrong while selecting the values from the db
 * @throws KettleValueException    If something went wrong while adding the data to the cache
 * @throws KettleConfigException   If the step configuration is incomplete
 * @author nwyrwa
 */
private void preloadCache( RowMetaInterface hashRowMeta )
  throws KettleDatabaseException, KettleValueException, KettleConfigException {
  // fast exit if no preload cache or no cache
  if ( meta.getPreloadCache() && meta.getCacheSize() >= 0 ) {
    if ( hashRowMeta == null ) {
      throw new KettleConfigException( BaseMessages.getString( PKG, "CombinationLookup.Log.UnexpectedError" ) );
    }
    DatabaseMeta databaseMeta = meta.getDatabaseMeta();
    if ( databaseMeta == null ) {
      throw new KettleConfigException( BaseMessages.getString( PKG, "CombinationLookup.Log.UnexpectedError" ) );
    }
    String lookupKeys = "";
    String sql = "";
    List<Object[]> cacheValues;

    /* build SQl Statement to preload cache
     *
         * SELECT
         * min(<retval>) as <retval>,
         * key1,
         * key2,
         * key3
         * FROM   <table>
         *
         * GROUP BY key1,
         * key2,
         * key3;
         *
         */

    // Build a string representation of the lookupKeys
    for ( int i = 0; i < meta.getKeyLookup().length; i++ ) {
      lookupKeys += databaseMeta.quoteField( meta.getKeyLookup()[ i ] );

      // No comma after last field
      if ( i < meta.getKeyLookup().length - 1 ) {
        lookupKeys += "," + Const.CR;
      }
    }

    // Use min in case of disambiguation
    sql += "SELECT " + Const.CR;
    sql += "MIN(" + databaseMeta.quoteField( meta.getTechnicalKeyField() ) + ") as "
      + databaseMeta.quoteField( meta.getTechnicalKeyField() ) + "," + Const.CR;
    sql += lookupKeys + Const.CR;
    sql += "FROM " + data.schemaTable + Const.CR;
    sql += "GROUP BY" + Const.CR;
    sql += lookupKeys + Const.CR;

    if ( log.isDebug() ) {
      logDebug( "Using preload cache statement:" + Const.CR + sql );
    }
    cacheValues = data.db.getRows( databaseMeta.stripCR( sql ), meta.getCacheSize() );
    for ( Object[] cacheRow : cacheValues ) {
      // Create a correctly structured array for the cache
      Object[] hashRow = new Object[ data.hashRowMeta.size() ];
      // Assumes the technical key is at position 0 !!
      System.arraycopy( cacheRow, 1, hashRow, 0, hashRow.length );
      // Potential Cache Overflow is ahndled inside
      addToCache( hashRowMeta, hashRow, (Long) cacheRow[ 0 ] );
      incrementLinesInput();
    }

  }

}
 
Example 13
Source File: UniqueRowsDialog.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private void ok() {
  if ( Utils.isEmpty( wStepname.getText() ) ) {
    return;
  }

  int nrfields = wFields.nrNonEmpty();
  input.allocate( nrfields );

  //CHECKSTYLE:Indentation:OFF
  for ( int i = 0; i < nrfields; i++ ) {
    TableItem item = wFields.getNonEmpty( i );
    input.getCompareFields()[i] = item.getText( 1 );
    input.getCaseInsensitive()[i] = "Y".equalsIgnoreCase( item.getText( 2 ) );
  }

  input.setCountField( wCountField.getText() );
  input.setCountRows( wCount.getSelection() );
  input.setRejectDuplicateRow( wRejectDuplicateRow.getSelection() );
  input.setErrorDescription( wErrorDesc.getText() );
  stepname = wStepname.getText(); // return value

  if ( "Y".equalsIgnoreCase( props.getCustomParameter( STRING_SORT_WARNING_PARAMETER, "Y" ) ) ) {
    MessageDialogWithToggle md = new MessageDialogWithToggle( shell,
      BaseMessages.getString( PKG, "UniqueRowsDialog.InputNeedSort.DialogTitle" ),
      null,
      BaseMessages.getString( PKG, "UniqueRowsDialog.InputNeedSort.DialogMessage", Const.CR ) + Const.CR,
      MessageDialog.WARNING,
      new String[] { BaseMessages.getString( PKG, "UniqueRowsDialog.InputNeedSort.Option1" ) },
      0,
      BaseMessages.getString( PKG, "UniqueRowsDialog.InputNeedSort.Option2" ),
      "N".equalsIgnoreCase( props.getCustomParameter( STRING_SORT_WARNING_PARAMETER, "Y" ) ) );
    MessageDialogWithToggle.setDefaultImage( GUIResource.getInstance().getImageSpoon() );
    md.open();
    props.setCustomParameter( STRING_SORT_WARNING_PARAMETER, md.getToggleState() ? "N" : "Y" );
    props.saveProps();
  }

  // Remove any error hops coming out of UniqueRows when Reject Duplicate Rows checkbox is unselected.
  if ( wRejectDuplicateRow.getSelection() == false ) {
    List<TransHopMeta> hops = this.transMeta.getTransHops();
    IntStream.range( 0, hops.size() )
      .filter( hopInd -> {
        TransHopMeta hop = hops.get( hopInd );
        return (
          hop.isErrorHop()
          && hop.getFromStep().getName().equals( this.input.getParentStepMeta().getName() ) );
      } )
      .forEach( hopInd -> this.transMeta.removeTransHop( hopInd ) );
  }

  dispose();
}
 
Example 14
Source File: MSAccessDatabaseMeta.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 ) {
    retval += fieldname + " ";
  }

  int type = v.getType();
  switch ( type ) {
    case ValueMetaInterface.TYPE_TIMESTAMP:
    case ValueMetaInterface.TYPE_DATE:
      retval += "DATETIME";
      break;
    // Move back to Y/N for bug - [# 1538] Repository on MS ACCESS: error creating repository
    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
      ) {
        if ( useAutoinc ) {
          retval += "COUNTER PRIMARY KEY";
        } else {
          retval += "LONG PRIMARY KEY";
        }
      } else {
        if ( precision == 0 ) {
          if ( length > 9 ) {
            retval += "DOUBLE";
          } else {
            if ( length > 5 ) {
              retval += "LONG";
            } else {
              retval += "INTEGER";
            }
          }
        } else {
          retval += "DOUBLE";
        }
      }
      break;
    case ValueMetaInterface.TYPE_STRING:
      if ( length > 0 ) {
        if ( length < 256 ) {
          retval += "TEXT(" + length + ")";
        } else {
          retval += "MEMO";
        }
      } else {
        retval += "TEXT";
      }
      break;
    case ValueMetaInterface.TYPE_BINARY:
      retval += " LONGBINARY";
      break;
    default:
      retval += " UNKNOWN";
      break;
  }

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

  return retval;
}
 
Example 15
Source File: DB2DatabaseMeta.java    From pentaho-kettle with Apache License 2.0 3 votes vote down vote up
/**
 * Generates the SQL statement to modify a column in the specified table
 *
 * @param tablename
 *          The table to add
 * @param v
 *          The column defined as a value
 * @param tk
 *          the name of the technical key field
 * @param useAutoinc
 *          whether or not this field uses auto increment
 * @param pk
 *          the name of the primary key field
 * @param semicolon
 *          whether or not to add a semi-colon behind the statement.
 * @return the SQL statement to modify a column in the specified table
 */
@Override
public String getModifyColumnStatement( String tablename, ValueMetaInterface v, String tk, boolean useAutoinc,
  String pk, boolean semicolon ) {
  String retval = "";
  retval += "ALTER TABLE " + tablename + " DROP COLUMN " + v.getName() + Const.CR + ";" + Const.CR;
  retval +=
    "ALTER TABLE " + tablename + " ADD COLUMN " + getFieldDefinition( v, tk, pk, useAutoinc, true, false );
  return retval;
}
 
Example 16
Source File: KingbaseESDatabaseMeta.java    From pentaho-kettle with Apache License 2.0 3 votes vote down vote up
/**
 * Generates the SQL statement to modify a column in the specified table
 *
 * @param tablename
 *          The table to add
 * @param v
 *          The column defined as a value
 * @param tk
 *          the name of the technical key field
 * @param useAutoinc
 *          whether or not this field uses auto increment
 * @param pk
 *          the name of the primary key field
 * @param semicolon
 *          whether or not to add a semi-colon behind the statement.
 * @return the SQL statement to modify a column in the specified table
 */
@Override
public String getModifyColumnStatement( String tablename, ValueMetaInterface v, String tk, boolean useAutoinc,
  String pk, boolean semicolon ) {
  String retval = "";
  retval += "ALTER TABLE " + tablename + " DROP COLUMN " + v.getName() + Const.CR + ";" + Const.CR;
  retval +=
    "ALTER TABLE " + tablename + " ADD COLUMN " + getFieldDefinition( v, tk, pk, useAutoinc, true, false );
  return retval;
}
 
Example 17
Source File: ExtenDBDatabaseMeta.java    From pentaho-kettle with Apache License 2.0 3 votes vote down vote up
/**
 * Generates the SQL statement to modify a column in the specified table
 *
 * @param tablename
 *          The table to add
 * @param v
 *          The column defined as a value
 * @param tk
 *          the name of the technical key field
 * @param useAutoinc
 *          whether or not this field uses auto increment
 * @param pk
 *          the name of the primary key field
 * @param semicolon
 *          whether or not to add a semi-colon behind the statement.
 * @return the SQL statement to modify a column in the specified table
 */
@Override
public String getModifyColumnStatement( String tablename, ValueMetaInterface v, String tk, boolean useAutoinc,
  String pk, boolean semicolon ) {
  String retval = "";
  retval += "ALTER TABLE " + tablename + " DROP " + v.getName() + Const.CR + ";" + Const.CR;
  retval += "ALTER TABLE " + tablename + " ADD " + getFieldDefinition( v, tk, pk, useAutoinc, true, false );
  return retval;
}
 
Example 18
Source File: MSAccessDatabaseMeta.java    From pentaho-kettle with Apache License 2.0 2 votes vote down vote up
/**
 * Generates the SQL statement to drop a column from the specified table
 *
 * @param tablename
 *          The table to add
 * @param v
 *          The column defined as a value
 * @param tk
 *          the name of the technical key field
 * @param useAutoinc
 *          whether or not this field uses auto increment
 * @param pk
 *          the name of the primary key field
 * @param semicolon
 *          whether or not to add a semi-colon behind the statement.
 * @return the SQL statement to drop a column from the specified table
 */
@Override
public String getDropColumnStatement( String tablename, ValueMetaInterface v, String tk, boolean useAutoinc,
  String pk, boolean semicolon ) {
  return "ALTER TABLE " + tablename + " DROP COLUMN " + v.getName() + Const.CR;
}
 
Example 19
Source File: NeoviewDatabaseMeta.java    From pentaho-kettle with Apache License 2.0 2 votes vote down vote up
/**
 * Generates the SQL statement to drop a column from the specified table
 *
 * @param tablename
 *          The table to add
 * @param v
 *          The column defined as a value
 * @param tk
 *          the name of the technical key field
 * @param useAutoinc
 *          whether or not this field uses auto increment
 * @param pk
 *          the name of the primary key field
 * @param semicolon
 *          whether or not to add a semi-colon behind the statement.
 * @return the SQL statement to drop a column from the specified table
 */
@Override
public String getDropColumnStatement( String tablename, ValueMetaInterface v, String tk, boolean useAutoinc,
  String pk, boolean semicolon ) {
  return "ALTER TABLE " + tablename + " DROP ( " + v.getName() + " ) " + Const.CR;
}
 
Example 20
Source File: XMLHandler.java    From pentaho-kettle with Apache License 2.0 2 votes vote down vote up
/**
 * The header string to specify encoding in an XML file
 *
 * @param encoding The desired encoding to use in the XML file
 * @return The XML header.
 */
public static String getXMLHeader( String encoding ) {
  return "<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>" + Const.CR;
}