Search in sources :

Example 16 with SQLEditor

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

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

Example 18 with SQLEditor

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

the class MonetDBBulkLoaderDialog method create.

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

Example 19 with SQLEditor

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

the class OraBulkLoaderDialog method create.

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

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

the class KettleDatabaseRepositoryDialog method create.

private void create() {
    System.out.println("Loading repository info...");
    KettleDatabaseRepositoryMeta repositoryMeta = new KettleDatabaseRepositoryMeta();
    getInfo(repositoryMeta);
    if (repositoryMeta.getConnection() != null) {
        if (repositoryMeta.getConnection().getAccessType() == DatabaseMeta.TYPE_ACCESS_ODBC) {
            // Show a warning: using ODBC is not always the best choice ;-)
            System.out.println("Show ODBC warning...");
            MessageBox qmb = new MessageBox(shell, SWT.ICON_WARNING | SWT.YES | SWT.NO);
            qmb.setMessage(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.ODBCIsNotSafe.Message", Const.CR, Const.CR));
            qmb.setText(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.ODBCIsNotSafe.Title"));
            int answer = qmb.open();
            if (answer != SWT.YES) {
                // Don't continue
                return;
            }
        }
        try {
            System.out.println("Allocating repository...");
            KettleDatabaseRepository rep = (KettleDatabaseRepository) PluginRegistry.getInstance().loadClass(RepositoryPluginType.class, repositoryMeta, Repository.class);
            rep.init(repositoryMeta);
            if (!rep.getDatabaseMeta().getDatabaseInterface().supportsRepository()) {
                // Show a warning box "This database type is not supported for the use as a database repository."
                System.out.println("Show database type is not supported warning...");
                MessageBox qmb = new MessageBox(shell, SWT.ICON_WARNING | SWT.YES | SWT.NO);
                qmb.setMessage(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.DBTypeNotSupport.Message", Const.CR, Const.CR));
                qmb.setText(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.DBTypeNotSupport.Title"));
                int answer = qmb.open();
                if (answer != SWT.YES) {
                    // Don't continue
                    return;
                }
            }
            System.out.println("Connecting to database for repository creation...");
            rep.connectionDelegate.connect(true, true);
            boolean upgrade = false;
            String cu = BaseMessages.getString(PKG, "RepositoryDialog.Dialog.CreateUpgrade.Create");
            try {
                String userTableName = rep.getDatabaseMeta().quoteField(KettleDatabaseRepository.TABLE_R_USER);
                upgrade = rep.getDatabase().checkTableExists(userTableName);
                if (upgrade) {
                    cu = BaseMessages.getString(PKG, "RepositoryDialog.Dialog.CreateUpgrade.Upgrade");
                }
            } catch (KettleDatabaseException dbe) {
                // Roll back the connection: this is required for certain databases like PGSQL
                // Otherwise we can't execute any other DDL statement.
                // 
                rep.rollback();
            // Don't show an error anymore, just go ahead and propose to create the repository!
            }
            MessageBox qmb = new MessageBox(shell, SWT.ICON_WARNING | SWT.YES | SWT.NO);
            qmb.setMessage(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.CreateUpgrade.Message1") + cu + BaseMessages.getString(PKG, "RepositoryDialog.Dialog.CreateUpgrade.Message2"));
            qmb.setText(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.CreateUpgrade.Title"));
            int answer = qmb.open();
            if (answer == SWT.YES) {
                boolean goAhead = !upgrade;
                if (!goAhead) {
                    EnterPasswordDialog etd = new EnterPasswordDialog(shell, BaseMessages.getString(PKG, "RepositoryDialog.Dialog.EnterPassword.Title"), BaseMessages.getString(PKG, "RepositoryDialog.Dialog.EnterPassword.Message"), "");
                    etd.setModal();
                    String pwd = etd.open();
                    if (pwd != null) {
                        try {
                            // authenticate as admin before upgrade
                            // disconnect before connecting, we connected above already
                            // 
                            rep.disconnect();
                            rep.connect("admin", pwd, true);
                            goAhead = true;
                        } catch (KettleException e) {
                            new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryDialog.Dialog.UnableToVerifyUser.Title"), BaseMessages.getString(PKG, "RepositoryDialog.Dialog.UnableToVerifyUser.Message"), e);
                        }
                    }
                }
                if (goAhead) {
                    System.out.println(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.TryingToUpgradeRepository.Message1") + cu + BaseMessages.getString(PKG, "RepositoryDialog.Dialog.TryingToUpgradeRepository.Message2"));
                    UpgradeRepositoryProgressDialog urpd = new UpgradeRepositoryProgressDialog(shell, rep, upgrade);
                    if (urpd.open()) {
                        if (urpd.isDryRun()) {
                            StringBuilder sql = new StringBuilder();
                            sql.append("-- Repository creation/upgrade DDL: ").append(Const.CR);
                            sql.append("--").append(Const.CR);
                            sql.append("-- Nothing was created nor modified in the target repository database.").append(Const.CR);
                            sql.append("-- Hit the OK button to execute the generated SQL or Close to reject the changes.").append(Const.CR);
                            sql.append("-- Please note that it is possible to change/edit the generated SQL before execution.").append(Const.CR);
                            sql.append("--").append(Const.CR);
                            for (String statement : urpd.getGeneratedStatements()) {
                                if (statement.endsWith(";")) {
                                    sql.append(statement).append(Const.CR);
                                } else {
                                    sql.append(statement).append(";").append(Const.CR).append(Const.CR);
                                }
                            }
                            SQLEditor editor = new SQLEditor(rep.getDatabaseMeta(), shell, SWT.NONE, rep.getDatabaseMeta(), DBCache.getInstance(), sql.toString());
                            editor.open();
                        } else {
                            MessageBox mb = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
                            mb.setMessage(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.UpgradeFinished.Message1") + cu + BaseMessages.getString(PKG, "RepositoryDialog.Dialog.UpgradeFinished.Message2"));
                            mb.setText(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.UpgradeFinished.Title"));
                            mb.open();
                        }
                    }
                }
            }
            rep.disconnect();
        } catch (KettleException ke) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryDialog.Dialog.UnableToConnectToUpgrade.Title"), BaseMessages.getString(PKG, "RepositoryDialog.Dialog.UnableToConnectToUpgrade.Message") + Const.CR, ke);
        }
    } else {
        MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
        mb.setMessage(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.FirstCreateAValidConnection.Message"));
        mb.setText(BaseMessages.getString(PKG, "RepositoryDialog.Dialog.FirstCreateAValidConnection.Title"));
        mb.open();
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) UpgradeRepositoryProgressDialog(org.pentaho.di.ui.repository.dialog.UpgradeRepositoryProgressDialog) SQLEditor(org.pentaho.di.ui.core.database.dialog.SQLEditor) RepositoryPluginType(org.pentaho.di.core.plugins.RepositoryPluginType) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) KettleDatabaseRepositoryMeta(org.pentaho.di.repository.kdr.KettleDatabaseRepositoryMeta) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) KettleDatabaseRepository(org.pentaho.di.repository.kdr.KettleDatabaseRepository) EnterPasswordDialog(org.pentaho.di.ui.core.dialog.EnterPasswordDialog) MessageBox(org.eclipse.swt.widgets.MessageBox) KettleDatabaseRepository(org.pentaho.di.repository.kdr.KettleDatabaseRepository) Repository(org.pentaho.di.repository.Repository)

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