use of org.pentaho.platform.api.data.IPreparedComponent in project pentaho-platform by pentaho.
the class MDXBaseComponent method executeAction.
@Override
protected boolean executeAction() {
boolean value = false;
/*
* This is the query part. You would need a connection to execute the query. The connection will either come in as
* an INPUT (prepared_component) or will be specified right there.
*
* So check if a prepared component exists, if not create a new connection. If connection is not null, proceed to
* work on the query part.
*
* In the query section you can either execute the query right away or prepare it to be used later by a sub report.
*/
try {
if (getActionDefinition() instanceof MdxQueryAction) {
MdxQueryAction queryAction = (MdxQueryAction) getActionDefinition();
// instead of creating our own.
if (queryAction.getMdxConnection() != ActionInputConstant.NULL_INPUT) {
if (queryAction.getMdxConnection().getValue() != null) {
connectionOwner = false;
IPreparedComponent component = (IPreparedComponent) queryAction.getMdxConnection().getValue();
IPentahoConnection conn = component.shareConnection();
if (conn.getDatasourceType() == IPentahoConnection.MDX_DATASOURCE) {
connection = conn;
} else {
error(Messages.getInstance().getErrorString("IPreparedComponent.ERROR_0001_INVALID_CONNECTION_TYPE", // $NON-NLS-1$
getActionName()));
}
} else {
error(Messages.getInstance().getErrorString("IPreparedComponent.ERROR_0002_CONNECTION_NOT_AVAILABLE", // $NON-NLS-1$
getActionName()));
}
} else {
dispose();
connection = getDatasourceConnection();
}
if (connection != null) {
String query = queryAction.getQuery().getStringValue();
if (queryAction.getOutputPreparedStatement() != 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.
setOutputValue(IPreparedComponent.PREPARED_COMPONENT_NAME, this);
value = true;
} else {
value = runQuery(connection, query);
}
} else {
error(Messages.getInstance().getErrorString("IPreparedComponent.ERROR_0004_NO_CONNECTION_INFO", // $NON-NLS-1$
getActionName()));
}
} else if (getActionDefinition() instanceof MdxConnectionAction) {
dispose();
connection = getDatasourceConnection();
if (connection != null) {
setOutputValue(IPreparedComponent.PREPARED_COMPONENT_NAME, this);
value = true;
}
} else {
error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0004_VALIDATION_FAILED", // $NON-NLS-1$
getActionName()));
}
} catch (Exception e) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0006_EXECUTE_FAILED", getActionName()), e);
}
return value;
}
use of org.pentaho.platform.api.data.IPreparedComponent in project pentaho-platform by pentaho.
the class PentahoTableDataFactory method queryData.
/**
* Queries a datasource. The string 'query' defines the name of the query. The Parameterset given here may contain
* more data than actually needed.
* <p/>
* The dataset may change between two calls, do not assume anything!
*
* @param query
* the name of the table.
* @param parameters
* are ignored for this factory.
* @return the report data or null.
*/
public TableModel queryData(final String query, final DataRow parameters) {
TableModel model = tables.get(query);
if (model == null) {
final IPreparedComponent component = components.get(query);
if (component != null) {
final HashMap<String, Object> map = new HashMap<String, Object>();
if (parameters != null) {
String[] columnNames = parameters.getColumnNames();
for (String columnName : columnNames) {
map.put(columnName, parameters.get(columnName));
}
}
final IPentahoResultSet rs = component.executePrepared(map);
model = new PentahoTableModel(rs);
}
}
return model;
}
Aggregations