Search in sources :

Example 96 with Database

use of org.pentaho.di.core.database.Database in project pentaho-kettle by pentaho.

the class DeleteDialog method getSchemaNames.

private void getSchemaNames() {
    DatabaseMeta databaseMeta = transMeta.findDatabase(wConnection.getText());
    if (databaseMeta != null) {
        Database database = new Database(loggingObject, databaseMeta);
        try {
            database.connect();
            String[] schemas = database.getSchemas();
            if (null != schemas && schemas.length > 0) {
                schemas = Const.sortStrings(schemas);
                EnterSelectionDialog dialog = new EnterSelectionDialog(shell, schemas, BaseMessages.getString(PKG, "DeleteDialog.AvailableSchemas.Title", wConnection.getText()), BaseMessages.getString(PKG, "DeleteDialog.AvailableSchemas.Message", wConnection.getText()));
                String d = dialog.open();
                if (d != null) {
                    wSchema.setText(Const.NVL(d, ""));
                    setTableFieldCombo();
                }
            } else {
                MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
                mb.setMessage(BaseMessages.getString(PKG, "DeleteDialog.NoSchema.Error"));
                mb.setText(BaseMessages.getString(PKG, "DeleteDialog.GetSchemas.Error"));
                mb.open();
            }
        } catch (Exception e) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "DeleteDialog.ErrorGettingSchemas"), e);
        } finally {
            database.disconnect();
        }
    }
}
Also used : Database(org.pentaho.di.core.database.Database) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) EnterSelectionDialog(org.pentaho.di.ui.core.dialog.EnterSelectionDialog) KettleException(org.pentaho.di.core.exception.KettleException) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 97 with Database

use of org.pentaho.di.core.database.Database in project pentaho-kettle by pentaho.

the class DimensionLookupDialog method getFieldsFromTable.

private void getFieldsFromTable() {
    if (!gotTableFields) {
        if (!Utils.isEmpty(wTable.getText())) {
            DatabaseMeta ci = transMeta.findDatabase(wConnection.getText());
            if (ci != null) {
                Database db = new Database(loggingObject, ci);
                try {
                    db.connect();
                    RowMetaInterface r = db.getTableFieldsMeta(transMeta.environmentSubstitute(wSchema.getText()), transMeta.environmentSubstitute(wTable.getText()));
                    if (null != r) {
                        String[] fieldNames = r.getFieldNames();
                        if (null != fieldNames) {
                            // Version
                            String version = wVersion.getText();
                            wVersion.setItems(fieldNames);
                            if (version != null) {
                                wVersion.setText(version);
                            }
                            // from date
                            String fromdate = wFromdate.getText();
                            wFromdate.setItems(fieldNames);
                            if (fromdate != null) {
                                wFromdate.setText(fromdate);
                            }
                            // to date
                            String todate = wTodate.getText();
                            wTodate.setItems(fieldNames);
                            if (todate != null) {
                                wTodate.setText(todate);
                            }
                            // tk
                            String tk = wTk.getText();
                            wTk.setItems(fieldNames);
                            if (tk != null) {
                                wTk.setText(tk);
                            }
                            // AltStartDateField
                            String sd = wAltStartDateField.getText();
                            wAltStartDateField.setItems(fieldNames);
                            if (sd != null) {
                                wAltStartDateField.setText(sd);
                            }
                        }
                    }
                } catch (Exception e) {
                // ignore any errors here. drop downs will not be
                // filled, but no problem for the user
                }
            }
        }
        gotTableFields = true;
    }
}
Also used : Database(org.pentaho.di.core.database.Database) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) KettleException(org.pentaho.di.core.exception.KettleException)

Example 98 with Database

use of org.pentaho.di.core.database.Database in project pentaho-kettle by pentaho.

the class DimensionLookupDialog method getLookup.

/**
 * Get the fields from the table in the database and use them as lookup keys. Only get the the fields which are not
 * yet in use as key, or in the field table. Also ignore technical key, version, fromdate, todate.
 */
private void getLookup() {
    DatabaseMeta databaseMeta = transMeta.findDatabase(wConnection.getText());
    if (databaseMeta != null) {
        Database db = new Database(loggingObject, databaseMeta);
        db.shareVariablesWith(transMeta);
        try {
            db.connect();
            RowMetaInterface r = db.getTableFieldsMeta(wSchema.getText(), wTable.getText());
            if (r != null && !r.isEmpty()) {
                BaseStepDialog.getFieldsFromPrevious(r, wUpIns, 2, new int[] { 1, 2 }, new int[] { 3 }, -1, -1, new TableItemInsertListener() {

                    public boolean tableItemInserted(TableItem tableItem, ValueMetaInterface v) {
                        int idx = wKey.indexOfString(v.getName(), 2);
                        return idx < 0 && !v.getName().equalsIgnoreCase(wTk.getText()) && !v.getName().equalsIgnoreCase(wVersion.getText()) && !v.getName().equalsIgnoreCase(wFromdate.getText()) && !v.getName().equalsIgnoreCase(wTodate.getText());
                    }
                });
            }
        } catch (KettleException e) {
            MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
            mb.setText(BaseMessages.getString(PKG, "DimensionLookupDialog.ErrorOccurred.DialogTitle"));
            mb.setMessage(BaseMessages.getString(PKG, "DimensionLookupDialog.ErrorOccurred.DialogMessage") + Const.CR + e.getMessage());
            mb.open();
        } finally {
            db.disconnect();
        }
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) TableItemInsertListener(org.pentaho.di.ui.trans.step.TableItemInsertListener) TableItem(org.eclipse.swt.widgets.TableItem) Database(org.pentaho.di.core.database.Database) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 99 with Database

use of org.pentaho.di.core.database.Database in project pentaho-kettle by pentaho.

the class DimensionLookupDialog method setTableFieldCombo.

// Set table "dimension field" and "technical key" drop downs
private void setTableFieldCombo() {
    Runnable fieldLoader = new Runnable() {

        public void run() {
            if (!wTable.isDisposed() && !wConnection.isDisposed() && !wSchema.isDisposed()) {
                final String tableName = wTable.getText(), connectionName = wConnection.getText(), schemaName = wSchema.getText();
                // clear
                for (ColumnInfo colInfo : tableFieldColumns) {
                    colInfo.setComboValues(new String[] {});
                }
                // Ensure other table field dropdowns are refreshed fields when they
                // next get focus
                gotTableFields = false;
                if (!Utils.isEmpty(tableName)) {
                    DatabaseMeta ci = transMeta.findDatabase(connectionName);
                    if (ci != null) {
                        Database db = new Database(loggingObject, ci);
                        try {
                            db.connect();
                            RowMetaInterface r = db.getTableFieldsMeta(transMeta.environmentSubstitute(schemaName), transMeta.environmentSubstitute(tableName));
                            if (null != r) {
                                String[] fieldNames = r.getFieldNames();
                                if (null != fieldNames) {
                                    for (ColumnInfo colInfo : tableFieldColumns) {
                                        colInfo.setComboValues(fieldNames);
                                    }
                                    wTk.setItems(fieldNames);
                                }
                            }
                        } catch (Exception e) {
                            for (ColumnInfo colInfo : tableFieldColumns) {
                                colInfo.setComboValues(new String[] {});
                            }
                        // ignore any errors here. drop downs will not be
                        // filled, but no problem for the user
                        } finally {
                            try {
                                if (db != null) {
                                    db.disconnect();
                                }
                            } catch (Exception ignored) {
                                // ignore any errors here.
                                db = null;
                            }
                        }
                    }
                }
            }
        }
    };
    shell.getDisplay().asyncExec(fieldLoader);
}
Also used : Database(org.pentaho.di.core.database.Database) ColumnInfo(org.pentaho.di.ui.core.widget.ColumnInfo) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) KettleException(org.pentaho.di.core.exception.KettleException)

Example 100 with Database

use of org.pentaho.di.core.database.Database in project pentaho-kettle by pentaho.

the class LucidDBStreamingLoaderMeta method getRequiredFields.

public RowMetaInterface getRequiredFields(VariableSpace space) throws KettleException {
    String realTableName = space.environmentSubstitute(tableName);
    String realSchemaName = space.environmentSubstitute(schemaName);
    if (databaseMeta != null) {
        Database db = new Database(loggingObject, databaseMeta);
        try {
            db.connect();
            if (!Utils.isEmpty(realTableName)) {
                String schemaTable = databaseMeta.getQuotedSchemaTableCombination(realSchemaName, realTableName);
                // Check if this table exists...
                if (db.checkTableExists(schemaTable)) {
                    return db.getTableFields(schemaTable);
                } else {
                    throw new KettleException(BaseMessages.getString(PKG, "LucidDBStreamingLoaderMeta.Exception.TableNotFound"));
                }
            } else {
                throw new KettleException(BaseMessages.getString(PKG, "LucidDBStreamingLoaderMeta.Exception.TableNotSpecified"));
            }
        } catch (Exception e) {
            throw new KettleException(BaseMessages.getString(PKG, "LucidDBStreamingLoaderMeta.Exception.ErrorGettingFields"), e);
        } finally {
            db.disconnect();
        }
    } else {
        throw new KettleException(BaseMessages.getString(PKG, "LucidDBStreamingLoaderMeta.Exception.ConnectionNotDefined"));
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) Database(org.pentaho.di.core.database.Database) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleStepException(org.pentaho.di.core.exception.KettleStepException)

Aggregations

Database (org.pentaho.di.core.database.Database)238 KettleException (org.pentaho.di.core.exception.KettleException)135 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)90 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)82 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)62 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)46 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)32 KettleStepException (org.pentaho.di.core.exception.KettleStepException)30 MessageBox (org.eclipse.swt.widgets.MessageBox)28 CheckResult (org.pentaho.di.core.CheckResult)25 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)25 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)24 RowMeta (org.pentaho.di.core.row.RowMeta)22 SQLStatement (org.pentaho.di.core.SQLStatement)21 EnterSelectionDialog (org.pentaho.di.ui.core.dialog.EnterSelectionDialog)21 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)18 KettleValueException (org.pentaho.di.core.exception.KettleValueException)17 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)16 ColumnInfo (org.pentaho.di.ui.core.widget.ColumnInfo)15