Search in sources :

Example 36 with DatabaseMeta

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

the class GPLoadDialog method setTableFieldCombo.

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[] {});
                }
                if (!Utils.isEmpty(tableName)) {
                    DatabaseMeta ci = transMeta.findDatabase(connectionName);
                    if (ci != null) {
                        Database db = new Database(loggingObject, ci);
                        try {
                            db.connect();
                            String schemaTable = ci.getQuotedSchemaTableCombination(transMeta.environmentSubstitute(schemaName), transMeta.environmentSubstitute(tableName));
                            RowMetaInterface r = db.getTableFields(schemaTable);
                            if (null != r) {
                                String[] fieldNames = r.getFieldNames();
                                if (null != fieldNames) {
                                    for (ColumnInfo colInfo : tableFieldColumns) {
                                        colInfo.setComboValues(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
                        }
                    }
                }
            }
        }
    };
    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 37 with DatabaseMeta

use of org.pentaho.di.core.database.DatabaseMeta 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 38 with DatabaseMeta

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

the class GPBulkLoader method getControlFileContents.

/**
 * Get the contents of the control file as specified in the meta object
 *
 * @param meta
 *          the meta object to model the control file after
 *
 * @return a string containing the control file contents
 */
public String getControlFileContents(GPBulkLoaderMeta meta, RowMetaInterface rm, Object[] r) throws KettleException {
    DatabaseMeta dm = meta.getDatabaseMeta();
    String inputName = "'" + environmentSubstitute(meta.getDataFile()) + "'";
    // if ( GPBulkLoaderMeta.METHOD_AUTO_CONCURRENT.equals(meta.getLoadMethod()) )
    // {
    // // if loading is concurrent, the filename has to be a * as sqlldr will
    // // read from stdin.
    // inputName = "*";
    // }
    String loadAction = meta.getLoadAction();
    StringBuffer contents = new StringBuffer(500);
    String tableName = dm.getQuotedSchemaTableCombination(environmentSubstitute(meta.getSchemaName()), environmentSubstitute(meta.getTableName()));
    // Create a Postgres / Greenplum COPY string for use with a psql client
    if (loadAction.equalsIgnoreCase("truncate")) {
        contents.append(loadAction + " ");
        contents.append(tableName + ";");
        contents.append(Const.CR);
    }
    contents.append("\\COPY ");
    // Table name
    contents.append(tableName);
    // Names of columns
    contents.append(" ( ");
    String[] streamFields = meta.getFieldStream();
    String[] tableFields = meta.getFieldTable();
    if (streamFields == null || streamFields.length == 0) {
        throw new KettleException("No fields defined to load to database");
    }
    for (int i = 0; i < streamFields.length; i++) {
        if (i != 0) {
            contents.append(", ");
        }
        contents.append(dm.quoteField(tableFields[i]));
    }
    contents.append(" ) ");
    // The "FROM" filename
    contents.append(" FROM ");
    contents.append(inputName);
    // The "FORMAT" clause
    contents.append(" WITH CSV ");
    // The single row error handling
    contents.append("LOG ERRORS INTO ");
    contents.append(tableName + "_errors ");
    contents.append(" SEGMENT REJECT LIMIT ");
    contents.append(meta.getMaxErrors());
    return contents.toString();
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta)

Example 39 with DatabaseMeta

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

the class GPBulkLoaderDialog method setTableFieldCombo.

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[] {});
                }
                if (!Utils.isEmpty(tableName)) {
                    DatabaseMeta ci = transMeta.findDatabase(connectionName);
                    if (ci != null) {
                        Database db = new Database(loggingObject, ci);
                        try {
                            db.connect();
                            String schemaTable = ci.getQuotedSchemaTableCombination(transMeta.environmentSubstitute(schemaName), transMeta.environmentSubstitute(tableName));
                            RowMetaInterface r = db.getTableFields(schemaTable);
                            if (null != r) {
                                String[] fieldNames = r.getFieldNames();
                                if (null != fieldNames) {
                                    for (ColumnInfo colInfo : tableFieldColumns) {
                                        colInfo.setComboValues(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
                        }
                    }
                }
            }
        }
    };
    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 40 with DatabaseMeta

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

Aggregations

DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)522 Test (org.junit.Test)133 KettleException (org.pentaho.di.core.exception.KettleException)131 Database (org.pentaho.di.core.database.Database)88 MessageBox (org.eclipse.swt.widgets.MessageBox)66 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)63 TransMeta (org.pentaho.di.trans.TransMeta)57 StepMeta (org.pentaho.di.trans.step.StepMeta)54 ArrayList (java.util.ArrayList)53 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)48 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)44 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)42 SlaveServer (org.pentaho.di.cluster.SlaveServer)33 IMetaStore (org.pentaho.metastore.api.IMetaStore)30 ObjectId (org.pentaho.di.repository.ObjectId)29 DatabaseExplorerDialog (org.pentaho.di.ui.core.database.dialog.DatabaseExplorerDialog)29 JobMeta (org.pentaho.di.job.JobMeta)26 TransHopMeta (org.pentaho.di.trans.TransHopMeta)26 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)24 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)24