Search in sources :

Example 11 with SQLEditor

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

the class TransDialog method sql.

/**
 * Generates code for create table... Conversions done by Database
 */
private void sql() {
    getLogInfo();
    try {
        boolean allOK = true;
        for (LogTableInterface logTable : new LogTableInterface[] { transLogTable, performanceLogTable, channelLogTable, stepLogTable, metricsLogTable }) {
            if (logTable.getDatabaseMeta() != null && !Utils.isEmpty(logTable.getTableName())) {
                // OK, we have something to work with!
                // 
                Database db = null;
                try {
                    db = new Database(transMeta, logTable.getDatabaseMeta());
                    db.shareVariablesWith(transMeta);
                    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()), tableName);
                    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) {
                        allOK = false;
                        SQLEditor sqledit = new SQLEditor(transMeta, shell, SWT.NONE, logTable.getDatabaseMeta(), transMeta.getDbCache(), ddl.toString());
                        sqledit.open();
                    }
                } finally {
                    if (db != null) {
                        db.disconnect();
                    }
                }
            }
        }
        if (allOK) {
            MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
            mb.setText(BaseMessages.getString(PKG, "TransDialog.NoSqlNedds.DialogTitle"));
            mb.setMessage(BaseMessages.getString(PKG, "TransDialog.NoSqlNedds.DialogMessage"));
            mb.open();
        }
    } catch (Exception e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "TransDialog.ErrorOccurred.DialogTitle"), BaseMessages.getString(PKG, "TransDialog.ErrorOccurred.DialogMessage"), e);
    }
}
Also used : SQLEditor(org.pentaho.di.ui.core.database.dialog.SQLEditor) 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) LogTableInterface(org.pentaho.di.core.logging.LogTableInterface) Database(org.pentaho.di.core.database.Database)

Example 12 with SQLEditor

use of org.pentaho.di.ui.core.database.dialog.SQLEditor 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 13 with SQLEditor

use of org.pentaho.di.ui.core.database.dialog.SQLEditor 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)

Example 14 with SQLEditor

use of org.pentaho.di.ui.core.database.dialog.SQLEditor 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 15 with SQLEditor

use of org.pentaho.di.ui.core.database.dialog.SQLEditor 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)

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