use of org.pentaho.actionsequence.dom.IActionOutput in project pentaho-platform by pentaho.
the class MQLRelationalDataComponent method executeAction.
@Override
public boolean executeAction() {
//
// For backwards compatibility, call into the new metadata query component
//
MetadataQueryComponent component = new MetadataQueryComponent();
// setup component
MQLAction actionDefinition = (MQLAction) getActionDefinition();
String mql = actionDefinition.getQuery().getStringValue();
component.setQuery(mql);
if (actionDefinition.getMaxRows() != ActionInputConstant.NULL_INPUT) {
component.setMaxRows(actionDefinition.getMaxRows().getIntValue());
}
if (actionDefinition.getQueryTimeout() != ActionInputConstant.NULL_INPUT) {
component.setTimeout(actionDefinition.getQueryTimeout().getIntValue());
}
if (actionDefinition.getReadOnly() != ActionInputConstant.NULL_INPUT) {
component.setReadOnly(actionDefinition.getReadOnly().getBooleanValue());
}
// log the sql to info if set
if (isDefinedInput("logSql")) {
// $NON-NLS-1$
// $NON-NLS-1$ //$NON-NLS-2$
component.setLogSql("true".equals(actionDefinition.getInput("logSql").getStringValue()));
}
// TODO: We also need to pass in the component definitions
Set<String> inputNames = getInputNames();
if (inputNames != null) {
Map<String, Object> inputMap = new HashMap<String, Object>();
for (String inputName : inputNames) {
inputMap.put(ActionDefinitionEncoder.decodeBlankSpaces(inputName), getInputValue(inputName));
}
component.setInputs(inputMap);
}
boolean success = component.execute();
if (success) {
IActionOutput actionOutput = actionDefinition.getOutputResultSet();
if (actionOutput != null) {
actionOutput.setValue(component.getResultSet());
}
}
return success;
}
use of org.pentaho.actionsequence.dom.IActionOutput in project pentaho-platform by pentaho.
the class SQLBaseComponent method runQuery.
/**
* executes the specified query template. The query template is first formatted and then executed. If live, the
* original result set is made available as an output. If not live, the result set is converted into memory and the
* connection and live result set are closed.
*
* @param rawQuery
* query template
* @param live
* returns original result set if true, memory result set if false
* @return true if successful
*/
protected boolean runQuery(final String rawQuery, boolean live) {
try {
if ((connection == null) || !connection.initialized()) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("SQLBaseComponent.ERROR_0007_NO_CONNECTION"));
return false;
}
String query = applyInputsToFormat(rawQuery);
SQLConnection sqlConnection = null;
if ((connection instanceof SQLConnection)) {
sqlConnection = (SQLConnection) connection;
}
// Some of the following Added by Arijit Chatterjee passing the timeout value to SQLConnection class
if (sqlConnection != null) {
if (this.getQueryTimeout() >= 0) {
sqlConnection.setQueryTimeout(this.getQueryTimeout());
}
if (this.getMaxRows() >= 0) {
sqlConnection.setMaxRows(this.getMaxRows());
}
if (this.getReadOnly()) {
sqlConnection.setReadOnly(true);
}
}
AbstractRelationalDbAction relationalDbAction = (AbstractRelationalDbAction) getActionDefinition();
IPentahoResultSet resultSet = null;
boolean isForwardOnly = relationalDbAction.getUseForwardOnlyResultSet().getBooleanValue(false);
resultSet = doQuery(sqlConnection, query, isForwardOnly);
if (sqlConnection.isForcedForwardOnly()) {
isForwardOnly = true;
live = false;
// $NON-NLS-1$
warn(Messages.getInstance().getString("SQLBaseComponent.WARN_FALL_BACK_TO_NONSCROLLABLE"));
}
if (live) {
// set the result set as the output
rSet = resultSet;
// After preparation and execution, we need to clear out the
// prepared parameters.
preparedParameters.clear();
if (resultSet != null) {
getMetadata(resultSet, true);
IActionOutput actionOutput = relationalDbAction.getOutputResultSet();
if (actionOutput != null) {
actionOutput.setValue(resultSet);
}
return true;
} else {
// close the connection if owner
error(Messages.getInstance().getErrorString("SQLBaseComponent.ERROR_0006_EXECUTE_FAILED", // $NON-NLS-1$
getActionName()));
if (connectionOwner) {
connection.close();
}
return false;
}
} else {
// execute the query, read the results and cache them
try {
// After preparation and execution, we need to clear out the
// prepared parameters.
preparedParameters.clear();
IPentahoResultSet cachedResultSet = resultSet.memoryCopy();
rSet = cachedResultSet;
IActionOutput actionOutput = relationalDbAction.getOutputResultSet();
if (actionOutput != null) {
actionOutput.setValue(cachedResultSet);
}
} finally {
// close the connection if owner
if (connectionOwner) {
connection.close();
connection = null;
}
}
}
return true;
} catch (Exception e) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("SQLBaseComponent.ERROR_0006_EXECUTE_FAILED", getActionName()), e);
}
return false;
}
use of org.pentaho.actionsequence.dom.IActionOutput in project pentaho-platform by pentaho.
the class HQLBaseComponent method runQuery.
protected boolean runQuery(final IPentahoConnection conn, final String[] classNames, final String query) {
try {
if (conn == null) {
return false;
}
rSet = ((HQLConnection) conn).executeQuery(query);
IActionOutput actionOutput = ((HQLQueryAction) getActionDefinition()).getOutputResultSetParam();
if (actionOutput != null) {
actionOutput.setValue(rSet);
}
return true;
} catch (Exception e) {
error(Messages.getInstance().getErrorString("HQLBaseComponent.ERROR_0007_QUERY_EXECUTION_FAILED", getActionName()), // $NON-NLS-1$
e);
return false;
}
}
use of org.pentaho.actionsequence.dom.IActionOutput in project pentaho-platform by pentaho.
the class ResultSetCompareComponent method compareEquals.
private boolean compareEquals(final IPentahoResultSet rs1, final IPentahoResultSet rs2, final int compareCol, boolean outputMismatches, final boolean stopOnError) {
int sourceRowCount = rs1.getRowCount();
int sourceColCount = rs1.getColumnCount();
int compRowCount = rs2.getRowCount();
int compColCount = rs2.getColumnCount();
StringBuffer outputBuf = new StringBuffer();
if (!outputMismatches) {
if (sourceRowCount != compRowCount) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("ResultSetCompareComponent.ERROR_0006_RESULTSETS_ROWCOUNT_WRONG"));
return false;
}
if (sourceColCount != compColCount) {
error(Messages.getInstance().getErrorString(// $NON-NLS-1$
"ResultSetCompareComponent.ERROR_0007_RESULTSETS_COLUMNCOUNT_WRONG"));
return false;
}
}
if (compareCol > sourceColCount) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("ResultSetCompareComponent.ERROR_0008_COLUMN_NOT_FOUND") + compareCol);
return false;
}
if (compareCol > compColCount) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("ResultSetCompareComponent.ERROR_0009_COMPARISON_COLUMN_NOT_FOUND") + compareCol);
return false;
}
boolean anyMismatches = false;
boolean foundIt;
Object srcValue = null, compValue = null;
ResultSetCompareAction compareAction = (ResultSetCompareAction) getActionDefinition();
IActionOutput output = compareAction.getOutputCompareResult();
for (int sourceRows = 0; sourceRows < sourceRowCount; sourceRows++) {
foundIt = false;
srcValue = rs1.getValueAt(sourceRows, compareCol);
// n+1 traversal. This accommodates non-ordered input
for (int compRows = 0; compRows < compRowCount; compRows++) {
compValue = rs2.getValueAt(compRows, compareCol);
if (compValue.equals(srcValue)) {
foundIt = true;
break;
}
}
if (!foundIt) {
if (outputBuf.length() > 0) {
// $NON-NLS-1$
outputBuf.append(",").append(srcValue.toString().trim());
} else {
outputBuf.append(srcValue.toString().trim());
}
if (output != null) {
output.setValue(outputBuf.toString());
}
if (outputMismatches) {
error(Messages.getInstance().getErrorString("ResultSetCompareComponent.ERROR_0010_MISMATCH_OUTPUT", // $NON-NLS-1$
srcValue.toString()));
anyMismatches = true;
} else {
if (stopOnError) {
return false;
}
}
}
}
if (!anyMismatches) {
if (output != null) {
output.setValue(ResultSetCompareComponent.COMPARE_RESULT_OK);
}
}
return stopOnError ? !anyMismatches : true;
}
use of org.pentaho.actionsequence.dom.IActionOutput in project pentaho-platform by pentaho.
the class UtilityComponent method executeCopyAction.
private boolean executeCopyAction(final CopyParamAction copyParamAction) {
boolean result = true;
IActionInput actionInput = copyParamAction.getCopyFrom();
IActionOutput actionOutput = copyParamAction.getOutputCopy();
if ((actionInput instanceof ActionInput) && (actionOutput != null)) {
try {
actionOutput.setValue(actionInput.getValue());
} catch (Exception ex) {
result = false;
}
}
return result;
}
Aggregations