use of org.pentaho.di.ui.core.dialog.PreviewRowsDialog in project pentaho-kettle by pentaho.
the class SQLEditor method exec.
private void exec() {
DatabaseMeta ci = connection;
if (ci == null) {
return;
}
StringBuilder message = new StringBuilder();
Database db = new Database(loggingObject, ci);
boolean first = true;
PartitionDatabaseMeta[] partitioningInformation = ci.getPartitioningInformation();
for (int partitionNr = 0; first || (partitioningInformation != null && partitionNr < partitioningInformation.length); partitionNr++) {
first = false;
String partitionId = null;
if (partitioningInformation != null && partitioningInformation.length > 0) {
partitionId = partitioningInformation[partitionNr].getPartitionId();
}
try {
db.connect(partitionId);
String sqlScript = Utils.isEmpty(wScript.getSelectionText()) ? wScript.getText() : wScript.getSelectionText();
// Multiple statements in the script need to be split into individual
// executable statements
statements = ci.getDatabaseInterface().getSqlScriptStatements(sqlScript + Const.CR);
int nrstats = 0;
for (SqlScriptStatement sql : statements) {
if (sql.isQuery()) {
// A Query
log.logDetailed("launch SELECT statement: " + Const.CR + sql);
nrstats++;
try {
List<Object[]> rows = db.getRows(sql.getStatement(), 1000);
RowMetaInterface rowMeta = db.getReturnRowMeta();
if (rows.size() > 0) {
PreviewRowsDialog prd = new PreviewRowsDialog(shell, ci, SWT.NONE, BaseMessages.getString(PKG, "SQLEditor.ResultRows.Title", Integer.toString(nrstats)), rowMeta, rows);
prd.open();
} else {
MessageBox mb = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
mb.setMessage(BaseMessages.getString(PKG, "SQLEditor.NoRows.Message", sql));
mb.setText(BaseMessages.getString(PKG, "SQLEditor.NoRows.Title"));
mb.open();
}
} catch (KettleDatabaseException dbe) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "SQLEditor.ErrorExecSQL.Title"), BaseMessages.getString(PKG, "SQLEditor.ErrorExecSQL.Message", sql), dbe);
}
} else {
log.logDetailed("launch DDL statement: " + Const.CR + sql);
// A DDL statement
nrstats++;
int startLogLine = KettleLogStore.getLastBufferLineNr();
try {
log.logDetailed("Executing SQL: " + Const.CR + sql);
db.execStatement(sql.getStatement());
message.append(BaseMessages.getString(PKG, "SQLEditor.Log.SQLExecuted", sql));
message.append(Const.CR);
// Clear the database cache, in case we're using one...
if (dbcache != null) {
dbcache.clear(ci.getName());
}
// mark the statement in green in the dialog...
//
sql.setOk(true);
} catch (Exception dbe) {
sql.setOk(false);
String error = BaseMessages.getString(PKG, "SQLEditor.Log.SQLExecError", sql, dbe.toString());
message.append(error).append(Const.CR);
ErrorDialog dialog = new ErrorDialog(shell, BaseMessages.getString(PKG, "SQLEditor.ErrorExecSQL.Title"), error, dbe, true);
if (dialog.isCancelled()) {
break;
}
} finally {
int endLogLine = KettleLogStore.getLastBufferLineNr();
sql.setLoggingText(KettleLogStore.getAppender().getLogBufferFromTo(db.getLogChannelId(), true, startLogLine, endLogLine).toString());
sql.setComplete(true);
refreshExecutionResults();
}
}
}
message.append(BaseMessages.getString(PKG, "SQLEditor.Log.StatsExecuted", Integer.toString(nrstats)));
if (partitionId != null) {
message.append(BaseMessages.getString(PKG, "SQLEditor.Log.OnPartition", partitionId));
}
message.append(Const.CR);
} catch (KettleDatabaseException dbe) {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
String error = BaseMessages.getString(PKG, "SQLEditor.Error.CouldNotConnect.Message", (connection == null ? "" : connection.getName()), dbe.getMessage());
message.append(error).append(Const.CR);
mb.setMessage(error);
mb.setText(BaseMessages.getString(PKG, "SQLEditor.Error.CouldNotConnect.Title"));
mb.open();
} finally {
db.disconnect();
refreshExecutionResults();
}
}
EnterTextDialog dialog = new EnterTextDialog(shell, BaseMessages.getString(PKG, "SQLEditor.Result.Title"), BaseMessages.getString(PKG, "SQLEditor.Result.Message"), message.toString(), true);
dialog.open();
}
use of org.pentaho.di.ui.core.dialog.PreviewRowsDialog in project pentaho-kettle by pentaho.
the class GetXMLDataDialog method preview.
// Preview the data
private void preview() {
try {
// Create the XML input step
GetXMLDataMeta oneMeta = new GetXMLDataMeta();
getInfo(oneMeta);
// check if the path is given
if (!checkLoopXPath(oneMeta)) {
return;
}
TransMeta previewMeta = TransPreviewFactory.generatePreviewTransformation(transMeta, oneMeta, wStepname.getText());
EnterNumberDialog numberDialog = new EnterNumberDialog(shell, props.getDefaultPreviewSize(), BaseMessages.getString(PKG, "GetXMLDataDialog.NumberRows.DialogTitle"), BaseMessages.getString(PKG, "GetXMLDataDialog.NumberRows.DialogMessage"));
int previewSize = numberDialog.open();
if (previewSize > 0) {
TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog(shell, previewMeta, new String[] { wStepname.getText() }, new int[] { previewSize });
progressDialog.open();
if (!progressDialog.isCancelled()) {
Trans trans = progressDialog.getTrans();
String loggingText = progressDialog.getLoggingText();
if (trans.getResult() != null && trans.getResult().getNrErrors() > 0) {
EnterTextDialog etd = new EnterTextDialog(shell, BaseMessages.getString(PKG, "System.Dialog.PreviewError.Title"), BaseMessages.getString(PKG, "System.Dialog.PreviewError.Message"), loggingText, true);
etd.setReadOnly();
etd.open();
}
PreviewRowsDialog prd = new PreviewRowsDialog(shell, transMeta, SWT.NONE, wStepname.getText(), progressDialog.getPreviewRowsMeta(wStepname.getText()), progressDialog.getPreviewRows(wStepname.getText()), loggingText);
prd.open();
}
}
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "GetXMLDataDialog.ErrorPreviewingData.DialogTitle"), BaseMessages.getString(PKG, "GetXMLDataDialog.ErrorPreviewingData.DialogMessage"), e);
}
}
use of org.pentaho.di.ui.core.dialog.PreviewRowsDialog in project pentaho-kettle by pentaho.
the class ScriptDialog method newTest.
private boolean newTest() {
PluginRegistry registry = PluginRegistry.getInstance();
String scriptStepName = wStepname.getText();
try {
// What fields are coming into the step?
//
RowMetaInterface rowMeta = transMeta.getPrevStepFields(stepname).clone();
if (rowMeta != null) {
//
if (genMeta == null) {
genMeta = new RowGeneratorMeta();
genMeta.setRowLimit("10");
genMeta.allocate(rowMeta.size());
// CHECKSTYLE:Indentation:OFF
for (int i = 0; i < rowMeta.size(); i++) {
ValueMetaInterface valueMeta = rowMeta.getValueMeta(i);
if (valueMeta.isStorageBinaryString()) {
valueMeta.setStorageType(ValueMetaInterface.STORAGE_TYPE_NORMAL);
}
genMeta.getFieldName()[i] = valueMeta.getName();
genMeta.getFieldType()[i] = valueMeta.getTypeDesc();
genMeta.getFieldLength()[i] = valueMeta.getLength();
genMeta.getFieldPrecision()[i] = valueMeta.getPrecision();
genMeta.getCurrency()[i] = valueMeta.getCurrencySymbol();
genMeta.getDecimal()[i] = valueMeta.getDecimalSymbol();
genMeta.getGroup()[i] = valueMeta.getGroupingSymbol();
String string = null;
switch(valueMeta.getType()) {
case ValueMetaInterface.TYPE_DATE:
genMeta.getFieldFormat()[i] = "yyyy/MM/dd HH:mm:ss";
valueMeta.setConversionMask(genMeta.getFieldFormat()[i]);
string = valueMeta.getString(new Date());
break;
case ValueMetaInterface.TYPE_STRING:
string = "test value test value";
break;
case ValueMetaInterface.TYPE_INTEGER:
genMeta.getFieldFormat()[i] = "#";
valueMeta.setConversionMask(genMeta.getFieldFormat()[i]);
string = valueMeta.getString(Long.valueOf(0L));
break;
case ValueMetaInterface.TYPE_NUMBER:
genMeta.getFieldFormat()[i] = "#.#";
valueMeta.setConversionMask(genMeta.getFieldFormat()[i]);
string = valueMeta.getString(Double.valueOf(0.0D));
break;
case ValueMetaInterface.TYPE_BIGNUMBER:
genMeta.getFieldFormat()[i] = "#.#";
valueMeta.setConversionMask(genMeta.getFieldFormat()[i]);
string = valueMeta.getString(BigDecimal.ZERO);
break;
case ValueMetaInterface.TYPE_BOOLEAN:
string = valueMeta.getString(Boolean.TRUE);
break;
case ValueMetaInterface.TYPE_BINARY:
string = valueMeta.getString(new byte[] { 65, 66, 67, 68, 69, 70, 71, 72, 73, 74 });
break;
default:
break;
}
genMeta.getValue()[i] = string;
}
}
StepMeta genStep = new StepMeta(registry.getPluginId(StepPluginType.class, genMeta), "## TEST DATA ##", genMeta);
genStep.setLocation(50, 50);
// Now create a JavaScript step with the information in this dialog
//
ScriptMeta scriptMeta = new ScriptMeta();
getInfo(scriptMeta);
StepMeta scriptStep = new StepMeta(registry.getPluginId(StepPluginType.class, scriptMeta), Const.NVL(scriptStepName, "## SCRIPT ##"), scriptMeta);
scriptStepName = scriptStep.getName();
scriptStep.setLocation(150, 50);
// Create a hop between both steps...
//
TransHopMeta hop = new TransHopMeta(genStep, scriptStep);
// Generate a new test transformation...
//
TransMeta transMeta = new TransMeta();
transMeta.setName(wStepname.getText() + " - PREVIEW");
transMeta.addStep(genStep);
transMeta.addStep(scriptStep);
transMeta.addTransHop(hop);
//
if (Spoon.getInstance().editStep(transMeta, genStep) != null) {
// Now run this transformation and grab the results...
//
TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog(shell, transMeta, new String[] { scriptStepName }, new int[] { Const.toInt(genMeta.getRowLimit(), 10) });
progressDialog.open();
Trans trans = progressDialog.getTrans();
String loggingText = progressDialog.getLoggingText();
if (!progressDialog.isCancelled()) {
if (trans.getResult() != null && trans.getResult().getNrErrors() > 0) {
EnterTextDialog etd = new EnterTextDialog(shell, BaseMessages.getString(PKG, "System.Dialog.PreviewError.Title"), BaseMessages.getString(PKG, "System.Dialog.PreviewError.Message"), loggingText, true);
etd.setReadOnly();
etd.open();
}
}
RowMetaInterface previewRowsMeta = progressDialog.getPreviewRowsMeta(wStepname.getText());
List<Object[]> previewRows = progressDialog.getPreviewRows(wStepname.getText());
if (previewRowsMeta != null && previewRows != null && previewRows.size() > 0) {
PreviewRowsDialog prd = new PreviewRowsDialog(shell, transMeta, SWT.NONE, wStepname.getText(), previewRowsMeta, previewRows, loggingText);
prd.open();
}
}
return true;
} else {
throw new KettleException(BaseMessages.getString(PKG, "ScriptDialog.Exception.CouldNotGetFields"));
}
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "ScriptDialog.TestFailed.DialogTitle"), BaseMessages.getString(PKG, "ScriptDialog.TestFailed.DialogMessage"), e);
return false;
}
}
use of org.pentaho.di.ui.core.dialog.PreviewRowsDialog in project pentaho-kettle by pentaho.
the class ScriptValuesModDialog method newTest.
private boolean newTest() {
PluginRegistry registry = PluginRegistry.getInstance();
String scriptStepName = wStepname.getText();
try {
// What fields are coming into the step?
//
RowMetaInterface rowMeta = transMeta.getPrevStepFields(stepname).clone();
if (rowMeta != null) {
//
if (genMeta == null) {
genMeta = new RowGeneratorMeta();
genMeta.setRowLimit("10");
genMeta.allocate(rowMeta.size());
// CHECKSTYLE:Indentation:OFF
for (int i = 0; i < rowMeta.size(); i++) {
ValueMetaInterface valueMeta = rowMeta.getValueMeta(i);
if (valueMeta.isStorageBinaryString()) {
valueMeta.setStorageType(ValueMetaInterface.STORAGE_TYPE_NORMAL);
}
genMeta.getFieldName()[i] = valueMeta.getName();
genMeta.getFieldType()[i] = valueMeta.getTypeDesc();
genMeta.getFieldLength()[i] = valueMeta.getLength();
genMeta.getFieldPrecision()[i] = valueMeta.getPrecision();
genMeta.getCurrency()[i] = valueMeta.getCurrencySymbol();
genMeta.getDecimal()[i] = valueMeta.getDecimalSymbol();
genMeta.getGroup()[i] = valueMeta.getGroupingSymbol();
String string = null;
switch(valueMeta.getType()) {
case ValueMetaInterface.TYPE_DATE:
genMeta.getFieldFormat()[i] = "yyyy/MM/dd HH:mm:ss";
valueMeta.setConversionMask(genMeta.getFieldFormat()[i]);
string = valueMeta.getString(new Date());
break;
case ValueMetaInterface.TYPE_STRING:
string = "test value test value";
break;
case ValueMetaInterface.TYPE_INTEGER:
genMeta.getFieldFormat()[i] = "#";
valueMeta.setConversionMask(genMeta.getFieldFormat()[i]);
string = valueMeta.getString(Long.valueOf(0L));
break;
case ValueMetaInterface.TYPE_NUMBER:
genMeta.getFieldFormat()[i] = "#.#";
valueMeta.setConversionMask(genMeta.getFieldFormat()[i]);
string = valueMeta.getString(Double.valueOf(0.0D));
break;
case ValueMetaInterface.TYPE_BIGNUMBER:
genMeta.getFieldFormat()[i] = "#.#";
valueMeta.setConversionMask(genMeta.getFieldFormat()[i]);
string = valueMeta.getString(BigDecimal.ZERO);
break;
case ValueMetaInterface.TYPE_BOOLEAN:
string = valueMeta.getString(Boolean.TRUE);
break;
case ValueMetaInterface.TYPE_BINARY:
string = valueMeta.getString(new byte[] { 65, 66, 67, 68, 69, 70, 71, 72, 73, 74 });
break;
default:
break;
}
genMeta.getValue()[i] = string;
}
}
StepMeta genStep = new StepMeta(registry.getPluginId(StepPluginType.class, genMeta), "## TEST DATA ##", genMeta);
genStep.setLocation(50, 50);
// Now create a JavaScript step with the information in this dialog
//
ScriptValuesMetaMod scriptMeta = new ScriptValuesMetaMod();
getInfo(scriptMeta);
StepMeta scriptStep = new StepMeta(registry.getPluginId(StepPluginType.class, scriptMeta), Const.NVL(scriptStepName, "## SCRIPT ##"), scriptMeta);
scriptStepName = scriptStep.getName();
scriptStep.setLocation(150, 50);
// Create a hop between both steps...
//
TransHopMeta hop = new TransHopMeta(genStep, scriptStep);
// Generate a new test transformation...
//
TransMeta transMeta = new TransMeta();
transMeta.setName(wStepname.getText() + " - PREVIEW");
transMeta.addStep(genStep);
transMeta.addStep(scriptStep);
transMeta.addTransHop(hop);
//
if (Spoon.getInstance().editStep(transMeta, genStep) != null) {
// Now run this transformation and grab the results...
//
TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog(shell, transMeta, new String[] { scriptStepName }, new int[] { Const.toInt(genMeta.getRowLimit(), 10) });
progressDialog.open();
Trans trans = progressDialog.getTrans();
String loggingText = progressDialog.getLoggingText();
if (!progressDialog.isCancelled()) {
if (trans.getResult() != null && trans.getResult().getNrErrors() > 0) {
EnterTextDialog etd = new EnterTextDialog(shell, BaseMessages.getString(PKG, "System.Dialog.PreviewError.Title"), BaseMessages.getString(PKG, "System.Dialog.PreviewError.Message"), loggingText, true);
etd.setReadOnly();
etd.open();
}
}
RowMetaInterface previewRowsMeta = progressDialog.getPreviewRowsMeta(wStepname.getText());
List<Object[]> previewRows = progressDialog.getPreviewRows(wStepname.getText());
if (previewRowsMeta != null && previewRows != null && previewRows.size() > 0) {
PreviewRowsDialog prd = new PreviewRowsDialog(shell, transMeta, SWT.NONE, wStepname.getText(), previewRowsMeta, previewRows, loggingText);
prd.open();
}
}
return true;
} else {
throw new KettleException(BaseMessages.getString(PKG, "ScriptValuesDialogMod.Exception.CouldNotGetFields"));
}
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "ScriptValuesDialogMod.TestFailed.DialogTitle"), BaseMessages.getString(PKG, "ScriptValuesDialogMod.TestFailed.DialogMessage"), e);
return false;
}
}
use of org.pentaho.di.ui.core.dialog.PreviewRowsDialog in project pentaho-kettle by pentaho.
the class SSHDialog method preview.
/**
* Preview the data generated by this step. This generates a transformation using this step & a dummy and previews it.
*/
private void preview() {
try {
// Create the Access input step
SSHMeta oneMeta = new SSHMeta();
getInfo(oneMeta);
TransMeta previewMeta = TransPreviewFactory.generatePreviewTransformation(transMeta, oneMeta, wStepname.getText());
EnterNumberDialog numberDialog = new EnterNumberDialog(shell, 1, BaseMessages.getString(PKG, "SSHDialog.NumberRows.DialogTitle"), BaseMessages.getString(PKG, "SSHDialog.NumberRows.DialogMessage"));
int previewSize = numberDialog.open();
if (previewSize > 0) {
TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog(shell, previewMeta, new String[] { wStepname.getText() }, new int[] { previewSize });
progressDialog.open();
if (!progressDialog.isCancelled()) {
Trans trans = progressDialog.getTrans();
String loggingText = progressDialog.getLoggingText();
if (trans.getResult() != null && trans.getResult().getNrErrors() > 0) {
EnterTextDialog etd = new EnterTextDialog(shell, BaseMessages.getString(PKG, "System.Dialog.PreviewError.Title"), BaseMessages.getString(PKG, "System.Dialog.PreviewError.Message"), loggingText, true);
etd.setReadOnly();
etd.open();
}
PreviewRowsDialog prd = new PreviewRowsDialog(shell, transMeta, SWT.NONE, wStepname.getText(), progressDialog.getPreviewRowsMeta(wStepname.getText()), progressDialog.getPreviewRows(wStepname.getText()), loggingText);
prd.open();
}
}
} catch (KettleException e) {
new ErrorDialog(shell, "Error", "Error while previewing data", e);
}
}
Aggregations