Search in sources :

Example 1 with MDXResultSet

use of org.pentaho.platform.plugin.services.connections.mondrian.MDXResultSet 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;
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) IActionOutput(org.pentaho.actionsequence.dom.IActionOutput) MDXResultSet(org.pentaho.platform.plugin.services.connections.mondrian.MDXResultSet) MdxQueryAction(org.pentaho.actionsequence.dom.actions.MdxQueryAction) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)

Aggregations

IActionOutput (org.pentaho.actionsequence.dom.IActionOutput)1 MdxQueryAction (org.pentaho.actionsequence.dom.actions.MdxQueryAction)1 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)1 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)1 MDXResultSet (org.pentaho.platform.plugin.services.connections.mondrian.MDXResultSet)1