Search in sources :

Example 6 with SQLEditor

use of org.pentaho.di.ui.core.database.dialog.SQLEditor in project pentaho-kettle by pentaho.

the class InsertUpdateDialog method create.

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

use of org.pentaho.di.ui.core.database.dialog.SQLEditor in project pentaho-kettle by pentaho.

the class JobDialog method sql.

/**
 * Generates code for create table... Conversions done by Database
 */
private void sql() {
    if (previousLogTableIndex >= 0) {
        getLogInfo(previousLogTableIndex);
    }
    try {
        for (LogTableInterface logTable : logTables) {
            if (logTable.getDatabaseMeta() != null && !Utils.isEmpty(logTable.getTableName())) {
                // OK, we have something to work with!
                // 
                Database db = null;
                try {
                    db = new Database(jobMeta, logTable.getDatabaseMeta());
                    db.shareVariablesWith(jobMeta);
                    db.connect();
                    StringBuilder ddl = new StringBuilder();
                    RowMetaInterface fields = logTable.getLogRecord(LogStatus.START, null, null).getRowMeta();
                    String tableName = db.environmentSubstitute(logTable.getTableName());
                    String schemaTable = logTable.getDatabaseMeta().getQuotedSchemaTableCombination(db.environmentSubstitute(logTable.getSchemaName()), db.environmentSubstitute(logTable.getTableName()));
                    String createTable = db.getDDL(schemaTable, fields);
                    if (!Utils.isEmpty(createTable)) {
                        ddl.append("-- ").append(logTable.getLogTableType()).append(Const.CR);
                        ddl.append("--").append(Const.CR).append(Const.CR);
                        ddl.append(createTable).append(Const.CR);
                    }
                    java.util.List<RowMetaInterface> indexes = logTable.getRecommendedIndexes();
                    for (int i = 0; i < indexes.size(); i++) {
                        RowMetaInterface index = indexes.get(i);
                        if (!index.isEmpty()) {
                            String createIndex = db.getCreateIndexStatement(schemaTable, "IDX_" + tableName + "_" + (i + 1), index.getFieldNames(), false, false, false, true);
                            if (!Utils.isEmpty(createIndex)) {
                                ddl.append(createIndex);
                            }
                        }
                    }
                    if (ddl.length() > 0) {
                        SQLEditor sqledit = new SQLEditor(jobMeta, shell, SWT.NONE, logTable.getDatabaseMeta(), DBCache.getInstance(), ddl.toString());
                        sqledit.open();
                    } else {
                        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
                        mb.setText(BaseMessages.getString(PKG, "JobDialog.NoSqlNedds.DialogTitle"));
                        mb.setMessage(logTable.getLogTableType() + Const.CR + Const.CR + BaseMessages.getString(PKG, "JobDialog.NoSqlNedds.DialogMessage"));
                        mb.open();
                    }
                } finally {
                    if (db != null) {
                        db.disconnect();
                    }
                }
            }
        }
    } catch (Exception e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "JobDialog.Dialog.ErrorCreatingSQL.Title"), BaseMessages.getString(PKG, "JobDialog.Dialog.ErrorCreatingSQL.Message"), e);
    }
}
Also used : LogTableInterface(org.pentaho.di.core.logging.LogTableInterface) SQLEditor(org.pentaho.di.ui.core.database.dialog.SQLEditor) Database(org.pentaho.di.core.database.Database) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) DuplicateParamException(org.pentaho.di.core.parameters.DuplicateParamException) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) KettleException(org.pentaho.di.core.exception.KettleException) KettleRepositoryLostException(org.pentaho.di.repository.KettleRepositoryLostException) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 8 with SQLEditor

use of org.pentaho.di.ui.core.database.dialog.SQLEditor in project pentaho-kettle by pentaho.

the class LucidDBBulkLoaderDialog method create.

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

Example 9 with SQLEditor

use of org.pentaho.di.ui.core.database.dialog.SQLEditor in project pentaho-kettle by pentaho.

the class LucidDBStreamingLoaderDialog method create.

// Generate code for create table...
// Conversions done by Database
private void create() {
    try {
        LucidDBStreamingLoaderMeta info = new LucidDBStreamingLoaderMeta();
        getInfo(info);
        // new name might not yet be linked to other steps!
        String name = stepname;
        StepMeta stepMeta = new StepMeta(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.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, "LucidDBStreamingLoaderDialog.NoSQLNeeds.DialogMessage"));
                mb.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.NoSQLNeeds.DialogTitle"));
                mb.open();
            }
        } else {
            MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
            mb.setMessage(sql.getError());
            mb.setText(BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.SQLError.DialogTitle"));
            mb.open();
        }
    } catch (KettleException ke) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.CouldNotBuildSQL.DialogTitle"), BaseMessages.getString(PKG, "LucidDBStreamingLoaderDialog.CouldNotBuildSQL.DialogMessage"), ke);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) SQLEditor(org.pentaho.di.ui.core.database.dialog.SQLEditor) LucidDBStreamingLoaderMeta(org.pentaho.di.trans.steps.luciddbstreamingloader.LucidDBStreamingLoaderMeta) 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 10 with SQLEditor

use of org.pentaho.di.ui.core.database.dialog.SQLEditor in project pentaho-kettle by pentaho.

the class CombinationLookupDialog method create.

/**
 * Generate code for create table. Conversions done by database.
 */
private void create() {
    try {
        // Gather info...
        CombinationLookupMeta info = new CombinationLookupMeta();
        getInfo(info);
        // new name might not yet be linked to other steps!
        String name = stepname;
        StepMeta stepMeta = new StepMeta(BaseMessages.getString(PKG, "CombinationLookupDialog.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, "CombinationLookupDialog.NoSQLNeeds.DialogMessage"));
                mb.setText(BaseMessages.getString(PKG, "CombinationLookupDialog.NoSQLNeeds.DialogTitle"));
                mb.open();
            }
        } else {
            MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
            mb.setMessage(sql.getError());
            mb.setText(BaseMessages.getString(PKG, "CombinationLookupDialog.SQLError.DialogTitle"));
            mb.open();
        }
    } catch (KettleException ke) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "CombinationLookupDialog.UnableToCreateSQL.DialogTitle"), BaseMessages.getString(PKG, "CombinationLookupDialog.UnableToCreateSQL.DialogMessage"), ke);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) SQLEditor(org.pentaho.di.ui.core.database.dialog.SQLEditor) CombinationLookupMeta(org.pentaho.di.trans.steps.combinationlookup.CombinationLookupMeta) 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)

Aggregations

SQLEditor (org.pentaho.di.ui.core.database.dialog.SQLEditor)20 KettleException (org.pentaho.di.core.exception.KettleException)19 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)19 MessageBox (org.eclipse.swt.widgets.MessageBox)18 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)17 SQLStatement (org.pentaho.di.core.SQLStatement)16 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)15 StepMeta (org.pentaho.di.trans.step.StepMeta)15 Database (org.pentaho.di.core.database.Database)2 KettleStepException (org.pentaho.di.core.exception.KettleStepException)2 LogTableInterface (org.pentaho.di.core.logging.LogTableInterface)2 DuplicateParamException (org.pentaho.di.core.parameters.DuplicateParamException)2 UnknownParamException (org.pentaho.di.core.parameters.UnknownParamException)2 RowMeta (org.pentaho.di.core.row.RowMeta)2 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)2 KettleRepositoryLostException (org.pentaho.di.repository.KettleRepositoryLostException)2 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)1 RepositoryPluginType (org.pentaho.di.core.plugins.RepositoryPluginType)1 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)1 Repository (org.pentaho.di.repository.Repository)1