Search in sources :

Example 1 with HQLConnectionAction

use of org.pentaho.actionsequence.dom.actions.HQLConnectionAction 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 HQLConnectionAction

use of org.pentaho.actionsequence.dom.actions.HQLConnectionAction 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 HQLConnectionAction

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

the class HQLBaseComponent method getCatalog.

/*
   * Utility function to get the catalog info from hibernate config.
   */
private String getCatalog() {
    IActionResource hibernateConfigRes = ((HQLConnectionAction) getActionDefinition()).getHibernateConfigResource();
    String catalog = null;
    String resAddress = null;
    if (hibernateConfigRes != null) {
        String resName = this.applyInputsToFormat(hibernateConfigRes.getName());
        IActionSequenceResource resource = getResource(resName);
        resAddress = resource.getAddress();
        if (resAddress != null) {
            catalog = this.applyInputsToFormat(resAddress);
        }
    }
    return catalog;
}
Also used : IActionResource(org.pentaho.actionsequence.dom.IActionResource) HQLConnectionAction(org.pentaho.actionsequence.dom.actions.HQLConnectionAction) IActionSequenceResource(org.pentaho.platform.api.engine.IActionSequenceResource)

Aggregations

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