Search in sources :

Example 1 with DatabaseExplorerDialog

use of org.apache.hop.ui.core.database.dialog.DatabaseExplorerDialog in project hop by apache.

the class ActionEvalTableContentDialog method getSql.

private void getSql() {
    DatabaseMeta inf = getWorkflowMeta().findDatabase(wConnection.getText());
    if (inf != null) {
        DatabaseExplorerDialog std = new DatabaseExplorerDialog(shell, SWT.NONE, variables, inf, getWorkflowMeta().getDatabases());
        if (std.open()) {
            String sql = "SELECT *" + Const.CR + "FROM " + inf.getQuotedSchemaTableCombination(variables, 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, "ActionEvalTableContent.IncludeFieldNamesInSQL"));
            yn.setText(BaseMessages.getString(PKG, "ActionEvalTableContent.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, variables, inf);
                    try {
                        db.connect();
                        IRowMeta fields = db.getQueryFields(sql, false);
                        if (fields != null) {
                            sql = "SELECT" + Const.CR;
                            for (int i = 0; i < fields.size(); i++) {
                                IValueMeta field = fields.getValueMeta(i);
                                if (i == 0) {
                                    sql += "  ";
                                } else {
                                    sql += ", ";
                                }
                                sql += inf.quoteField(field.getName()) + Const.CR;
                            }
                            sql += "FROM " + inf.getQuotedSchemaTableCombination(variables, 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, "ActionEvalTableContent.ERROR_CouldNotRetrieveFields") + Const.CR + BaseMessages.getString(PKG, "ActionEvalTableContent.PerhapsNoPermissions"));
                            mb.setText(BaseMessages.getString(PKG, "ActionEvalTableContent.DialogCaptionError2"));
                            mb.open();
                        }
                    } catch (HopException e) {
                        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
                        mb.setText(BaseMessages.getString(PKG, "ActionEvalTableContent.DialogCaptionError3"));
                        mb.setMessage(BaseMessages.getString(PKG, "ActionEvalTableContent.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, "ActionEvalTableContent.ConnectionNoLongerAvailable"));
        mb.setText(BaseMessages.getString(PKG, "ActionEvalTableContent.DialogCaptionError4"));
        mb.open();
    }
}
Also used : IValueMeta(org.apache.hop.core.row.IValueMeta) HopException(org.apache.hop.core.exception.HopException) IRowMeta(org.apache.hop.core.row.IRowMeta) Database(org.apache.hop.core.database.Database) DatabaseMeta(org.apache.hop.core.database.DatabaseMeta) DatabaseExplorerDialog(org.apache.hop.ui.core.database.dialog.DatabaseExplorerDialog)

Example 2 with DatabaseExplorerDialog

use of org.apache.hop.ui.core.database.dialog.DatabaseExplorerDialog in project hop by apache.

the class PGBulkLoaderDialog method getTableName.

private void getTableName() {
    String connectionName = wConnection.getText();
    if (StringUtils.isEmpty(connectionName)) {
        return;
    }
    DatabaseMeta databaseMeta = pipelineMeta.findDatabase(connectionName);
    if (databaseMeta != null) {
        logDebug(BaseMessages.getString(PKG, "PGBulkLoaderDialog.Log.LookingAtConnection") + databaseMeta.toString());
        DatabaseExplorerDialog std = new DatabaseExplorerDialog(shell, SWT.NONE, variables, databaseMeta, pipelineMeta.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, "PGBulkLoaderDialog.InvalidConnection.DialogMessage"));
        mb.setText(BaseMessages.getString(PKG, "PGBulkLoaderDialog.InvalidConnection.DialogTitle"));
        mb.open();
    }
}
Also used : DatabaseMeta(org.apache.hop.core.database.DatabaseMeta) DatabaseExplorerDialog(org.apache.hop.ui.core.database.dialog.DatabaseExplorerDialog)

Example 3 with DatabaseExplorerDialog

use of org.apache.hop.ui.core.database.dialog.DatabaseExplorerDialog in project hop by apache.

the class ColumnExistsDialog method getTableName.

private void getTableName() {
    String connectionName = wConnection.getText();
    if (StringUtils.isEmpty(connectionName)) {
        return;
    }
    DatabaseMeta databaseMeta = pipelineMeta.findDatabase(connectionName);
    if (databaseMeta != null) {
        DatabaseExplorerDialog std = new DatabaseExplorerDialog(shell, SWT.NONE, variables, databaseMeta, pipelineMeta.getDatabases());
        std.setSelectedSchemaAndTable(wSchemaname.getText(), wTablenameText.getText());
        if (std.open()) {
            wSchemaname.setText(Const.NVL(std.getSchemaName(), ""));
            wTablenameText.setText(Const.NVL(std.getTableName(), ""));
        }
    } else {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
        mb.setMessage(BaseMessages.getString(PKG, "ColumnExistsDialog.ConnectionError2.DialogMessage"));
        mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title"));
        mb.open();
    }
}
Also used : DatabaseMeta(org.apache.hop.core.database.DatabaseMeta) DatabaseExplorerDialog(org.apache.hop.ui.core.database.dialog.DatabaseExplorerDialog)

Example 4 with DatabaseExplorerDialog

use of org.apache.hop.ui.core.database.dialog.DatabaseExplorerDialog in project hop by apache.

the class SQLFileOutputDialog method getTableName.

private void getTableName() {
    String connectionName = wConnection.getText();
    if (StringUtils.isEmpty(connectionName)) {
        return;
    }
    DatabaseMeta databaseMeta = pipelineMeta.findDatabase(connectionName);
    if (databaseMeta != null) {
        logDebug(BaseMessages.getString(PKG, "SQLFileOutputDialog.Log.LookingAtConnection", databaseMeta.toString()));
        DatabaseExplorerDialog std = new DatabaseExplorerDialog(shell, SWT.NONE, variables, databaseMeta, pipelineMeta.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, "SQLFileOutputDialog.ConnectionError2.DialogMessage"));
        mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title"));
        mb.open();
    }
}
Also used : DatabaseMeta(org.apache.hop.core.database.DatabaseMeta) DatabaseExplorerDialog(org.apache.hop.ui.core.database.dialog.DatabaseExplorerDialog)

Example 5 with DatabaseExplorerDialog

use of org.apache.hop.ui.core.database.dialog.DatabaseExplorerDialog in project hop by apache.

the class ActionColumnsExistDialog method getTableName.

private void getTableName() {
    String databaseName = wConnection.getText();
    if (StringUtils.isNotEmpty(databaseName)) {
        DatabaseMeta databaseMeta = this.getWorkflowMeta().findDatabase(databaseName);
        if (databaseMeta != null) {
            DatabaseExplorerDialog std = new DatabaseExplorerDialog(shell, SWT.NONE, variables, databaseMeta, this.getWorkflowMeta().getDatabases());
            std.setSelectedSchemaAndTable(wSchemaname.getText(), wTablename.getText());
            if (std.open()) {
                wSchemaname.setText(Const.NVL(std.getSchemaName(), ""));
                wTablename.setText(Const.NVL(std.getTableName(), ""));
            }
        } else {
            MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
            mb.setMessage(BaseMessages.getString(PKG, "ActionColumnsExist.ConnectionError.DialogMessage"));
            mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title"));
            mb.open();
        }
    }
}
Also used : DatabaseMeta(org.apache.hop.core.database.DatabaseMeta) DatabaseExplorerDialog(org.apache.hop.ui.core.database.dialog.DatabaseExplorerDialog)

Aggregations

DatabaseExplorerDialog (org.apache.hop.ui.core.database.dialog.DatabaseExplorerDialog)23 DatabaseMeta (org.apache.hop.core.database.DatabaseMeta)22 Database (org.apache.hop.core.database.Database)3 HopException (org.apache.hop.core.exception.HopException)3 IRowMeta (org.apache.hop.core.row.IRowMeta)3 IValueMeta (org.apache.hop.core.row.IValueMeta)3 ErrorDialog (org.apache.hop.ui.core.dialog.ErrorDialog)1