Java Code Examples for org.pentaho.di.core.database.Database#getDDL()

The following examples show how to use org.pentaho.di.core.database.Database#getDDL() . 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: SQLFileOutputMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public SQLStatement getSQLStatements( TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev,
  Repository repository, IMetaStore metaStore ) {
  SQLStatement retval = new SQLStatement( stepMeta.getName(), databaseMeta, null ); // default: nothing to do!

  if ( databaseMeta != null ) {
    if ( prev != null && prev.size() > 0 ) {
      if ( !Utils.isEmpty( tablename ) ) {
        Database db = new Database( loggingObject, databaseMeta );
        db.shareVariablesWith( transMeta );
        try {
          db.connect();

          String schemaTable = databaseMeta.getQuotedSchemaTableCombination( schemaName, tablename );
          String cr_table = db.getDDL( schemaTable, prev );

          // Empty string means: nothing to do: set it to null...
          if ( cr_table == null || cr_table.length() == 0 ) {
            cr_table = null;
          }

          retval.setSQL( cr_table );
        } catch ( KettleDatabaseException dbe ) {
          retval.setError( BaseMessages.getString( PKG, "SQLFileOutputMeta.Error.ErrorConnecting", dbe
            .getMessage() ) );
        } finally {
          db.disconnect();
        }
      } else {
        retval.setError( BaseMessages.getString( PKG, "SQLFileOutputMeta.Exception.TableNotSpecified" ) );
      }
    } else {
      retval.setError( BaseMessages.getString( PKG, "SQLFileOutputMeta.Error.NoInput" ) );
    }
  } else {
    retval.setError( BaseMessages.getString( PKG, "SQLFileOutputMeta.Error.NoConnection" ) );
  }

  return retval;
}
 
Example 2
Source File: TableOutputMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public SQLStatement getSQLStatements( TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, String tk,
                                      boolean use_autoinc, String pk ) {
  SQLStatement retval = new SQLStatement( stepMeta.getName(), databaseMeta, null ); // default: nothing to do!

  if ( databaseMeta != null ) {
    if ( prev != null && prev.size() > 0 ) {
      if ( !Utils.isEmpty( tableName ) ) {
        Database db = new Database( loggingObject, databaseMeta );
        db.shareVariablesWith( transMeta );
        try {
          db.connect();

          String schemaTable = databaseMeta.getQuotedSchemaTableCombination( schemaName, tableName );
          String cr_table = db.getDDL( schemaTable, prev, tk, use_autoinc, pk );

          // Empty string means: nothing to do: set it to null...
          if ( cr_table == null || cr_table.length() == 0 ) {
            cr_table = null;
          }

          retval.setSQL( cr_table );
        } catch ( KettleDatabaseException dbe ) {
          retval.setError( BaseMessages.getString( PKG, "TableOutputMeta.Error.ErrorConnecting", dbe
            .getMessage() ) );
        } finally {
          db.disconnect();
        }
      } else {
        retval.setError( BaseMessages.getString( PKG, "TableOutputMeta.Error.NoTable" ) );
      }
    } else {
      retval.setError( BaseMessages.getString( PKG, "TableOutputMeta.Error.NoInput" ) );
    }
  } else {
    retval.setError( BaseMessages.getString( PKG, "TableOutputMeta.Error.NoConnection" ) );
  }

  return retval;
}
 
Example 3
Source File: InsertUpdateMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public SQLStatement getSQLStatements( TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev,
    Repository repository, IMetaStore metaStore ) throws KettleStepException {
  SQLStatement retval = new SQLStatement( stepMeta.getName(), databaseMeta, null ); // default: nothing to do!

  if ( databaseMeta != null ) {
    if ( prev != null && prev.size() > 0 ) {
      // Copy the row
      RowMetaInterface tableFields = RowMetaUtils.getRowMetaForUpdate( prev, keyLookup,
          keyStream, updateLookup, updateStream );

      if ( !Utils.isEmpty( tableName ) ) {
        Database db = new Database( loggingObject, databaseMeta );
        db.shareVariablesWith( transMeta );
        try {
          db.connect();

          String schemaTable = databaseMeta.getQuotedSchemaTableCombination( schemaName, tableName );
          String cr_table = db.getDDL( schemaTable, tableFields, null, false, null, true );

          String cr_index = "";
          String[] idx_fields = null;

          if ( keyLookup != null && keyLookup.length > 0 ) {
            idx_fields = new String[keyLookup.length];
            for ( int i = 0; i < keyLookup.length; i++ ) {
              idx_fields[i] = keyLookup[i];
            }
          } else {
            retval.setError( BaseMessages.getString( PKG, "InsertUpdateMeta.CheckResult.MissingKeyFields" ) );
          }

          // Key lookup dimensions...
          if ( idx_fields != null
              && idx_fields.length > 0 && !db.checkIndexExists( schemaName, tableName, idx_fields ) ) {
            String indexname = "idx_" + tableName + "_lookup";
            cr_index =
              db.getCreateIndexStatement( schemaTable, indexname, idx_fields, false, false, false, true );
          }

          String sql = cr_table + cr_index;
          if ( sql.length() == 0 ) {
            retval.setSQL( null );
          } else {
            retval.setSQL( sql );
          }
        } catch ( KettleException e ) {
          retval.setError( BaseMessages.getString( PKG, "InsertUpdateMeta.ReturnValue.ErrorOccurred" )
              + e.getMessage() );
        }
      } else {
        retval
          .setError( BaseMessages.getString( PKG, "InsertUpdateMeta.ReturnValue.NoTableDefinedOnConnection" ) );
      }
    } else {
      retval.setError( BaseMessages.getString( PKG, "InsertUpdateMeta.ReturnValue.NotReceivingAnyFields" ) );
    }
  } else {
    retval.setError( BaseMessages.getString( PKG, "InsertUpdateMeta.ReturnValue.NoConnectionDefined" ) );
  }

  return retval;
}
 
Example 4
Source File: PGBulkLoaderMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public SQLStatement getSQLStatements( TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev,
  Repository repository, IMetaStore metaStore ) throws KettleStepException {
  SQLStatement retval = new SQLStatement( stepMeta.getName(), databaseMeta, null ); // default: nothing to do!

  if ( databaseMeta != null ) {
    if ( prev != null && prev.size() > 0 ) {
      // Copy the row
      RowMetaInterface tableFields = new RowMeta();

      // Now change the field names
      for ( int i = 0; i < fieldTable.length; i++ ) {
        ValueMetaInterface v = prev.searchValueMeta( fieldStream[i] );
        if ( v != null ) {
          ValueMetaInterface tableField = v.clone();
          tableField.setName( fieldTable[i] );
          tableFields.addValueMeta( tableField );
        } else {
          throw new KettleStepException( "Unable to find field [" + fieldStream[i] + "] in the input rows" );
        }
      }

      if ( !Utils.isEmpty( tableName ) ) {
        Database db = new Database( loggingObject, databaseMeta );
        db.shareVariablesWith( transMeta );
        try {
          db.connect();

          String schemaTable =
            databaseMeta.getQuotedSchemaTableCombination(
              transMeta.environmentSubstitute( schemaName ), transMeta.environmentSubstitute( tableName ) );
          String sql = db.getDDL( schemaTable, tableFields, null, false, null, true );

          if ( sql.length() == 0 ) {
            retval.setSQL( null );
          } else {
            retval.setSQL( sql );
          }
        } catch ( KettleException e ) {
          retval.setError( BaseMessages.getString( PKG, "GPBulkLoaderMeta.GetSQL.ErrorOccurred" )
            + e.getMessage() );
        }
      } else {
        retval.setError( BaseMessages.getString( PKG, "GPBulkLoaderMeta.GetSQL.NoTableDefinedOnConnection" ) );
      }
    } else {
      retval.setError( BaseMessages.getString( PKG, "GPBulkLoaderMeta.GetSQL.NotReceivingAnyFields" ) );
    }
  } else {
    retval.setError( BaseMessages.getString( PKG, "GPBulkLoaderMeta.GetSQL.NoConnectionDefined" ) );
  }

  return retval;
}
 
Example 5
Source File: DeleteMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public SQLStatement getSQLStatements( TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev,
  Repository repository, IMetaStore metaStore ) {
  SQLStatement retval = new SQLStatement( stepMeta.getName(), databaseMeta, null ); // default: nothing to do!

  if ( databaseMeta != null ) {
    if ( prev != null && prev.size() > 0 ) {
      if ( !Utils.isEmpty( tableName ) ) {
        Database db = new Database( loggingObject, databaseMeta );
        db.shareVariablesWith( transMeta );
        try {
          db.connect();

          String schemaTable = databaseMeta.getQuotedSchemaTableCombination( schemaName, tableName );
          String cr_table = db.getDDL( schemaTable, prev, null, false, null, true );

          String cr_index = "";
          String[] idx_fields = null;

          if ( keyLookup != null && keyLookup.length > 0 ) {
            idx_fields = new String[keyLookup.length];
            for ( int i = 0; i < keyLookup.length; i++ ) {
              idx_fields[i] = keyLookup[i];
            }
          } else {
            retval.setError( BaseMessages.getString( PKG, "DeleteMeta.CheckResult.KeyFieldsRequired" ) );
          }

          // Key lookup dimensions...
          if ( idx_fields != null && idx_fields.length > 0 && !db.checkIndexExists( schemaTable, idx_fields ) ) {
            String indexname = "idx_" + tableName + "_lookup";
            cr_index =
              db.getCreateIndexStatement(
                schemaName, tableName, indexname, idx_fields, false, false, false, true );
          }

          String sql = cr_table + cr_index;
          if ( sql.length() == 0 ) {
            retval.setSQL( null );
          } else {
            retval.setSQL( sql );
          }
        } catch ( KettleException e ) {
          retval.setError( BaseMessages.getString( PKG, "DeleteMeta.Returnvalue.ErrorOccurred" )
            + e.getMessage() );
        }
      } else {
        retval.setError( BaseMessages.getString( PKG, "DeleteMeta.Returnvalue.NoTableDefinedOnConnection" ) );
      }
    } else {
      retval.setError( BaseMessages.getString( PKG, "DeleteMeta.Returnvalue.NoReceivingAnyFields" ) );
    }
  } else {
    retval.setError( BaseMessages.getString( PKG, "DeleteMeta.Returnvalue.NoConnectionDefined" ) );
  }

  return retval;
}
 
Example 6
Source File: UpdateMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public SQLStatement getSQLStatements( TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev,
  Repository repository, IMetaStore metaStore ) throws KettleStepException  {
  SQLStatement retval = new SQLStatement( stepMeta.getName(), databaseMeta, null ); // default: nothing to do!

  if ( databaseMeta != null ) {
    if ( prev != null && prev.size() > 0 ) {
      // Copy the row
      RowMetaInterface tableFields = RowMetaUtils.getRowMetaForUpdate( prev, keyLookup, keyStream,
          updateLookup, updateStream );
      if ( !Utils.isEmpty( tableName ) ) {
        String schemaTable = databaseMeta.getQuotedSchemaTableCombination( schemaName, tableName );

        Database db = new Database( loggingObject, databaseMeta );
        db.shareVariablesWith( transMeta );
        try {
          db.connect();

          if ( getIgnoreFlagField() != null && getIgnoreFlagField().length() > 0 ) {
            prev.addValueMeta( new ValueMetaBoolean( getIgnoreFlagField() ) );
          }

          String cr_table = db.getDDL( schemaTable, tableFields, null, false, null, true );

          String cr_index = "";
          String[] idx_fields = null;

          if ( keyLookup != null && keyLookup.length > 0 ) {
            idx_fields = new String[keyLookup.length];
            for ( int i = 0; i < keyLookup.length; i++ ) {
              idx_fields[i] = keyLookup[i];
            }
          } else {
            retval.setError( BaseMessages.getString( PKG, "UpdateMeta.CheckResult.MissingKeyFields" ) );
          }

          // Key lookup dimensions...
          if ( idx_fields != null
            && idx_fields.length > 0 && !db.checkIndexExists( schemaTable, idx_fields ) ) {
            String indexname = "idx_" + tableName + "_lookup";
            cr_index =
              db.getCreateIndexStatement(
                schemaTable, indexname, idx_fields, false, false, false, true );
          }

          String sql = cr_table + cr_index;
          if ( sql.length() == 0 ) {
            retval.setSQL( null );
          } else {
            retval.setSQL( sql );
          }
        } catch ( KettleException e ) {
          retval.setError( BaseMessages.getString( PKG, "UpdateMeta.ReturnValue.ErrorOccurred" )
            + e.getMessage() );
        }
      } else {
        retval.setError( BaseMessages.getString( PKG, "UpdateMeta.ReturnValue.NoTableDefinedOnConnection" ) );
      }
    } else {
      retval.setError( BaseMessages.getString( PKG, "UpdateMeta.ReturnValue.NotReceivingAnyFields" ) );
    }
  } else {
    retval.setError( BaseMessages.getString( PKG, "UpdateMeta.ReturnValue.NoConnectionDefined" ) );
  }

  return retval;
}
 
Example 7
Source File: IngresVectorwiseLoaderMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public SQLStatement getSQLStatements( TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev,
  Repository repository, IMetaStore metaStore ) {
  SQLStatement retval = new SQLStatement( stepMeta.getName(), databaseMeta, null ); // default:
                                                                                    // nothing
                                                                                    // to
                                                                                    // do!

  if ( databaseMeta != null ) {
    if ( prev != null && prev.size() > 0 ) {
      if ( !Utils.isEmpty( tablename ) ) {
        Database db = new Database( loggingObject, databaseMeta );
        db.shareVariablesWith( transMeta );
        try {
          db.connect();

          String schemaTable = databaseMeta.getQuotedSchemaTableCombination( null, tablename );
          String cr_table = db.getDDL( schemaTable, prev );

          // Squeeze in the VECTORWISE col store clause...
          // TODO: move this to the database dialog and make it user
          // configurable.
          //
          String VW_CLAUSE = "WITH STRUCTURE=VECTORWISE";

          if ( cr_table.toUpperCase().contains( "CREATE TABLE" ) ) {
            int scIndex = cr_table.indexOf( ';' );
            if ( scIndex < 0 ) {
              cr_table += VW_CLAUSE;
            } else {
              cr_table = cr_table.substring( 0, scIndex ) + VW_CLAUSE + cr_table.substring( scIndex );
            }
          }

          // Empty string means: nothing to do: set it to null...
          if ( cr_table == null || cr_table.length() == 0 ) {
            cr_table = null;
          }

          retval.setSQL( cr_table );
        } catch ( KettleDatabaseException dbe ) {
          retval.setError( BaseMessages.getString( PKG, "IngresVectorWiseLoaderMeta.Error.ErrorConnecting", dbe
            .getMessage() ) );
        } finally {
          db.disconnect();
        }
      } else {
        retval.setError( BaseMessages.getString( PKG, "IngresVectorWiseLoaderMeta.Error.NoTable" ) );
      }
    } else {
      retval.setError( BaseMessages.getString( PKG, "IngresVectorWiseLoaderMeta.Error.NoInput" ) );
    }
  } else {
    retval.setError( BaseMessages.getString( PKG, "IngresVectorWiseLoaderMeta.Error.NoConnection" ) );
  }

  return retval;
}
 
Example 8
Source File: OraBulkLoaderMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public SQLStatement getSQLStatements( TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev,
  Repository repository, IMetaStore metaStore ) throws KettleStepException {
  SQLStatement retval = new SQLStatement( stepMeta.getName(), databaseMeta, null ); // default: nothing to do!

  if ( databaseMeta != null ) {
    if ( prev != null && prev.size() > 0 ) {
      // Copy the row
      RowMetaInterface tableFields = new RowMeta();

      // Now change the field names
      for ( int i = 0; i < fieldTable.length; i++ ) {
        ValueMetaInterface v = prev.searchValueMeta( fieldStream[i] );
        if ( v != null ) {
          ValueMetaInterface tableField = v.clone();
          tableField.setName( fieldTable[i] );
          tableFields.addValueMeta( tableField );
        } else {
          throw new KettleStepException( "Unable to find field [" + fieldStream[i] + "] in the input rows" );
        }
      }

      if ( !Utils.isEmpty( tableName ) ) {
        Database db = new Database( loggingObject, databaseMeta );
        db.shareVariablesWith( transMeta );
        try {
          db.connect();

          String schemaTable =
            databaseMeta.getQuotedSchemaTableCombination(
              transMeta.environmentSubstitute( schemaName ), transMeta.environmentSubstitute( tableName ) );
          String sql = db.getDDL( schemaTable, tableFields, null, false, null, true );

          if ( sql.length() == 0 ) {
            retval.setSQL( null );
          } else {
            retval.setSQL( sql );
          }
        } catch ( KettleException e ) {
          retval.setError( BaseMessages.getString( PKG, "OraBulkLoaderMeta.GetSQL.ErrorOccurred" )
            + e.getMessage() );
        }
      } else {
        retval.setError( BaseMessages.getString( PKG, "OraBulkLoaderMeta.GetSQL.NoTableDefinedOnConnection" ) );
      }
    } else {
      retval.setError( BaseMessages.getString( PKG, "OraBulkLoaderMeta.GetSQL.NotReceivingAnyFields" ) );
    }
  } else {
    retval.setError( BaseMessages.getString( PKG, "OraBulkLoaderMeta.GetSQL.NoConnectionDefined" ) );
  }

  return retval;
}
 
Example 9
Source File: MySQLBulkLoaderMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public SQLStatement getSQLStatements( TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev,
    Repository repository, IMetaStore metaStore ) throws KettleStepException {
  SQLStatement retval = new SQLStatement( stepMeta.getName(), databaseMeta, null ); // default: nothing to do!

  if ( databaseMeta != null ) {
    if ( prev != null && prev.size() > 0 ) {
      // Copy the row
      RowMetaInterface tableFields = new RowMeta();

      // Now change the field names
      for ( int i = 0; i < fieldTable.length; i++ ) {
        ValueMetaInterface v = prev.searchValueMeta( fieldStream[i] );
        if ( v != null ) {
          ValueMetaInterface tableField = v.clone();
          tableField.setName( fieldTable[i] );
          tableFields.addValueMeta( tableField );
        } else {
          throw new KettleStepException( "Unable to find field [" + fieldStream[i] + "] in the input rows" );
        }
      }

      if ( !Utils.isEmpty( tableName ) ) {
        Database db = new Database( loggingObject, databaseMeta );
        db.shareVariablesWith( transMeta );
        try {
          db.connect();

          String schemaTable =
              databaseMeta.getQuotedSchemaTableCombination( transMeta.environmentSubstitute( schemaName ), transMeta
                  .environmentSubstitute( tableName ) );
          String cr_table = db.getDDL( schemaTable, tableFields, null, false, null, true );

          String sql = cr_table;
          if ( sql.length() == 0 ) {
            retval.setSQL( null );
          } else {
            retval.setSQL( sql );
          }
        } catch ( KettleException e ) {
          retval
              .setError( BaseMessages.getString( PKG, "MySQLBulkLoaderMeta.GetSQL.ErrorOccurred" ) + e.getMessage() );
        }
      } else {
        retval.setError( BaseMessages.getString( PKG, "MySQLBulkLoaderMeta.GetSQL.NoTableDefinedOnConnection" ) );
      }
    } else {
      retval.setError( BaseMessages.getString( PKG, "MySQLBulkLoaderMeta.GetSQL.NotReceivingAnyFields" ) );
    }
  } else {
    retval.setError( BaseMessages.getString( PKG, "MySQLBulkLoaderMeta.GetSQL.NoConnectionDefined" ) );
  }

  return retval;
}
 
Example 10
Source File: LucidDBStreamingLoaderMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public SQLStatement getSQLStatements( TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev,
  Repository repository, IMetaStore metaStore ) throws KettleStepException {

  SQLStatement retval = super.getSQLStatements( transMeta, stepMeta, prev, repository, metaStore );

  if ( databaseMeta != null ) {
    if ( prev != null && prev.size() > 0 ) {
      String schemaTable =
        databaseMeta.getQuotedSchemaTableCombination( transMeta.environmentSubstitute( schemaName ), transMeta
          .environmentSubstitute( tableName ) );

      if ( !Utils.isEmpty( schemaTable ) ) {
        Database db = new Database( loggingObject, databaseMeta );
        db.shareVariablesWith( transMeta );
        try {
          db.connect();

          String cr_table = db.getDDL( schemaTable, prev );

          // Empty string means: nothing to do: set it to null...
          if ( cr_table == null || cr_table.length() == 0 ) {
            cr_table = null;
          }

          retval.setSQL( cr_table );
        } catch ( KettleDatabaseException dbe ) {
          retval.setError( BaseMessages.getString( PKG, "LucidDBStreamingLoaderMeta.Error.ErrorConnecting", dbe
            .getMessage() ) );
        } finally {
          db.disconnect();
        }
      } else {
        retval.setError( BaseMessages.getString( PKG, "LucidDBStreamingLoaderMeta.Error.NoTable" ) );
      }
    } else {
      retval.setError( BaseMessages.getString( PKG, "LucidDBStreamingLoaderMeta.Error.NoInput" ) );
    }
  } else {
    retval.setError( BaseMessages.getString( PKG, "LucidDBStreamingLoaderMeta.Error.NoConnection" ) );
  }

  return retval;
}
 
Example 11
Source File: GPLoadMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public SQLStatement getSQLStatements( TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev,
    Repository repository, IMetaStore metaStore ) throws KettleStepException {
  SQLStatement retval = new SQLStatement( stepMeta.getName(), databaseMeta, null ); // default: nothing to do!

  if ( databaseMeta != null ) {
    if ( prev != null && prev.size() > 0 ) {
      // Copy the row
      RowMetaInterface tableFields = new RowMeta();

      // Now change the field names
      for ( int i = 0; i < fieldTable.length; i++ ) {
        ValueMetaInterface v = prev.searchValueMeta( fieldStream[i] );
        if ( v != null ) {
          ValueMetaInterface tableField = v.clone();
          tableField.setName( fieldTable[i] );
          tableFields.addValueMeta( tableField );
        } else {
          throw new KettleStepException( "Unable to find field [" + fieldStream[i] + "] in the input rows" );
        }
      }

      if ( !Utils.isEmpty( tableName ) ) {
        Database db = new Database( loggingObject, databaseMeta );
        db.shareVariablesWith( transMeta );
        try {
          db.connect();

          String schemaTable =
              databaseMeta.getQuotedSchemaTableCombination( transMeta.environmentSubstitute( schemaName ), transMeta
                  .environmentSubstitute( tableName ) );
          String sql = db.getDDL( schemaTable, tableFields, null, false, null, true );

          if ( sql.length() == 0 ) {
            retval.setSQL( null );
          } else {
            retval.setSQL( sql );
          }
        } catch ( KettleException e ) {
          retval.setError( BaseMessages.getString( PKG, "GPLoadMeta.GetSQL.ErrorOccurred" ) + e.getMessage() );
        }
      } else {
        retval.setError( BaseMessages.getString( PKG, "GPLoadMeta.GetSQL.NoTableDefinedOnConnection" ) );
      }
    } else {
      retval.setError( BaseMessages.getString( PKG, "GPLoadMeta.GetSQL.NotReceivingAnyFields" ) );
    }
  } else {
    retval.setError( BaseMessages.getString( PKG, "GPLoadMeta.GetSQL.NoConnectionDefined" ) );
  }

  return retval;
}
 
Example 12
Source File: LucidDBBulkLoaderMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public SQLStatement getSQLStatements( TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev,
  Repository repository, IMetaStore metaStore ) throws KettleStepException {
  SQLStatement retval = new SQLStatement( stepMeta.getName(), databaseMeta, null ); // default: nothing to do!

  if ( databaseMeta != null ) {
    if ( prev != null && prev.size() > 0 ) {
      // Copy the row
      RowMetaInterface tableFields = new RowMeta();

      // Now change the field names
      for ( int i = 0; i < fieldTable.length; i++ ) {
        ValueMetaInterface v = prev.searchValueMeta( fieldStream[i] );
        if ( v != null ) {
          ValueMetaInterface tableField = v.clone();
          tableField.setName( fieldTable[i] );
          tableFields.addValueMeta( tableField );
        } else {
          throw new KettleStepException( "Unable to find field [" + fieldStream[i] + "] in the input rows" );
        }
      }

      if ( !Utils.isEmpty( tableName ) ) {
        Database db = new Database( loggingObject, databaseMeta );
        db.shareVariablesWith( transMeta );
        try {
          db.connect();

          String schemaTable =
            databaseMeta.getQuotedSchemaTableCombination(
              transMeta.environmentSubstitute( schemaName ), transMeta.environmentSubstitute( tableName ) );
          String sql = db.getDDL( schemaTable, tableFields, null, false, null, true );

          if ( Utils.isEmpty( sql ) ) {
            retval.setSQL( null );
          } else {
            retval.setSQL( sql );
          }
        } catch ( KettleException e ) {
          retval.setError( BaseMessages.getString( PKG, "LucidDBBulkLoaderMeta.GetSQL.ErrorOccurred" )
            + e.getMessage() );
        }
      } else {
        retval
          .setError( BaseMessages.getString( PKG, "LucidDBBulkLoaderMeta.GetSQL.NoTableDefinedOnConnection" ) );
      }
    } else {
      retval.setError( BaseMessages.getString( PKG, "LucidDBBulkLoaderMeta.GetSQL.NotReceivingAnyFields" ) );
    }
  } else {
    retval.setError( BaseMessages.getString( PKG, "LucidDBBulkLoaderMeta.GetSQL.NoConnectionDefined" ) );
  }

  return retval;
}
 
Example 13
Source File: GPBulkLoaderMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public SQLStatement getSQLStatements( TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev,
  Repository repository, IMetaStore metaStore ) throws KettleStepException {
  SQLStatement retval = new SQLStatement( stepMeta.getName(), databaseMeta, null ); // default: nothing to do!

  if ( databaseMeta != null ) {
    if ( prev != null && prev.size() > 0 ) {
      // Copy the row
      RowMetaInterface tableFields = new RowMeta();

      // Now change the field names
      for ( int i = 0; i < fieldTable.length; i++ ) {
        ValueMetaInterface v = prev.searchValueMeta( fieldStream[i] );
        if ( v != null ) {
          ValueMetaInterface tableField = v.clone();
          tableField.setName( fieldTable[i] );
          tableFields.addValueMeta( tableField );
        } else {
          throw new KettleStepException( "Unable to find field [" + fieldStream[i] + "] in the input rows" );
        }
      }

      if ( !Utils.isEmpty( tableName ) ) {
        Database db = new Database( loggingObject, databaseMeta );
        db.shareVariablesWith( transMeta );
        try {
          db.connect();

          String schemaTable =
            databaseMeta.getQuotedSchemaTableCombination(
              transMeta.environmentSubstitute( schemaName ), transMeta.environmentSubstitute( tableName ) );
          String sql = db.getDDL( schemaTable, tableFields, null, false, null, true );

          if ( sql.length() == 0 ) {
            retval.setSQL( null );
          } else {
            retval.setSQL( sql );
          }
        } catch ( KettleException e ) {
          retval.setError( BaseMessages.getString( PKG, "GPBulkLoaderMeta.GetSQL.ErrorOccurred" )
            + e.getMessage() );
        }
      } else {
        retval.setError( BaseMessages.getString( PKG, "GPBulkLoaderMeta.GetSQL.NoTableDefinedOnConnection" ) );
      }
    } else {
      retval.setError( BaseMessages.getString( PKG, "GPBulkLoaderMeta.GetSQL.NotReceivingAnyFields" ) );
    }
  } else {
    retval.setError( BaseMessages.getString( PKG, "GPBulkLoaderMeta.GetSQL.NoConnectionDefined" ) );
  }

  return retval;
}