Search in sources :

Example 46 with SQLStatement

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

the class SpoonDBDelegate method getJobSQL.

/**
 * Get & show the SQL required to run the loaded job entry...
 */
public void getJobSQL(JobMeta jobMeta) {
    GetJobSQLProgressDialog pspd = new GetJobSQLProgressDialog(spoon.getShell(), jobMeta, spoon.getRepository());
    List<SQLStatement> stats = pspd.open();
    if (stats != null) {
        if (stats.size() > 0) {
            SQLStatementsDialog ssd = new SQLStatementsDialog(spoon.getShell(), jobMeta, SWT.NONE, stats);
            ssd.open();
        } else {
            MessageBox mb = new MessageBox(spoon.getShell(), SWT.OK | SWT.ICON_INFORMATION);
            mb.setMessage(BaseMessages.getString(PKG, "Spoon.Dialog.JobNoSQLNeedEexecuted.Message"));
            mb.setText(BaseMessages.getString(PKG, "Spoon.Dialog.JobNoSQLNeedEexecuted.Title"));
            mb.open();
        }
    }
}
Also used : SQLStatementsDialog(org.pentaho.di.ui.core.dialog.SQLStatementsDialog) GetJobSQLProgressDialog(org.pentaho.di.ui.spoon.dialog.GetJobSQLProgressDialog) SQLStatement(org.pentaho.di.core.SQLStatement) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 47 with SQLStatement

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

the class SpoonDBDelegate method getTransSQL.

/**
 * Get & show the SQL required to run the loaded transformation...
 */
public void getTransSQL(TransMeta transMeta) {
    GetSQLProgressDialog pspd = new GetSQLProgressDialog(spoon.getShell(), transMeta);
    List<SQLStatement> stats = pspd.open();
    if (stats != null) {
        if (stats.size() > 0) {
            SQLStatementsDialog ssd = new SQLStatementsDialog(spoon.getShell(), Variables.getADefaultVariableSpace(), SWT.NONE, stats);
            String sn = ssd.open();
            if (sn != null) {
                StepMeta esi = transMeta.findStep(sn);
                if (esi != null) {
                    spoon.delegates.steps.editStep(transMeta, esi);
                }
            }
        } else {
            MessageBox mb = new MessageBox(spoon.getShell(), SWT.OK | SWT.ICON_INFORMATION);
            mb.setMessage(BaseMessages.getString(PKG, "Spoon.Dialog.NoSQLNeedEexecuted.Message"));
            // "SQL"
            mb.setText(BaseMessages.getString(PKG, "Spoon.Dialog.NoSQLNeedEexecuted.Title"));
            mb.open();
        }
    }
}
Also used : GetSQLProgressDialog(org.pentaho.di.ui.spoon.dialog.GetSQLProgressDialog) SQLStatementsDialog(org.pentaho.di.ui.core.dialog.SQLStatementsDialog) SQLStatement(org.pentaho.di.core.SQLStatement) StepMeta(org.pentaho.di.trans.step.StepMeta) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 48 with SQLStatement

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

the class SynchronizeAfterMergeDialog method create.

// Generate code for create table...
// Conversions done by Database
private void create() {
    try {
        SynchronizeAfterMergeMeta info = new SynchronizeAfterMergeMeta();
        getInfo(info);
        // new name might not yet be linked to other steps!
        String name = stepname;
        StepMeta stepMeta = new StepMeta(BaseMessages.getString(PKG, "SynchronizeAfterMergeDialog.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, "SynchronizeAfterMergeDialog.NoSQLNeeds.DialogMessage"));
                mb.setText(BaseMessages.getString(PKG, "SynchronizeAfterMergeDialog.NoSQLNeeds.DialogTitle"));
                mb.open();
            }
        } else {
            MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
            mb.setMessage(sql.getError());
            mb.setText(BaseMessages.getString(PKG, "SynchronizeAfterMergeDialog.SQLError.DialogTitle"));
            mb.open();
        }
    } catch (KettleException ke) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "SynchronizeAfterMergeDialog.CouldNotBuildSQL.DialogTitle"), BaseMessages.getString(PKG, "SynchronizeAfterMergeDialog.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) SynchronizeAfterMergeMeta(org.pentaho.di.trans.steps.synchronizeaftermerge.SynchronizeAfterMergeMeta) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 49 with SQLStatement

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

the class TableOutputDialog method sql.

// Generate code for create table...
// Conversions done by Database
// 
private void sql() {
    try {
        TableOutputMeta info = new TableOutputMeta();
        getInfo(info);
        RowMetaInterface prev = transMeta.getPrevStepFields(stepname);
        if (info.isTableNameInField() && !info.isTableNameInTable() && info.getTableNameField().length() > 0) {
            int idx = prev.indexOfValue(info.getTableNameField());
            if (idx >= 0) {
                prev.removeValueMeta(idx);
            }
        }
        StepMeta stepMeta = transMeta.findStep(stepname);
        if (info.specifyFields()) {
            // 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, "TableOutputDialog.FailedToFindField.Message", info.getFieldStream()[i]));
                }
            }
            prev = prevNew;
        }
        boolean autoInc = false;
        String pk = null;
        // 
        if (info.isReturningGeneratedKeys() && !Utils.isEmpty(info.getGeneratedKeyField())) {
            ValueMetaInterface valueMeta = new ValueMetaInteger(info.getGeneratedKeyField());
            valueMeta.setLength(15);
            prev.addValueMeta(0, valueMeta);
            autoInc = true;
            pk = info.getGeneratedKeyField();
        }
        if (isValidRowMeta(prev)) {
            SQLStatement sql = info.getSQLStatements(transMeta, stepMeta, prev, pk, autoInc, pk);
            if (!sql.hasError()) {
                if (sql.hasSQL()) {
                    SQLEditor sqledit = new SQLEditor(transMeta, shell, SWT.NONE, info.getDatabaseMeta(), transMeta.getDbCache(), sql.getSQL());
                    sqledit.open();
                } else {
                    String message = getBaseMessage("TableOutputDialog.NoSQL.DialogMessage");
                    String text = getBaseMessage("TableOutputDialog.NoSQL.DialogTitle");
                    showMessage(shell, SWT.OK | SWT.ICON_INFORMATION, message, text);
                }
            } else {
                String text = getBaseMessage("System.Dialog.Error.Title");
                showMessage(shell, SWT.OK | SWT.ICON_ERROR, sql.getError(), text);
            }
        } else {
            String message = getBaseMessage("TableOutputDialog.NoSQL.EmptyCSVFields");
            String text = getBaseMessage("TableOutputDialog.NoSQL.DialogTitle");
            showMessage(shell, SWT.OK | SWT.ICON_ERROR, message, text);
        }
    } catch (KettleException ke) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "TableOutputDialog.BuildSQLError.DialogTitle"), BaseMessages.getString(PKG, "TableOutputDialog.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) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) TableOutputMeta(org.pentaho.di.trans.steps.tableoutput.TableOutputMeta) 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) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger)

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