Search in sources :

Example 56 with RowMetaInterface

use of org.pentaho.di.core.row.RowMetaInterface in project pentaho-kettle by pentaho.

the class SynchronizeAfterMergeDialog method getUpdate.

private void getUpdate() {
    try {
        RowMetaInterface r = transMeta.getPrevStepFields(stepname);
        if (r != null) {
            TableItemInsertListener listener = new TableItemInsertListener() {

                public boolean tableItemInserted(TableItem tableItem, ValueMetaInterface v) {
                    tableItem.setText(3, "Y");
                    return true;
                }
            };
            BaseStepDialog.getFieldsFromPrevious(r, wReturn, 1, new int[] { 1, 2 }, new int[] {}, -1, -1, listener);
        }
    } catch (KettleException ke) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "SynchronizeAfterMergeDialog.FailedToGetFields.DialogTitle"), BaseMessages.getString(PKG, "SynchronizeAfterMergeDialog.FailedToGetFields.DialogMessage"), ke);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) TableItemInsertListener(org.pentaho.di.ui.trans.step.TableItemInsertListener) TableItem(org.eclipse.swt.widgets.TableItem) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 57 with RowMetaInterface

use of org.pentaho.di.core.row.RowMetaInterface in project pentaho-kettle by pentaho.

the class SynchronizeAfterMergeDialog method getFields.

private void getFields() {
    if (!gotPreviousFields) {
        try {
            String field = wTableField.getText();
            String fieldoperation = wOperationField.getText();
            RowMetaInterface r = transMeta.getPrevStepFields(stepname);
            if (r != null) {
                wTableField.setItems(r.getFieldNames());
                wOperationField.setItems(r.getFieldNames());
            }
            if (field != null) {
                wTableField.setText(field);
            }
            if (fieldoperation != null) {
                wOperationField.setText(fieldoperation);
            }
        } catch (KettleException ke) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "SynchronizeAfterMergeDialog.FailedToGetFields.DialogTitle"), BaseMessages.getString(PKG, "SynchronizeAfterMergeDialog.FailedToGetFields.DialogMessage"), ke);
        }
        gotPreviousFields = true;
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface)

Example 58 with RowMetaInterface

use of org.pentaho.di.core.row.RowMetaInterface in project pentaho-kettle by pentaho.

the class SyslogMessageDialog method get.

private void get() {
    if (!gotPreviousFields) {
        gotPreviousFields = true;
        try {
            String source = wMessageField.getText();
            wMessageField.removeAll();
            RowMetaInterface r = transMeta.getPrevStepFields(stepname);
            if (r != null) {
                wMessageField.setItems(r.getFieldNames());
                if (source != null) {
                    wMessageField.setText(source);
                }
            }
        } catch (KettleException ke) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "SyslogMessageDialog.FailedToGetFields.DialogTitle"), BaseMessages.getString(PKG, "SyslogMessageDialog.FailedToGetFields.DialogMessage"), ke);
        }
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface)

Example 59 with RowMetaInterface

use of org.pentaho.di.core.row.RowMetaInterface in project pentaho-kettle by pentaho.

the class SpoonDBDelegate method copyTable.

public boolean copyTable(DatabaseMeta sourceDBInfo, DatabaseMeta targetDBInfo, String tablename) {
    try {
        // 
        // Create a new transformation...
        // 
        TransMeta meta = new TransMeta();
        meta.addDatabase(sourceDBInfo);
        meta.addDatabase(targetDBInfo);
        // 
        // Add a note
        // 
        String note = BaseMessages.getString(PKG, "Spoon.Message.Note.ReadInformationFromTableOnDB", tablename, sourceDBInfo.getDatabaseName()) + // "Reads information from table ["+tablename+"]
        Const.CR;
        // on database ["+sourceDBInfo+"]"
        note += BaseMessages.getString(PKG, "Spoon.Message.Note.WriteInformationToTableOnDB", tablename, targetDBInfo.getDatabaseName());
        // the information to table
        // ["+tablename+"] on
        // database
        // ["+targetDBInfo+"]"
        NotePadMeta ni = new NotePadMeta(note, 150, 10, -1, -1);
        meta.addNote(ni);
        // 
        // create the source step...
        // 
        // "read
        String fromstepname = BaseMessages.getString(PKG, "Spoon.Message.Note.ReadFromTable", tablename);
        // from
        // ["+tablename+"]";
        TableInputMeta tii = new TableInputMeta();
        tii.setDatabaseMeta(sourceDBInfo);
        tii.setSQL("SELECT * FROM " + tablename);
        PluginRegistry registry = PluginRegistry.getInstance();
        String fromstepid = registry.getPluginId(StepPluginType.class, tii);
        StepMeta fromstep = new StepMeta(fromstepid, fromstepname, tii);
        fromstep.setLocation(150, 100);
        fromstep.setDraw(true);
        fromstep.setDescription(BaseMessages.getString(PKG, "Spoon.Message.Note.ReadInformationFromTableOnDB", tablename, sourceDBInfo.getDatabaseName()));
        meta.addStep(fromstep);
        // 
        // add logic to rename fields in case any of the field names contain
        // reserved words...
        // Use metadata logic in SelectValues, use SelectValueInfo...
        // 
        Database sourceDB = new Database(loggingObject, sourceDBInfo);
        sourceDB.shareVariablesWith(meta);
        sourceDB.connect();
        try {
            // Get the fields for the input table...
            RowMetaInterface fields = sourceDB.getTableFields(tablename);
            // See if we need to deal with reserved words...
            int nrReserved = targetDBInfo.getNrReservedWords(fields);
            if (nrReserved > 0) {
                SelectValuesMeta svi = new SelectValuesMeta();
                svi.allocate(0, 0, nrReserved);
                int nr = 0;
                // CHECKSTYLE:Indentation:OFF
                for (int i = 0; i < fields.size(); i++) {
                    ValueMetaInterface v = fields.getValueMeta(i);
                    if (targetDBInfo.isReservedWord(v.getName())) {
                        if (svi.getMeta()[nr] == null) {
                            svi.getMeta()[nr] = new SelectMetadataChange(svi);
                        }
                        svi.getMeta()[nr].setName(v.getName());
                        svi.getMeta()[nr].setRename(targetDBInfo.quoteField(v.getName()));
                        nr++;
                    }
                }
                String selstepname = BaseMessages.getString(PKG, "Spoon.Message.Note.HandleReservedWords");
                String selstepid = registry.getPluginId(StepPluginType.class, svi);
                StepMeta selstep = new StepMeta(selstepid, selstepname, svi);
                selstep.setLocation(350, 100);
                selstep.setDraw(true);
                selstep.setDescription(BaseMessages.getString(PKG, "Spoon.Message.Note.RenamesReservedWords", // 
                targetDBInfo.getPluginId()));
                meta.addStep(selstep);
                TransHopMeta shi = new TransHopMeta(fromstep, selstep);
                meta.addTransHop(shi);
                fromstep = selstep;
            }
            // 
            // Create the target step...
            // 
            // 
            // Add the TableOutputMeta step...
            // 
            String tostepname = BaseMessages.getString(PKG, "Spoon.Message.Note.WriteToTable", tablename);
            TableOutputMeta toi = new TableOutputMeta();
            toi.setDatabaseMeta(targetDBInfo);
            toi.setTableName(tablename);
            toi.setCommitSize(200);
            toi.setTruncateTable(true);
            String tostepid = registry.getPluginId(StepPluginType.class, toi);
            StepMeta tostep = new StepMeta(tostepid, tostepname, toi);
            tostep.setLocation(550, 100);
            tostep.setDraw(true);
            tostep.setDescription(BaseMessages.getString(PKG, "Spoon.Message.Note.WriteInformationToTableOnDB2", tablename, targetDBInfo.getDatabaseName()));
            meta.addStep(tostep);
            // 
            // Add a hop between the two steps...
            // 
            TransHopMeta hi = new TransHopMeta(fromstep, tostep);
            meta.addTransHop(hi);
            // OK, if we're still here: overwrite the current transformation...
            // Set a name on this generated transformation
            // 
            String name = "Copy table from [" + sourceDBInfo.getName() + "] to [" + targetDBInfo.getName() + "]";
            String transName = name;
            int nr = 1;
            if (spoon.delegates.trans.getTransformation(transName) != null) {
                nr++;
                transName = name + " " + nr;
            }
            meta.setName(transName);
            spoon.delegates.trans.addTransGraph(meta);
            spoon.refreshGraph();
            spoon.refreshTree();
        } finally {
            sourceDB.disconnect();
        }
    } catch (Exception e) {
        new ErrorDialog(spoon.getShell(), BaseMessages.getString(PKG, "Spoon.Dialog.UnexpectedError.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.UnexpectedError.Message"), new KettleException(e.getMessage(), e));
        return false;
    }
    return true;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) TransMeta(org.pentaho.di.trans.TransMeta) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) TableOutputMeta(org.pentaho.di.trans.steps.tableoutput.TableOutputMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) TableInputMeta(org.pentaho.di.trans.steps.tableinput.TableInputMeta) KettleException(org.pentaho.di.core.exception.KettleException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) SelectValuesMeta(org.pentaho.di.trans.steps.selectvalues.SelectValuesMeta) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) Database(org.pentaho.di.core.database.Database) SelectMetadataChange(org.pentaho.di.trans.steps.selectvalues.SelectMetadataChange) NotePadMeta(org.pentaho.di.core.NotePadMeta) TransHopMeta(org.pentaho.di.trans.TransHopMeta)

Example 60 with RowMetaInterface

use of org.pentaho.di.core.row.RowMetaInterface in project pentaho-kettle by pentaho.

the class EnterPreviewRowsDialog method show.

private void show() {
    if (rowDatas.size() == 0) {
        return;
    }
    int nr = wStepList.getSelectionIndex();
    java.util.List<Object[]> buffer = rowDatas.get(nr);
    RowMetaInterface rowMeta = rowMetas.get(nr);
    String name = stepNames.get(nr);
    if (rowMeta != null && buffer != null && buffer.size() > 0) {
        PreviewRowsDialog prd = new PreviewRowsDialog(shell, Variables.getADefaultVariableSpace(), SWT.NONE, name, rowMeta, buffer);
        prd.open();
    } else {
        MessageBox mb = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
        mb.setText(BaseMessages.getString(PKG, "EnterPreviewRowsDialog.Dialog.NoPreviewRowsFound.Title"));
        mb.setMessage(BaseMessages.getString(PKG, "EnterPreviewRowsDialog.Dialog.NoPreviewRowsFound.Message"));
        mb.open();
    }
}
Also used : RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) PreviewRowsDialog(org.pentaho.di.ui.core.dialog.PreviewRowsDialog) MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)908 KettleException (org.pentaho.di.core.exception.KettleException)369 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)330 RowMeta (org.pentaho.di.core.row.RowMeta)275 ArrayList (java.util.ArrayList)206 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)196 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)180 Test (org.junit.Test)169 StepMeta (org.pentaho.di.trans.step.StepMeta)150 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)142 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)110 KettleStepException (org.pentaho.di.core.exception.KettleStepException)107 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)101 TableItem (org.eclipse.swt.widgets.TableItem)84 ColumnInfo (org.pentaho.di.ui.core.widget.ColumnInfo)84 Database (org.pentaho.di.core.database.Database)81 TableItemInsertListener (org.pentaho.di.ui.trans.step.TableItemInsertListener)79 FormAttachment (org.eclipse.swt.layout.FormAttachment)76 FormData (org.eclipse.swt.layout.FormData)76 FormLayout (org.eclipse.swt.layout.FormLayout)76