use of org.pentaho.platform.api.data.IPreparedComponent in project pentaho-platform by pentaho.
the class IPreparedComponentIT method testIPreparedComponentXQueryAvailable.
/*
* public void testIPreparedComponentSQLTempTables() { startTest();
* info("Expected: Successful execution with one row of data"); //$NON-NLS-1$ IRuntimeContext context = run("test",
* "ipreparedcomponents", "ipreparedcomponent_sql_temptables.xaction"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
* assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
* IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$
*
* IActionParameter rtn1 = context.getOutputParameter("a_result"); //$NON-NLS-1$ assertNotNull(rtn1); IPentahoResultSet
* resultset1 = (IPentahoResultSet) rtn1.getValue(); assertEquals(1, resultset1.getRowCount()); assertEquals(
* "Expected first row of 'a_result' to contain a 1 in the first column.", new Integer(1), resultset1.getValueAt(0,
* 0)); //$NON-NLS-1$
*
* IActionParameter rtn2 = context.getOutputParameter("no_results"); //$NON-NLS-1$ assertNotNull(rtn2);
* IPentahoResultSet resultset2 = (IPentahoResultSet) rtn2.getValue(); assertEquals(1, resultset2.getRowCount());
* assertEquals( "Expected first row of 'no_results' to contain a 0 in the first column.", new Integer(0),
* resultset2.getValueAt(0, 0)); //$NON-NLS-1$
*
* finishTest(); }
*/
/*
* public void testIPreparedComponentSQLPrepareLater() { startTest();
* info("Expected: Successful execution with object available"); //$NON-NLS-1$ IRuntimeContext context = run("test",
* "ipreparedcomponents", "ipreparedcomponent_sql_preparelater.xaction"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
* assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
* IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$
*
* IActionParameter rtn1 = context.getOutputParameter("prepared_component"); //$NON-NLS-1$ assertNotNull(rtn1);
* IPreparedComponent preparedComponent1 = (IPreparedComponent) rtn1.getValue(); assertNotNull(preparedComponent1);
* IPentahoResultSet resultset1 = preparedComponent1.executePrepared(null); assertEquals(1, resultset1.getRowCount());
* Number val1 = (Number) resultset1.getValueAt(0, 0);
*
* IActionParameter rtn2 = context.getOutputParameter("second_prepared_component"); //$NON-NLS-1$ assertNotNull(rtn2);
* IPreparedComponent preparedComponent2 = (IPreparedComponent) rtn2.getValue(); assertNotNull(preparedComponent2);
* HashMap map = new HashMap(); map.put("DEPARTMENT", "Sales"); //$NON-NLS-1$ //$NON-NLS-2$ map.put("REGION",
* "Eastern"); //$NON-NLS-1$ //$NON-NLS-2$ IPentahoResultSet resultset2 = preparedComponent2.executePrepared(map);
* assertEquals(1, resultset2.getRowCount()); Number val2 = (Number) resultset2.getValueAt(0, 0);
*
* assertEquals("Values from the first and second query should be equal", val1, val2); //$NON-NLS-1$
*
* finishTest(); }
*/
/*
* public void testIPreparedComponentMDXAvailable() { startTest();
* info("Expected: Successful execution with object available"); //$NON-NLS-1$ IRuntimeContext context = run("test",
* "ipreparedcomponents", "ipreparedcomponent_mdx_available.xaction"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
* assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
* IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$
*
* IActionParameter rtn = context.getOutputParameter("prepared_component"); //$NON-NLS-1$ assertNotNull(rtn);
* IPreparedComponent preparedComponent = (IPreparedComponent) rtn.getValue();
*
* assertNotNull(preparedComponent);
*
* finishTest(); }
*/
/*
* public void testIPreparedComponentMDXShareConnection() { startTest();
* info("Expected: Successful execution with object available"); //$NON-NLS-1$ IRuntimeContext context = run("test",
* "ipreparedcomponents", "ipreparedcomponent_mdx_shareconn.xaction"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
* assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
* IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$
*
* IActionParameter rtn = context.getOutputParameter("prepared_component"); //$NON-NLS-1$ assertNotNull(rtn);
* IPreparedComponent preparedComponent = (IPreparedComponent) rtn.getValue();
*
* assertNotNull(preparedComponent);
*
* IPentahoResultSet resultset = preparedComponent.executePrepared(null); assertNotNull(resultset);
* assertTrue(resultset.getRowCount() >= 1); Object val1 = resultset.getValueAt(0, 0); assertNotNull(val1);
*
* finishTest(); }
*/
/*
* public void testIPreparedComponentMDXPrepareLater() { startTest();
* info("Expected: Successful execution with object available"); //$NON-NLS-1$ IRuntimeContext context = run("test",
* "ipreparedcomponents", "ipreparedcomponent_mdx_preparelater.xaction"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
* assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
* IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$
*
* IActionParameter rtn1 = context.getOutputParameter("prepared_component"); //$NON-NLS-1$ assertNotNull(rtn1);
* IPreparedComponent preparedComponent1 = (IPreparedComponent) rtn1.getValue(); assertNotNull(preparedComponent1);
* IPentahoResultSet resultset1 = preparedComponent1.executePrepared(null); assertNotNull(resultset1);
* assertTrue(resultset1.getRowCount() >= 1); Object val1 = resultset1.getValueAt(0, 0);
*
* IActionParameter rtn2 = context.getOutputParameter("second_prepared_component"); //$NON-NLS-1$ assertNotNull(rtn2);
* IPreparedComponent preparedComponent2 = (IPreparedComponent) rtn2.getValue(); assertNotNull(preparedComponent2);
* HashMap map = new HashMap(); map.put("productline", "Classic Cars"); //$NON-NLS-1$ //$NON-NLS-2$ IPentahoResultSet
* resultset2 = preparedComponent2.executePrepared(map); assertTrue(resultset2.getRowCount() >= 1);
* assertEquals(resultset1.getRowCount(), resultset2.getRowCount());
*
* Object val2 = resultset2.getValueAt(0, 0);
*
* assertEquals("Values from the first and second query should be equal", val1, val2); //$NON-NLS-1$
*
* finishTest(); }
*/
public void testIPreparedComponentXQueryAvailable() {
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_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();
}
use of org.pentaho.platform.api.data.IPreparedComponent 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;
}
use of org.pentaho.platform.api.data.IPreparedComponent in project pentaho-platform by pentaho.
the class XQueryBaseComponent method executeAction.
@Override
protected boolean executeAction() {
boolean result = false;
IActionDefinition actionDefinition = getActionDefinition();
// int queryTimeout = -1;
if (actionDefinition instanceof XQueryAction) {
XQueryAction xQueryAction = (XQueryAction) actionDefinition;
// Not implemented yet
// IActionInput queryTimeoutInput = xQueryAction.getQueryTimeout();
IActionInput maxRowsInput = xQueryAction.getMaxRows();
if (maxRowsInput != ActionInputConstant.NULL_INPUT) {
this.setMaxRows(maxRowsInput.getIntValue());
}
IPreparedComponent sharedConnection = (IPreparedComponent) xQueryAction.getSharedConnection().getValue();
if (sharedConnection != null) {
connectionOwner = false;
connection = sharedConnection.shareConnection();
} else {
connection = getConnection();
}
if (connection == null) {
error(Messages.getInstance().getErrorString("IPreparedComponent.ERROR_0002_CONNECTION_NOT_AVAILABLE", // $NON-NLS-1$
getActionName()));
} else if (connection.getDatasourceType() != IPentahoConnection.XML_DATASOURCE) {
error(Messages.getInstance().getErrorString("IPreparedComponent.ERROR_0001_INVALID_CONNECTION_TYPE", // $NON-NLS-1$
getActionName()));
} else {
result = runQuery(connection, xQueryAction.getQuery().getStringValue());
}
} else if (actionDefinition instanceof XQueryConnectionAction) {
XQueryConnectionAction xQueryConnectionAction = (XQueryConnectionAction) getActionDefinition();
connection = getConnection();
if (connection == null) {
error(Messages.getInstance().getErrorString("IPreparedComponent.ERROR_0002_CONNECTION_NOT_AVAILABLE", // $NON-NLS-1$
getActionName()));
} else if (connection.getDatasourceType() != IPentahoConnection.XML_DATASOURCE) {
error(Messages.getInstance().getErrorString("IPreparedComponent.ERROR_0001_INVALID_CONNECTION_TYPE", // $NON-NLS-1$
getActionName()));
} else {
xQueryConnectionAction.getOutputConnection().setValue(this);
result = true;
}
}
return result;
}
use of org.pentaho.platform.api.data.IPreparedComponent in project pentaho-platform by pentaho.
the class IPreparedComponentIT method testIPreparedComponentXQueryAvailableErrorNoDocument.
public void testIPreparedComponentXQueryAvailableErrorNoDocument() {
startTest();
IRuntimeContext context = // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
run("/test/ipreparedcomponents/ipreparedcomponent_xquery_available_error_nodocument.xaction");
assertEquals(Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_FAILURE, // $NON-NLS-1$
context.getStatus());
// $NON-NLS-1$
IActionParameter rtn = context.getOutputParameter("prepared_component");
assertNotNull(rtn);
IPreparedComponent preparedComponent = (IPreparedComponent) rtn.getValue();
assertNull(preparedComponent);
finishTest();
}
use of org.pentaho.platform.api.data.IPreparedComponent in project pentaho-platform by pentaho.
the class IPreparedComponentIT method testIPreparedComponentXQueryPrepareLater.
public void testIPreparedComponentXQueryPrepareLater() {
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_preparelater.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);
// $NON-NLS-1$
IActionParameter rtn2 = context.getOutputParameter("second_prepared_component");
assertNotNull(rtn2);
IPreparedComponent preparedComponent2 = (IPreparedComponent) rtn2.getValue();
assertNotNull(preparedComponent2);
HashMap map = new HashMap();
// $NON-NLS-1$ //$NON-NLS-2$
map.put("POSITIONTITLE", "Engineer");
IPentahoResultSet resultset2 = preparedComponent2.executePrepared(map);
assertTrue(resultset2.getRowCount() >= 1);
assertEquals(resultset1.getRowCount(), resultset2.getRowCount());
Object val2 = resultset2.getValueAt(0, 0);
// $NON-NLS-1$
assertEquals("Values from the first and second query should be equal", val1, val2);
finishTest();
}
Aggregations