Search in sources :

Example 1 with DatabaseExplorerDialog

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

the class GPLoadDialog method getTableName.

private void getTableName(TextVar schema, TextVar tableName) {
    DatabaseMeta inf = null;
    // New class: SelectTableDialog
    int connr = wConnection.getSelectionIndex();
    if (connr >= 0) {
        inf = transMeta.getDatabase(connr);
    }
    if (inf != null) {
        if (log.isDebug()) {
            logDebug(BaseMessages.getString(PKG, "GPLoadDialog.Log.LookingAtConnection") + inf.toString());
        }
        DatabaseExplorerDialog std = new DatabaseExplorerDialog(shell, SWT.NONE, inf, transMeta.getDatabases());
        std.setSelectedSchemaAndTable(wSchema.getText(), wTable.getText());
        if (std.open()) {
            schema.setText(Const.NVL(std.getSchemaName(), ""));
            tableName.setText(Const.NVL(std.getTableName(), ""));
        }
    } else {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
        mb.setMessage(BaseMessages.getString(PKG, "GPLoadDialog.InvalidConnection.DialogMessage"));
        mb.setText(BaseMessages.getString(PKG, "GPLoadDialog.InvalidConnection.DialogTitle"));
        mb.open();
    }
}
Also used : DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) DatabaseExplorerDialog(org.pentaho.di.ui.core.database.dialog.DatabaseExplorerDialog) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 2 with DatabaseExplorerDialog

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

the class GPBulkLoaderDialog method getTableName.

private void getTableName() {
    DatabaseMeta inf = null;
    // New class: SelectTableDialog
    int connr = wConnection.getSelectionIndex();
    if (connr >= 0) {
        inf = transMeta.getDatabase(connr);
    }
    if (inf != null) {
        if (log.isDebug()) {
            logDebug(BaseMessages.getString(PKG, "GPBulkLoaderDialog.Log.LookingAtConnection") + inf.toString());
        }
        DatabaseExplorerDialog std = new DatabaseExplorerDialog(shell, SWT.NONE, inf, transMeta.getDatabases());
        std.setSelectedSchemaAndTable(wSchema.getText(), wTable.getText());
        if (std.open()) {
            wSchema.setText(Const.NVL(std.getSchemaName(), ""));
            wTable.setText(Const.NVL(std.getTableName(), ""));
        }
    } else {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
        mb.setMessage(BaseMessages.getString(PKG, "GPBulkLoaderDialog.InvalidConnection.DialogMessage"));
        mb.setText(BaseMessages.getString(PKG, "GPBulkLoaderDialog.InvalidConnection.DialogTitle"));
        mb.open();
    }
}
Also used : DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) DatabaseExplorerDialog(org.pentaho.di.ui.core.database.dialog.DatabaseExplorerDialog) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 3 with DatabaseExplorerDialog

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

the class JobEntryWaitForSQLDialog method getSQL.

private void getSQL() {
    DatabaseMeta inf = jobMeta.findDatabase(wConnection.getText());
    if (inf != null) {
        DatabaseExplorerDialog std = new DatabaseExplorerDialog(shell, SWT.NONE, inf, jobMeta.getDatabases());
        if (std.open()) {
            String sql = "SELECT *" + Const.CR + "FROM " + inf.getQuotedSchemaTableCombination(std.getSchemaName(), std.getTableName()) + Const.CR;
            wSQL.setText(sql);
            MessageBox yn = new MessageBox(shell, SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION);
            yn.setMessage(BaseMessages.getString(PKG, "JobEntryWaitForSQL.IncludeFieldNamesInSQL"));
            yn.setText(BaseMessages.getString(PKG, "JobEntryWaitForSQL.DialogCaptionQuestion"));
            int id = yn.open();
            switch(id) {
                case SWT.CANCEL:
                    break;
                case SWT.NO:
                    wSQL.setText(sql);
                    break;
                case SWT.YES:
                    Database db = new Database(loggingObject, inf);
                    try {
                        db.connect();
                        RowMetaInterface fields = db.getQueryFields(sql, false);
                        if (fields != null) {
                            sql = "SELECT" + Const.CR;
                            for (int i = 0; i < fields.size(); i++) {
                                ValueMetaInterface field = fields.getValueMeta(i);
                                if (i == 0) {
                                    sql += "  ";
                                } else {
                                    sql += ", ";
                                }
                                sql += inf.quoteField(field.getName()) + Const.CR;
                            }
                            sql += "FROM " + inf.getQuotedSchemaTableCombination(std.getSchemaName(), std.getTableName()) + Const.CR;
                            wSQL.setText(sql);
                        } else {
                            MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
                            mb.setMessage(BaseMessages.getString(PKG, "JobEntryWaitForSQL.ERROR_CouldNotRetrieveFields") + Const.CR + BaseMessages.getString(PKG, "JobEntryWaitForSQL.PerhapsNoPermissions"));
                            mb.setText(BaseMessages.getString(PKG, "JobEntryWaitForSQL.DialogCaptionError2"));
                            mb.open();
                        }
                    } catch (KettleException e) {
                        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
                        mb.setText(BaseMessages.getString(PKG, "JobEntryWaitForSQL.DialogCaptionError3"));
                        mb.setMessage(BaseMessages.getString(PKG, "JobEntryWaitForSQL.AnErrorOccurred") + Const.CR + e.getMessage());
                        mb.open();
                    } finally {
                        db.disconnect();
                    }
                    break;
                default:
                    break;
            }
        }
    } else {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
        mb.setMessage(BaseMessages.getString(PKG, "JobEntryWaitForSQL.ConnectionNoLongerAvailable"));
        mb.setText(BaseMessages.getString(PKG, "JobEntryWaitForSQL.DialogCaptionError4"));
        mb.open();
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) Database(org.pentaho.di.core.database.Database) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) DatabaseExplorerDialog(org.pentaho.di.ui.core.database.dialog.DatabaseExplorerDialog) MessageBox(org.eclipse.swt.widgets.MessageBox) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 4 with DatabaseExplorerDialog

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

the class OraBulkLoaderDialog method getTableName.

private void getTableName() {
    DatabaseMeta inf = null;
    // New class: SelectTableDialog
    int connr = wConnection.getSelectionIndex();
    if (connr >= 0) {
        inf = transMeta.getDatabase(connr);
    }
    if (inf != null) {
        if (log.isDebug()) {
            logDebug(BaseMessages.getString(PKG, "OraBulkLoaderDialog.Log.LookingAtConnection") + inf.toString());
        }
        DatabaseExplorerDialog std = new DatabaseExplorerDialog(shell, SWT.NONE, inf, transMeta.getDatabases());
        std.setSelectedSchemaAndTable(wSchema.getText(), wTable.getText());
        if (std.open()) {
            wSchema.setText(Const.NVL(std.getSchemaName(), ""));
            wTable.setText(Const.NVL(std.getTableName(), ""));
            setTableFieldCombo();
        }
    } else {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
        mb.setMessage(BaseMessages.getString(PKG, "OraBulkLoaderDialog.InvalidConnection.DialogMessage"));
        mb.setText(BaseMessages.getString(PKG, "OraBulkLoaderDialog.InvalidConnection.DialogTitle"));
        mb.open();
    }
}
Also used : DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) DatabaseExplorerDialog(org.pentaho.di.ui.core.database.dialog.DatabaseExplorerDialog) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 5 with DatabaseExplorerDialog

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

the class JobEntryEvalTableContentDialog method getSQL.

private void getSQL() {
    DatabaseMeta inf = jobMeta.findDatabase(wConnection.getText());
    if (inf != null) {
        DatabaseExplorerDialog std = new DatabaseExplorerDialog(shell, SWT.NONE, inf, jobMeta.getDatabases());
        if (std.open()) {
            String sql = "SELECT *" + Const.CR + "FROM " + inf.getQuotedSchemaTableCombination(std.getSchemaName(), std.getTableName()) + Const.CR;
            wSQL.setText(sql);
            MessageBox yn = new MessageBox(shell, SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION);
            yn.setMessage(BaseMessages.getString(PKG, "JobEntryEvalTableContent.IncludeFieldNamesInSQL"));
            yn.setText(BaseMessages.getString(PKG, "JobEntryEvalTableContent.DialogCaptionQuestion"));
            int id = yn.open();
            switch(id) {
                case SWT.CANCEL:
                    break;
                case SWT.NO:
                    wSQL.setText(sql);
                    break;
                case SWT.YES:
                    Database db = new Database(loggingObject, inf);
                    try {
                        db.connect();
                        RowMetaInterface fields = db.getQueryFields(sql, false);
                        if (fields != null) {
                            sql = "SELECT" + Const.CR;
                            for (int i = 0; i < fields.size(); i++) {
                                ValueMetaInterface field = fields.getValueMeta(i);
                                if (i == 0) {
                                    sql += "  ";
                                } else {
                                    sql += ", ";
                                }
                                sql += inf.quoteField(field.getName()) + Const.CR;
                            }
                            sql += "FROM " + inf.getQuotedSchemaTableCombination(std.getSchemaName(), std.getTableName()) + Const.CR;
                            wSQL.setText(sql);
                        } else {
                            MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
                            mb.setMessage(BaseMessages.getString(PKG, "JobEntryEvalTableContent.ERROR_CouldNotRetrieveFields") + Const.CR + BaseMessages.getString(PKG, "JobEntryEvalTableContent.PerhapsNoPermissions"));
                            mb.setText(BaseMessages.getString(PKG, "JobEntryEvalTableContent.DialogCaptionError2"));
                            mb.open();
                        }
                    } catch (KettleException e) {
                        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
                        mb.setText(BaseMessages.getString(PKG, "JobEntryEvalTableContent.DialogCaptionError3"));
                        mb.setMessage(BaseMessages.getString(PKG, "JobEntryEvalTableContent.AnErrorOccurred") + Const.CR + e.getMessage());
                        mb.open();
                    } finally {
                        db.disconnect();
                    }
                    break;
                default:
                    break;
            }
        }
    } else {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
        mb.setMessage(BaseMessages.getString(PKG, "JobEntryEvalTableContent.ConnectionNoLongerAvailable"));
        mb.setText(BaseMessages.getString(PKG, "JobEntryEvalTableContent.DialogCaptionError4"));
        mb.open();
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) Database(org.pentaho.di.core.database.Database) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) DatabaseExplorerDialog(org.pentaho.di.ui.core.database.dialog.DatabaseExplorerDialog) MessageBox(org.eclipse.swt.widgets.MessageBox) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Aggregations

DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)29 DatabaseExplorerDialog (org.pentaho.di.ui.core.database.dialog.DatabaseExplorerDialog)29 MessageBox (org.eclipse.swt.widgets.MessageBox)27 Database (org.pentaho.di.core.database.Database)3 KettleException (org.pentaho.di.core.exception.KettleException)3 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)3 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)3 HasDatabasesInterface (org.pentaho.di.trans.HasDatabasesInterface)1