Search in sources :

Example 41 with SQLStatement

use of org.pentaho.di.core.SQLStatement in project pentaho-kettle by pentaho.

the class DimensionLookupDialog method create.

// Generate code for create table...
// Conversions done by Database
// For Sybase ASE: don't keep everything in lowercase!
private void create() {
    try {
        DimensionLookupMeta info = new DimensionLookupMeta();
        getInfo(info);
        // new name might not yet be linked to other
        String name = stepname;
        // steps!
        StepMeta stepinfo = new StepMeta(BaseMessages.getString(PKG, "DimensionLookupDialog.Stepinfo.Title"), name, info);
        RowMetaInterface prev = transMeta.getPrevStepFields(stepname);
        String message = null;
        if (Utils.isEmpty(info.getKeyField())) {
            message = BaseMessages.getString(PKG, "DimensionLookupDialog.Error.NoTechnicalKeySpecified");
        }
        if (Utils.isEmpty(info.getTableName())) {
            message = BaseMessages.getString(PKG, "DimensionLookupDialog.Error.NoTableNameSpecified");
        }
        if (message == null) {
            SQLStatement sql = info.getSQLStatements(transMeta, stepinfo, prev, repository, metaStore);
            if (!sql.hasError()) {
                if (sql.hasSQL()) {
                    SQLEditor sqledit = new SQLEditor(transMeta, shell, SWT.NONE, info.getDatabaseMeta(), transMeta.getDbCache(), sql.getSQL());
                    sqledit.open();
                } else {
                    MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
                    mb.setMessage(BaseMessages.getString(PKG, "DimensionLookupDialog.NoSQLNeeds.DialogMessage"));
                    mb.setText(BaseMessages.getString(PKG, "DimensionLookupDialog.NoSQLNeeds.DialogTitle"));
                    mb.open();
                }
            } else {
                MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
                mb.setMessage(sql.getError());
                mb.setText(BaseMessages.getString(PKG, "DimensionLookupDialog.SQLError.DialogTitle"));
                mb.open();
            }
        } else {
            MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
            mb.setMessage(message);
            mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title"));
            mb.open();
        }
    } catch (KettleException ke) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "DimensionLookupDialog.UnableToBuildSQLError.DialogMessage"), BaseMessages.getString(PKG, "DimensionLookupDialog.UnableToBuildSQLError.DialogTitle"), ke);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) SQLEditor(org.pentaho.di.ui.core.database.dialog.SQLEditor) DimensionLookupMeta(org.pentaho.di.trans.steps.dimensionlookup.DimensionLookupMeta) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) SQLStatement(org.pentaho.di.core.SQLStatement) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 42 with SQLStatement

use of org.pentaho.di.core.SQLStatement in project pentaho-kettle by pentaho.

the class LucidDBStreamingLoaderMeta method getSQLStatements.

@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;
}
Also used : KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) Database(org.pentaho.di.core.database.Database) SQLStatement(org.pentaho.di.core.SQLStatement)

Example 43 with SQLStatement

use of org.pentaho.di.core.SQLStatement in project pentaho-kettle by pentaho.

the class GPBulkLoaderDialog method create.

// Generate code for create table...
// Conversions done by Database
private void create() {
    try {
        GPBulkLoaderMeta info = new GPBulkLoaderMeta();
        getInfo(info);
        // new name might not yet be linked to other steps!
        String name = stepname;
        StepMeta stepMeta = new StepMeta(BaseMessages.getString(PKG, "GPBulkLoaderDialog.StepMeta.Title"), name, info);
        RowMetaInterface prev = transMeta.getPrevStepFields(stepname);
        SQLStatement sql = info.getSQLStatements(transMeta, stepMeta, prev, repository, metaStore);
        if (!sql.hasError()) {
            if (sql.hasSQL()) {
                SQLEditor sqledit = new SQLEditor(transMeta, shell, SWT.NONE, info.getDatabaseMeta(), transMeta.getDbCache(), sql.getSQL());
                sqledit.open();
            } else {
                MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
                mb.setMessage(BaseMessages.getString(PKG, "GPBulkLoaderDialog.NoSQLNeeds.DialogMessage"));
                mb.setText(BaseMessages.getString(PKG, "GPBulkLoaderDialog.NoSQLNeeds.DialogTitle"));
                mb.open();
            }
        } else {
            MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
            mb.setMessage(sql.getError());
            mb.setText(BaseMessages.getString(PKG, "GPBulkLoaderDialog.SQLError.DialogTitle"));
            mb.open();
        }
    } catch (KettleException ke) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "GPBulkLoaderDialog.CouldNotBuildSQL.DialogTitle"), BaseMessages.getString(PKG, "GPBulkLoaderDialog.CouldNotBuildSQL.DialogMessage"), ke);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) SQLEditor(org.pentaho.di.ui.core.database.dialog.SQLEditor) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) SQLStatement(org.pentaho.di.core.SQLStatement) GPBulkLoaderMeta(org.pentaho.di.trans.steps.gpbulkloader.GPBulkLoaderMeta) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 44 with SQLStatement

use of org.pentaho.di.core.SQLStatement in project pentaho-kettle by pentaho.

the class GPLoadDialog method create.

// Generate code for create table...
// Conversions done by Database
private void create() {
    try {
        GPLoadMeta info = new GPLoadMeta();
        getInfo(info);
        // new name might not yet be linked to other
        String name = stepname;
        // steps!
        StepMeta stepMeta = new StepMeta(BaseMessages.getString(PKG, "GPLoadDialog.StepMeta.Title"), name, info);
        RowMetaInterface prev = transMeta.getPrevStepFields(stepname);
        SQLStatement sql = info.getSQLStatements(transMeta, stepMeta, prev, repository, metaStore);
        if (!sql.hasError()) {
            if (sql.hasSQL()) {
                SQLEditor sqledit = new SQLEditor(transMeta, shell, SWT.NONE, info.getDatabaseMeta(), transMeta.getDbCache(), sql.getSQL());
                sqledit.open();
            } else {
                MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
                mb.setMessage(BaseMessages.getString(PKG, "GPLoadDialog.NoSQLNeeds.DialogMessage"));
                mb.setText(BaseMessages.getString(PKG, "GPLoadDialog.NoSQLNeeds.DialogTitle"));
                mb.open();
            }
        } else {
            MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
            mb.setMessage(sql.getError());
            mb.setText(BaseMessages.getString(PKG, "GPLoadDialog.SQLError.DialogTitle"));
            mb.open();
        }
    } catch (KettleException ke) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "GPLoadDialog.CouldNotBuildSQL.DialogTitle"), BaseMessages.getString(PKG, "GPLoadDialog.CouldNotBuildSQL.DialogMessage"), ke);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) SQLEditor(org.pentaho.di.ui.core.database.dialog.SQLEditor) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) GPLoadMeta(org.pentaho.di.trans.steps.gpload.GPLoadMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) SQLStatement(org.pentaho.di.core.SQLStatement) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 45 with SQLStatement

use of org.pentaho.di.core.SQLStatement in project pentaho-kettle by pentaho.

the class IngresVectorwiseLoaderDialog method sql.

private void sql() {
    try {
        IngresVectorwiseLoaderMeta info = new IngresVectorwiseLoaderMeta();
        getInfo(info);
        RowMetaInterface prev = transMeta.getPrevStepFields(stepname);
        StepMeta stepMeta = transMeta.findStep(stepname);
        // Only use the fields that were specified.
        // 
        RowMetaInterface prevNew = new RowMeta();
        for (int i = 0; i < info.getFieldDatabase().length; i++) {
            ValueMetaInterface insValue = prev.searchValueMeta(info.getFieldStream()[i]);
            if (insValue != null) {
                ValueMetaInterface insertValue = insValue.clone();
                insertValue.setName(info.getFieldDatabase()[i]);
                prevNew.addValueMeta(insertValue);
            } else {
                throw new KettleStepException(BaseMessages.getString(PKG, "IngresVectorWiseLoaderDialog.FailedToFindField.Message", info.getFieldStream()[i]));
            }
        }
        prev = prevNew;
        SQLStatement sql = info.getSQLStatements(transMeta, stepMeta, prev, repository, metaStore);
        if (!sql.hasError()) {
            if (sql.hasSQL()) {
                SQLEditor sqledit = new SQLEditor(transMeta, shell, SWT.NONE, info.getDatabaseMeta(), transMeta.getDbCache(), sql.getSQL());
                sqledit.open();
            } else {
                MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
                mb.setMessage(BaseMessages.getString(PKG, "IngresVectorWiseLoaderDialog.NoSQL.DialogMessage"));
                mb.setText(BaseMessages.getString(PKG, "IngresVectorWiseLoaderDialog.NoSQL.DialogTitle"));
                mb.open();
            }
        } else {
            MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
            mb.setMessage(sql.getError());
            mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title"));
            mb.open();
        }
    } catch (KettleException ke) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "IngresVectorWiseLoaderDialog.BuildSQLError.DialogTitle"), BaseMessages.getString(PKG, "IngresVectorWiseLoaderDialog.BuildSQLError.DialogMessage"), ke);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) SQLEditor(org.pentaho.di.ui.core.database.dialog.SQLEditor) KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMeta(org.pentaho.di.core.row.RowMeta) IngresVectorwiseLoaderMeta(org.pentaho.di.trans.steps.ivwloader.IngresVectorwiseLoaderMeta) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) SQLStatement(org.pentaho.di.core.SQLStatement) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

SQLStatement (org.pentaho.di.core.SQLStatement)49 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)35 KettleException (org.pentaho.di.core.exception.KettleException)33 StepMeta (org.pentaho.di.trans.step.StepMeta)22 Database (org.pentaho.di.core.database.Database)21 MessageBox (org.eclipse.swt.widgets.MessageBox)18 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)16 SQLEditor (org.pentaho.di.ui.core.database.dialog.SQLEditor)16 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)16 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)15 RowMeta (org.pentaho.di.core.row.RowMeta)12 KettleStepException (org.pentaho.di.core.exception.KettleStepException)10 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)9 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)6 TransMeta (org.pentaho.di.trans.TransMeta)4 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)3 Point (org.pentaho.di.core.gui.Point)3 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)3 Repository (org.pentaho.di.repository.Repository)3 ArrayList (java.util.ArrayList)2