Search in sources :

Example 6 with IActionDefinition

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

the class UnresolvedParameterExceptionTest method testUnresolvedParameterExceptionStringStringStringStringIActionDefinition.

@Test
public void testUnresolvedParameterExceptionStringStringStringStringIActionDefinition() {
    IActionDefinition actionDef = Mockito.mock(IActionDefinition.class);
    try {
        Constructor<UnresolvedParameterException> constructor = UnresolvedParameterException.class.getDeclaredConstructor(String.class, Throwable.class, String.class, String.class, String.class, IActionDefinition.class);
        constructor.setAccessible(true);
        constructor.newInstance("msg", new Exception("cause"), "sessionName", "instanceId", "actionSequenceName", actionDef);
    } catch (Exception e) {
        fail(UnresolvedParameterException.class.getSimpleName() + " Does not have a constructor with String, Throwable, String, String, String, IActionDefinition ");
    }
}
Also used : IActionDefinition(org.pentaho.actionsequence.dom.IActionDefinition) Test(org.junit.Test)

Example 7 with IActionDefinition

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

the class SQLBaseComponent method validateAction.

/**
 * validates the action. checks to verify inputs are available to execute
 *
 * - verify query is available - verify connection is available, via jndi, connection string, or prepared component -
 * verify output is specified
 */
@Override
public boolean validateAction() {
    boolean result = true;
    IActionDefinition actionDefinition = getActionDefinition();
    String actionName = getActionName();
    if (actionDefinition instanceof AbstractRelationalDbAction) {
        AbstractRelationalDbAction relationalDbAction = (AbstractRelationalDbAction) actionDefinition;
        IActionInput query = relationalDbAction.getQuery();
        IActionInput dbUrl = relationalDbAction.getDbUrl();
        IActionInput jndi = relationalDbAction.getJndi();
        IActionInput sharedConnection = relationalDbAction.getSharedConnection();
        if (query == ActionInputConstant.NULL_INPUT) {
            // $NON-NLS-1$
            error(Messages.getInstance().getErrorString("SQLBaseComponent.ERROR_0001_QUERY_NOT_SPECIFIED", actionName));
            result = false;
        }
        if ((jndi == ActionInputConstant.NULL_INPUT) && (dbUrl == ActionInputConstant.NULL_INPUT) && (sharedConnection == ActionInputConstant.NULL_INPUT)) {
            error(Messages.getInstance().getErrorString("SQLBaseComponent.ERROR_0002_CONNECTION_NOT_SPECIFIED", // $NON-NLS-1$
            actionName));
            result = false;
        }
    } else if (actionDefinition instanceof SqlConnectionAction) {
        SqlConnectionAction sqlConnectionAction = (SqlConnectionAction) actionDefinition;
        IActionInput dbUrl = sqlConnectionAction.getDbUrl();
        IActionInput jndi = sqlConnectionAction.getJndi();
        if ((jndi == ActionInputConstant.NULL_INPUT) && (dbUrl == ActionInputConstant.NULL_INPUT)) {
            error(Messages.getInstance().getErrorString("SQLBaseComponent.ERROR_0002_CONNECTION_NOT_SPECIFIED", // $NON-NLS-1$
            actionName));
            result = false;
        }
    } else {
        error(Messages.getInstance().getErrorString("ComponentBase.ERROR_0001_UNKNOWN_ACTION_TYPE", // $NON-NLS-1$
        actionDefinition.getElement().asXML()));
        result = false;
    }
    return result;
}
Also used : IActionInput(org.pentaho.actionsequence.dom.IActionInput) IActionDefinition(org.pentaho.actionsequence.dom.IActionDefinition) SqlConnectionAction(org.pentaho.actionsequence.dom.actions.SqlConnectionAction) AbstractRelationalDbAction(org.pentaho.actionsequence.dom.actions.AbstractRelationalDbAction)

Example 8 with IActionDefinition

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

the class SQLBaseComponent method executeAction.

/**
 * determines state of component, and executes accordingly.
 *
 * various inputs that impact the state include:
 *
 * live - returns a live result set vs. an in memory copy transform - transform a result set based on additional
 * inputs prepared_component - if available, use existing connection from prepared component max_rows - sets the
 * number of rows that should be returned in result sets
 *
 * The specified output also impacts the state of the execution. If prepared_component is defined as an output, setup
 * the query but delay execution.
 */
@Override
protected boolean executeAction() {
    IActionDefinition actionDefinition = getActionDefinition();
    try {
        if (actionDefinition instanceof AbstractRelationalDbAction) {
            AbstractRelationalDbAction relationalDbAction = (AbstractRelationalDbAction) actionDefinition;
            // Added by Arijit Chatterjee
            IActionInput queryTimeoutInput = relationalDbAction.getQueryTimeout();
            IActionInput maxRowsInput = relationalDbAction.getMaxRows();
            IActionInput readOnlyInput = relationalDbAction.getReadOnly();
            String baseQuery = getQuery();
            if (baseQuery == null) {
                error(Messages.getInstance().getErrorString("SQLBaseComponent.ERROR_0001_QUERY_NOT_SPECIFIED", // $NON-NLS-1$
                actionDefinition.getDescription()));
                return false;
            }
            IPreparedComponent sharedConnection = (IPreparedComponent) relationalDbAction.getSharedConnection().getValue();
            if (readOnlyInput != ActionInputConstant.NULL_INPUT) {
                this.setReadOnly(readOnlyInput.getBooleanValue());
            }
            if (sharedConnection != null) {
                connectionOwner = false;
                IPentahoConnection conn = sharedConnection.shareConnection();
                if (conn == null) {
                    error(Messages.getInstance().getErrorString("IPreparedComponent.ERROR_0002_CONNECTION_NOT_AVAILABLE", // $NON-NLS-1$
                    getActionName()));
                    return false;
                } else if (conn.getDatasourceType() == IPentahoConnection.SQL_DATASOURCE) {
                    connection = conn;
                } else {
                    error(Messages.getInstance().getErrorString("IPreparedComponent.ERROR_0001_INVALID_CONNECTION_TYPE", // $NON-NLS-1$
                    getActionName()));
                    return false;
                }
            } else {
                dispose();
                connection = getDatasourceConnection();
            }
            if (connection == null) {
                return false;
            }
            // query and set this component as the output. This query will be run later from a subreport.
            if (relationalDbAction.getOutputPreparedStatement() != null) {
                prepareQuery(baseQuery);
                IActionOutput actionOutput = relationalDbAction.getOutputPreparedStatement();
                if (actionOutput != null) {
                    actionOutput.setValue(this);
                }
                return true;
            }
            // int maxRows = relationalDbAction.getMaxRows().getIntValue(-1);
            if (maxRowsInput != ActionInputConstant.NULL_INPUT) {
                this.setMaxRows(maxRowsInput.getIntValue());
            }
            // Added by Arijit Chatterjee.Sets the value of timeout. Default is -1, if parameter not found.
            if (queryTimeoutInput != ActionInputConstant.NULL_INPUT) {
                this.setQueryTimeout(queryTimeoutInput.getIntValue());
            }
            if (relationalDbAction.getPerformTransform().getBooleanValue(false)) {
                // The side effect of
                runQuery(baseQuery, false);
                // transform rSet here
                rSet = PentahoDataTransmuter.crossTab(rSet, relationalDbAction.getTransformPivotColumn().getIntValue(-1) - 1, relationalDbAction.getTransformMeasuresColumn().getIntValue(-1) - 1, relationalDbAction.getTransformSortColumn().getIntValue(0) - 1, (Format) relationalDbAction.getTransformPivotDataFormat().getValue(), (Format) relationalDbAction.getTransformSortDataFormat().getValue(), relationalDbAction.getTransformOrderOutputColumns().getBooleanValue(false));
                IActionOutput actionOutput = relationalDbAction.getOutputResultSet();
                if (actionOutput != null) {
                    actionOutput.setValue(rSet);
                }
                return true;
            } else {
                return runQuery(baseQuery, relationalDbAction.getLive().getBooleanValue(false));
            }
        } else if (actionDefinition instanceof SqlConnectionAction) {
            SqlConnectionAction sqlConnectionAction = (SqlConnectionAction) actionDefinition;
            dispose();
            connection = getDatasourceConnection();
            if (connection == null) {
                return false;
            } else {
                IActionOutput actionOutput = sqlConnectionAction.getOutputConnection();
                if (actionOutput != null) {
                    actionOutput.setValue(this);
                    return true;
                } else {
                    return false;
                }
            }
        }
    } catch (Exception e) {
        // $NON-NLS-1$
        error(Messages.getInstance().getErrorString("SQLBaseComponent.ERROR_0006_EXECUTE_FAILED", getActionName()), e);
    }
    return false;
}
Also used : IPentahoConnection(org.pentaho.commons.connection.IPentahoConnection) Format(java.text.Format) IActionInput(org.pentaho.actionsequence.dom.IActionInput) IActionDefinition(org.pentaho.actionsequence.dom.IActionDefinition) IActionOutput(org.pentaho.actionsequence.dom.IActionOutput) SqlConnectionAction(org.pentaho.actionsequence.dom.actions.SqlConnectionAction) IPreparedComponent(org.pentaho.platform.api.data.IPreparedComponent) AbstractRelationalDbAction(org.pentaho.actionsequence.dom.actions.AbstractRelationalDbAction)

Example 9 with IActionDefinition

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

the class SQLBaseComponent method executePrepared.

/**
 * executes a prepared method that returns a result set executePrepared looks up any "PREPARELATER" params in the
 * preparedParams map.
 *
 * @param preparedParams
 *          a map of possible parameters.
 * @return result set
 */
public IPentahoResultSet executePrepared(final Map preparedParams) {
    try {
        if (connection == null) {
            // $NON-NLS-1$
            error(Messages.getInstance().getErrorString("SQLBaseComponent.ERROR_0007_NO_CONNECTION"));
            return null;
        }
        if (!connection.initialized()) {
            // $NON-NLS-1$
            error(Messages.getInstance().getErrorString("SQLBaseComponent.ERROR_0007_NO_CONNECTION"));
            return null;
        }
        if (preparedQuery == null) {
            error(Messages.getInstance().getErrorString("SQLBaseComponent.ERROR_0001_QUERY_NOT_SPECIFIED", // $NON-NLS-1$
            getActionName()));
            return null;
        }
        // copy the preparedParams list, so it can be used multiple times.
        ArrayList copyOfPreparedParameters = new ArrayList(preparedParameters);
        // parse preparedQuery, replacing any {PREPARELATER:NAME} with appropriate values
        String query = TemplateUtil.applyTemplate(preparedQuery, getRuntimeContext(), new ParamResolver(copyOfPreparedParameters, preparedParams));
        if (ComponentBase.debug) {
            dumpQuery(query);
        }
        // evaluate
        IPentahoResultSet resultSet = null;
        if (preparedParameters.size() > 0) {
            resultSet = connection.prepareAndExecuteQuery(query, copyOfPreparedParameters);
        } else {
            resultSet = connection.executeQuery(query);
        }
        if (connection instanceof SQLConnection) {
            if (((SQLConnection) connection).isForcedForwardOnly()) {
                // $NON-NLS-1$
                warn(Messages.getInstance().getString("SQLBaseComponent.WARN_FALL_BACK_TO_NONSCROLLABLE"));
            }
        }
        boolean live = true;
        IActionDefinition actionDefinition = getActionDefinition();
        if (actionDefinition instanceof AbstractRelationalDbAction) {
            AbstractRelationalDbAction relationalDbAction = (AbstractRelationalDbAction) actionDefinition;
            live = relationalDbAction.getLive().getBooleanValue(false);
        }
        IPentahoResultSet rs = resultSet;
        // BISERVER-5915, BISERVER-5875 - if the live setting is false, return an in memory resultset.
        if (!live) {
            rs = resultSet.memoryCopy();
        }
        rSet = rs;
        return rs;
    } catch (Exception e) {
        // $NON-NLS-1$
        error(Messages.getInstance().getErrorString("SQLBaseComponent.ERROR_0006_EXECUTE_FAILED", getActionName()), e);
    }
    return null;
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) IActionDefinition(org.pentaho.actionsequence.dom.IActionDefinition) SQLConnection(org.pentaho.platform.plugin.services.connections.sql.SQLConnection) ArrayList(java.util.ArrayList) AbstractRelationalDbAction(org.pentaho.actionsequence.dom.actions.AbstractRelationalDbAction)

Example 10 with IActionDefinition

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

the class SQLDdlComponent method getActionDefinition.

@Override
public IActionDefinition getActionDefinition() {
    IActionDefinition generic = super.getActionDefinition();
    ActionSequenceParameterMgr paramMgr = new ActionSequenceParameterMgr(getRuntimeContext(), getSession());
    SqlDataAction action = new SqlDataAction(generic.getElement(), paramMgr);
    return action;
}
Also used : IActionDefinition(org.pentaho.actionsequence.dom.IActionDefinition) SqlDataAction(org.pentaho.actionsequence.dom.actions.SqlDataAction) ActionSequenceParameterMgr(org.pentaho.platform.engine.services.actionsequence.ActionSequenceParameterMgr)

Aggregations

IActionDefinition (org.pentaho.actionsequence.dom.IActionDefinition)19 Test (org.junit.Test)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 List (java.util.List)3 IActionInput (org.pentaho.actionsequence.dom.IActionInput)3 AbstractRelationalDbAction (org.pentaho.actionsequence.dom.actions.AbstractRelationalDbAction)3 IActionSequence (org.pentaho.platform.api.engine.IActionSequence)3 IMimeTypeListener (org.pentaho.platform.api.engine.IMimeTypeListener)3 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)3 ActionSequenceJCRHelper (org.pentaho.platform.engine.services.ActionSequenceJCRHelper)3 ArrayList (java.util.ArrayList)2 IActionIfStatement (org.pentaho.actionsequence.dom.IActionIfStatement)2 IActionLoop (org.pentaho.actionsequence.dom.IActionLoop)2 CopyParamAction (org.pentaho.actionsequence.dom.actions.CopyParamAction)2 FormatMsgAction (org.pentaho.actionsequence.dom.actions.FormatMsgAction)2 PrintMapValsAction (org.pentaho.actionsequence.dom.actions.PrintMapValsAction)2 PrintParamAction (org.pentaho.actionsequence.dom.actions.PrintParamAction)2 SqlConnectionAction (org.pentaho.actionsequence.dom.actions.SqlConnectionAction)2 XQueryAction (org.pentaho.actionsequence.dom.actions.XQueryAction)2 XQueryConnectionAction (org.pentaho.actionsequence.dom.actions.XQueryConnectionAction)2