Search in sources :

Example 1 with IPreparedComponent

use of org.pentaho.platform.api.data.IPreparedComponent 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 2 with IPreparedComponent

use of org.pentaho.platform.api.data.IPreparedComponent in project pentaho-platform by pentaho.

the class JFreeReportComponent method getInputParamDataFactory.

private PentahoTableDataFactory getInputParamDataFactory() {
    PentahoTableDataFactory factory = null;
    JFreeReportAction jFreeReportAction = (JFreeReportAction) getActionDefinition();
    ActionInput reportDataParam = (ActionInput) jFreeReportAction.getData();
    Object dataObject = reportDataParam != null ? reportDataParam.getValue() : null;
    if ((dataObject instanceof IPentahoResultSet) || (dataObject instanceof TableModel)) {
        factory = new PentahoTableDataFactory();
        if (dataObject instanceof IPentahoResultSet) {
            IPentahoResultSet resultset = (IPentahoResultSet) dataObject;
            if (resultset.isScrollable()) {
                resultset.beforeFirst();
            } else {
                // $NON-NLS-1$
                debug("ResultSet is not scrollable. Copying into memory");
                IPentahoResultSet memSet = resultset.memoryCopy();
                resultset.close();
                resultset = memSet;
            }
            factory.addTable(AbstractJFreeReportComponent.DATACOMPONENT_DEFAULTINPUT, new PentahoTableModel(resultset));
        } else if (dataObject instanceof TableModel) {
            factory.addTable(AbstractJFreeReportComponent.DATACOMPONENT_DEFAULTINPUT, (TableModel) dataObject);
        }
        IActionInput[] subreportQueries = jFreeReportAction.getSubreportQueryParams();
        for (IActionInput element : subreportQueries) {
            dataObject = element.getValue();
            if (dataObject instanceof IPreparedComponent) {
                factory.addPreparedComponent(element.getName(), (IPreparedComponent) dataObject);
            } else if (dataObject instanceof IPentahoResultSet) {
                final IPentahoResultSet resultset = (IPentahoResultSet) dataObject;
                resultset.beforeFirst();
                factory.addTable(element.getName(), new PentahoTableModel(resultset));
            } else if (dataObject instanceof TableModel) {
                factory.addTable(element.getName(), (TableModel) dataObject);
            }
        }
    }
    return factory;
}
Also used : JFreeReportAction(org.pentaho.actionsequence.dom.actions.JFreeReportAction) PentahoTableModel(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) ActionInput(org.pentaho.actionsequence.dom.ActionInput) IActionInput(org.pentaho.actionsequence.dom.IActionInput) IActionInput(org.pentaho.actionsequence.dom.IActionInput) PentahoTableDataFactory(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableDataFactory) TableModel(javax.swing.table.TableModel) PentahoTableModel(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel) IPreparedComponent(org.pentaho.platform.api.data.IPreparedComponent)

Example 3 with IPreparedComponent

use of org.pentaho.platform.api.data.IPreparedComponent in project pentaho-platform by pentaho.

the class JFreeReportDataComponent method getInputParamDataFactory.

@SuppressWarnings("unused")
private PentahoTableDataFactory getInputParamDataFactory() {
    PentahoTableDataFactory factory = null;
    if (isDefinedInput(AbstractJFreeReportComponent.DATACOMPONENT_DATAINPUT) || isDefinedInput(AbstractJFreeReportComponent.DATACOMPONENT_DEFAULTINPUT)) {
        factory = new PentahoTableDataFactory();
        final Iterator iter = getInputNames().iterator();
        while (iter.hasNext()) {
            String name = (String) iter.next();
            final Object dataObject = getInputValue(name);
            // if input name is "data", rename to "default" which is the name that jfreereport is expecting.
            if (name.equals(AbstractJFreeReportComponent.DATACOMPONENT_DATAINPUT)) {
                name = AbstractJFreeReportComponent.DATACOMPONENT_DEFAULTINPUT;
            }
            if (dataObject instanceof IPreparedComponent) {
                final IPreparedComponent comp = (IPreparedComponent) dataObject;
                factory.addPreparedComponent(name, comp);
            } else if (dataObject instanceof IPentahoResultSet) {
                final IPentahoResultSet resultset = (IPentahoResultSet) dataObject;
                resultset.beforeFirst();
                factory.addTable(name, new PentahoTableModel(resultset));
            } else if (dataObject instanceof TableModel) {
                final TableModel model = (TableModel) dataObject;
                factory.addTable(name, model);
            }
        }
    }
    return factory;
}
Also used : PentahoTableModel(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) PentahoTableDataFactory(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableDataFactory) Iterator(java.util.Iterator) IPreparedComponent(org.pentaho.platform.api.data.IPreparedComponent) PentahoTableModel(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel) TableModel(javax.swing.table.TableModel)

Example 4 with IPreparedComponent

use of org.pentaho.platform.api.data.IPreparedComponent in project pentaho-platform by pentaho.

the class IPreparedComponentIT method testIPreparedComponentSQLAvailable.

public void testIPreparedComponentSQLAvailable() {
    startTest();
    // $NON-NLS-1$
    info("Expected: Successful execution with object available");
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    IRuntimeContext context = run("/test/ipreparedcomponents/ipreparedcomponent_sql_available.xaction");
    assertEquals(Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS, // $NON-NLS-1$
    context.getStatus());
    // $NON-NLS-1$
    IActionParameter rtn = context.getOutputParameter("prepared_component");
    assertNotNull(rtn);
    IPreparedComponent preparedComponent = (IPreparedComponent) rtn.getValue();
    assertNotNull(preparedComponent);
    finishTest();
}
Also used : IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) IPreparedComponent(org.pentaho.platform.api.data.IPreparedComponent)

Example 5 with IPreparedComponent

use of org.pentaho.platform.api.data.IPreparedComponent in project pentaho-platform by pentaho.

the class IPreparedComponentIT method testIPreparedComponentXQueryShareConnection.

public void testIPreparedComponentXQueryShareConnection() {
    startTest();
    // $NON-NLS-1$
    info("Expected: Successful execution with object available");
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    IRuntimeContext context = run("/test/ipreparedcomponents/ipreparedcomponent_xquery_shareconn.xaction");
    assertEquals(Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS, // $NON-NLS-1$
    context.getStatus());
    // $NON-NLS-1$
    IActionParameter rtn1 = context.getOutputParameter("prepared_component");
    assertNotNull(rtn1);
    IPreparedComponent preparedComponent1 = (IPreparedComponent) rtn1.getValue();
    assertNotNull(preparedComponent1);
    IPentahoResultSet resultset1 = preparedComponent1.executePrepared(null);
    assertTrue(resultset1.getRowCount() >= 1);
    Object val1 = resultset1.getValueAt(0, 0);
    assertNotNull(val1);
    finishTest();
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) IPreparedComponent(org.pentaho.platform.api.data.IPreparedComponent)

Aggregations

IPreparedComponent (org.pentaho.platform.api.data.IPreparedComponent)12 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)5 IActionParameter (org.pentaho.platform.api.engine.IActionParameter)5 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)5 TableModel (javax.swing.table.TableModel)3 IActionInput (org.pentaho.actionsequence.dom.IActionInput)3 IPentahoConnection (org.pentaho.commons.connection.IPentahoConnection)3 HashMap (java.util.HashMap)2 IActionDefinition (org.pentaho.actionsequence.dom.IActionDefinition)2 IActionOutput (org.pentaho.actionsequence.dom.IActionOutput)2 PentahoTableDataFactory (org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableDataFactory)2 PentahoTableModel (org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel)2 Format (java.text.Format)1 Iterator (java.util.Iterator)1 ActionInput (org.pentaho.actionsequence.dom.ActionInput)1 AbstractRelationalDbAction (org.pentaho.actionsequence.dom.actions.AbstractRelationalDbAction)1 HQLConnectionAction (org.pentaho.actionsequence.dom.actions.HQLConnectionAction)1 HQLQueryAction (org.pentaho.actionsequence.dom.actions.HQLQueryAction)1 JFreeReportAction (org.pentaho.actionsequence.dom.actions.JFreeReportAction)1 MdxConnectionAction (org.pentaho.actionsequence.dom.actions.MdxConnectionAction)1