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;
}
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;
}
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;
}
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();
}
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();
}
Aggregations