Search in sources :

Example 1 with MdxQueryAction

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;
}
Also used : MdxConnectionAction(org.pentaho.actionsequence.dom.actions.MdxConnectionAction) MdxQueryAction(org.pentaho.actionsequence.dom.actions.MdxQueryAction) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)

Example 2 with MdxQueryAction

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

Example 3 with MdxQueryAction

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;
}
Also used : IPentahoConnection(org.pentaho.commons.connection.IPentahoConnection) MdxConnectionAction(org.pentaho.actionsequence.dom.actions.MdxConnectionAction) MdxQueryAction(org.pentaho.actionsequence.dom.actions.MdxQueryAction) IPreparedComponent(org.pentaho.platform.api.data.IPreparedComponent) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)

Aggregations

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