use of org.pentaho.actionsequence.dom.actions.MdxQueryAction in project pentaho-platform by pentaho.
the class MDXBaseComponent method validateAction.
@Override
protected boolean validateAction() {
boolean actionValidated = true;
MdxQueryAction queryAction = null;
MdxConnectionAction connAction = null;
try {
if (getActionDefinition() instanceof MdxQueryAction) {
queryAction = (MdxQueryAction) getActionDefinition();
actionValidated = isConnectionInfoSpecified(queryAction);
if (actionValidated) {
if (queryAction.getQuery() == ActionInputConstant.NULL_INPUT) {
error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0001_QUERY_NOT_SPECIFIED", // $NON-NLS-1$
getActionName()));
actionValidated = false;
}
}
if (actionValidated) {
if ((queryAction.getOutputResultSet() == null) && (queryAction.getOutputPreparedStatement() == null)) {
error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0003_OUTPUT_NOT_SPECIFIED", // $NON-NLS-1$
getActionName()));
actionValidated = false;
}
}
} else if (getActionDefinition() instanceof MdxConnectionAction) {
connAction = (MdxConnectionAction) getActionDefinition();
actionValidated = isConnectionInfoSpecified(connAction);
if (connAction.getOutputConnection() == null) {
error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0003_OUTPUT_NOT_SPECIFIED", // $NON-NLS-1$
getActionName()));
actionValidated = false;
}
}
} catch (Exception e) {
actionValidated = false;
error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0004_VALIDATION_FAILED", getActionName()), // $NON-NLS-1$
e);
}
return actionValidated;
}
use of org.pentaho.actionsequence.dom.actions.MdxQueryAction in project pentaho-platform by pentaho.
the class MDXBaseComponent method runQuery.
protected boolean runQuery(final IPentahoConnection localConnection, final String rawQuery) {
try {
if (localConnection == null) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0008_NO_CONNECTION"));
return false;
}
if (!localConnection.initialized()) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0008_NO_CONNECTION"));
return false;
}
if (rawQuery == null) {
error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0001_QUERY_NOT_SPECIFIED", // $NON-NLS-1$
getActionName()));
return false;
}
if (ComponentBase.debug) {
// $NON-NLS-1$
debug(Messages.getInstance().getString("MDXBaseComponent.DEBUG_RUNNING_QUERY", rawQuery));
}
// execute the query, read the results and cache them
IPentahoResultSet resultSet = localConnection.executeQuery(rawQuery);
if (resultSet != null && resultSet instanceof MDXResultSet) {
// BISERVER-3543 - set the result set to return formatted cell values
boolean formattedCellValues = false;
if (isDefinedInput(FORMATTED_CELL_VALUES)) {
formattedCellValues = getInputBooleanValue(FORMATTED_CELL_VALUES, false);
}
((MDXResultSet) resultSet).setFormattedCellValues(formattedCellValues);
}
rSet = resultSet;
if (resultSet != null) {
MdxQueryAction mdxQueryAction = (MdxQueryAction) getActionDefinition();
IActionOutput actionOutput = mdxQueryAction.getOutputResultSet();
if (actionOutput != null) {
actionOutput.setValue(resultSet);
}
return true;
} else {
// close the connection
error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0006_EXECUTE_FAILED", // $NON-NLS-1$
getActionName()));
localConnection.close();
return false;
}
} catch (Exception e) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0006_EXECUTE_FAILED", getActionName()), e);
}
return false;
}
use of org.pentaho.actionsequence.dom.actions.MdxQueryAction in project pentaho-platform by pentaho.
the class MDXBaseComponent method executeAction.
@Override
protected boolean executeAction() {
boolean value = false;
/*
* This is the query part. You would need a connection to execute the query. The connection will either come in as
* an INPUT (prepared_component) or will be specified right there.
*
* So check if a prepared component exists, if not create a new connection. If connection is not null, proceed to
* work on the query part.
*
* In the query section you can either execute the query right away or prepare it to be used later by a sub report.
*/
try {
if (getActionDefinition() instanceof MdxQueryAction) {
MdxQueryAction queryAction = (MdxQueryAction) getActionDefinition();
// instead of creating our own.
if (queryAction.getMdxConnection() != ActionInputConstant.NULL_INPUT) {
if (queryAction.getMdxConnection().getValue() != null) {
connectionOwner = false;
IPreparedComponent component = (IPreparedComponent) queryAction.getMdxConnection().getValue();
IPentahoConnection conn = component.shareConnection();
if (conn.getDatasourceType() == IPentahoConnection.MDX_DATASOURCE) {
connection = conn;
} else {
error(Messages.getInstance().getErrorString("IPreparedComponent.ERROR_0001_INVALID_CONNECTION_TYPE", // $NON-NLS-1$
getActionName()));
}
} else {
error(Messages.getInstance().getErrorString("IPreparedComponent.ERROR_0002_CONNECTION_NOT_AVAILABLE", // $NON-NLS-1$
getActionName()));
}
} else {
dispose();
connection = getDatasourceConnection();
}
if (connection != null) {
String query = queryAction.getQuery().getStringValue();
if (queryAction.getOutputPreparedStatement() != null) {
// prepare the query for execution, but don't execute quite yet.
prepareQuery(query);
// set the output as self, which will be used later by another component.
setOutputValue(IPreparedComponent.PREPARED_COMPONENT_NAME, this);
value = true;
} else {
value = runQuery(connection, query);
}
} else {
error(Messages.getInstance().getErrorString("IPreparedComponent.ERROR_0004_NO_CONNECTION_INFO", // $NON-NLS-1$
getActionName()));
}
} else if (getActionDefinition() instanceof MdxConnectionAction) {
dispose();
connection = getDatasourceConnection();
if (connection != null) {
setOutputValue(IPreparedComponent.PREPARED_COMPONENT_NAME, this);
value = true;
}
} else {
error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0004_VALIDATION_FAILED", // $NON-NLS-1$
getActionName()));
}
} catch (Exception e) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0006_EXECUTE_FAILED", getActionName()), e);
}
return value;
}
Aggregations