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);
}
}
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;
}
}
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);
}
}
}
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;
}
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();
}
}
Aggregations