Search in sources :

Example 1 with HQLQueryAction

use of org.pentaho.actionsequence.dom.actions.HQLQueryAction in project pentaho-platform by pentaho.

the class HQLBaseComponent method validateAction.

@Override
protected boolean validateAction() {
    HQLConnectionAction connAction = null;
    HQLQueryAction queryAction = null;
    boolean actionValidated = true;
    try {
        if (getActionDefinition() instanceof HQLQueryAction) {
            queryAction = (HQLQueryAction) getActionDefinition();
            actionValidated = isConnectionInfoSpecified(queryAction);
            // Check if the query is defined.
            if (actionValidated && (queryAction.getQuery() == ActionInputConstant.NULL_INPUT)) {
                actionValidated = false;
                error(Messages.getInstance().getErrorString("HQLBaseComponent.ERROR_0004_QUERY_NOT_SPECIFIED", // $NON-NLS-1$
                getActionName()));
            }
            // Check if output for the query is correctly defined.
            if (actionValidated && (queryAction.getOutputResultSetName() == null) && (queryAction.getOutputPreparedStatementName() == null)) {
                actionValidated = false;
                error(Messages.getInstance().getErrorString("HQLBaseComponent.ERROR_0005_OUTPUT_NOT_SPECIFIED", // $NON-NLS-1$
                getActionName()));
            }
        } else if (getActionDefinition() instanceof HQLConnectionAction) {
            connAction = (HQLConnectionAction) getActionDefinition();
            actionValidated = isConnectionInfoSpecified(connAction);
        } else {
            actionValidated = false;
            error(Messages.getInstance().getErrorString("ComponentBase.ERROR_0001_UNKNOWN_ACTION_TYPE", // $NON-NLS-1$
            getActionDefinition().getElement().asXML()));
        }
    } catch (Exception e) {
        actionValidated = false;
        error(Messages.getInstance().getErrorString("HQLBaseComponent.ERROR_0006_VALIDATION_FAILED", getActionName()), // $NON-NLS-1$
        e);
    }
    return actionValidated;
}
Also used : HQLConnectionAction(org.pentaho.actionsequence.dom.actions.HQLConnectionAction) HQLQueryAction(org.pentaho.actionsequence.dom.actions.HQLQueryAction)

Example 2 with HQLQueryAction

use of org.pentaho.actionsequence.dom.actions.HQLQueryAction in project pentaho-platform by pentaho.

the class HQLBaseComponent method executeAction.

@Override
protected boolean executeAction() {
    boolean returnValue = true;
    try {
        if (getActionDefinition() instanceof HQLQueryAction) {
            HQLQueryAction queryAction = (HQLQueryAction) getActionDefinition();
            String[] classNames = null;
            String query = queryAction.getQuery().getStringValue();
            if (queryAction.getInputSharedConnection() != ActionInputConstant.NULL_INPUT) {
                connectionOwner = false;
                IPreparedComponent component = (IPreparedComponent) queryAction.getInputSharedConnection().getValue();
                IPentahoConnection conn = component.shareConnection();
                if (IPentahoConnection.HQL_DATASOURCE.equals(conn.getDatasourceType())) {
                    connection = conn;
                } else {
                    connection = null;
                    returnValue = false;
                    error(Messages.getInstance().getErrorString("IPreparedComponent.ERROR_0001_INVALID_CONNECTION_TYPE", // $NON-NLS-1$
                    getActionName()));
                }
            } else {
                createBasicConnection(queryAction, classNames);
            }
            if (connection != null) {
                IActionOutput actionOutput = queryAction.getOutputPreparedStatementParam();
                if (actionOutput != 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.
                    actionOutput.setValue(this);
                } else {
                    return runQuery(connection, classNames, query);
                }
            }
        } else if (getActionDefinition() instanceof HQLConnectionAction) {
            HQLConnectionAction connAction = (HQLConnectionAction) getActionDefinition();
            String[] classNames = null;
            createBasicConnection(connAction, classNames);
            if (connection != null) {
                IActionOutput outputConnection = connAction.getOutputConnectionParam();
                if (outputConnection != null) {
                    outputConnection.setValue(this);
                }
            }
        } else {
            returnValue = false;
            error(Messages.getInstance().getErrorString("HQLBaseComponent.ERROR_00011_INVALID_HQL_COMPONENT", // $NON-NLS-1$
            getActionName()));
        }
    } catch (Exception e) {
        returnValue = false;
        // $NON-NLS-1$
        error(Messages.getInstance().getErrorString("HQLBaseComponent.ERROR_00012_EXECUTE_FAILED", getActionName()), e);
    }
    return returnValue;
}
Also used : IPentahoConnection(org.pentaho.commons.connection.IPentahoConnection) HQLQueryAction(org.pentaho.actionsequence.dom.actions.HQLQueryAction) IActionOutput(org.pentaho.actionsequence.dom.IActionOutput) HQLConnectionAction(org.pentaho.actionsequence.dom.actions.HQLConnectionAction) IPreparedComponent(org.pentaho.platform.api.data.IPreparedComponent)

Example 3 with HQLQueryAction

use of org.pentaho.actionsequence.dom.actions.HQLQueryAction 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;
    }
}
Also used : IActionOutput(org.pentaho.actionsequence.dom.IActionOutput) HQLQueryAction(org.pentaho.actionsequence.dom.actions.HQLQueryAction)

Aggregations

HQLQueryAction (org.pentaho.actionsequence.dom.actions.HQLQueryAction)3 IActionOutput (org.pentaho.actionsequence.dom.IActionOutput)2 HQLConnectionAction (org.pentaho.actionsequence.dom.actions.HQLConnectionAction)2 IPentahoConnection (org.pentaho.commons.connection.IPentahoConnection)1 IPreparedComponent (org.pentaho.platform.api.data.IPreparedComponent)1