|
Re: Reading resultset from ReportDesignHandle? [message #783888 is a reply to message #783829] |
Thu, 26 January 2012 16:59 |
|
You could always use the data engine to test a query:
package REAPI;
import org.eclipse.birt.data.engine.api.DataEngine;
import org.eclipse.birt.data.engine.api.IPreparedQuery;
import org.eclipse.birt.data.engine.api.IQueryResults;
import org.eclipse.birt.data.engine.api.IResultIterator;
import org.eclipse.birt.data.engine.api.IResultMetaData;
import org.eclipse.birt.data.engine.api.querydefn.OdaDataSetDesign;
import org.eclipse.birt.data.engine.api.querydefn.OdaDataSourceDesign;
import org.eclipse.birt.data.engine.api.querydefn.QueryDefinition;
import org.eclipse.birt.report.model.api.DesignConfig;
import org.eclipse.birt.report.model.api.IDesignEngine;
/**
* Simple BIRT Design Engine API (DEAPI) demo.
*/
public class DataEngineExample {
public static void main( String[] args )
{
try
{
extract( );
}
catch ( Exception e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// This function shows how to build a very simple BIRT report with a
// minimal set of content: a simple grid with an image and a label.
static void extract( ) throws Exception
{
//Configure the Engine and start the Platform
DesignConfig config = new DesignConfig( );
config.setBIRTHome(
"C:/birt/birt-runtime-2_6_1/birt-runtime-2_6_1/ReportEngine");
IDesignEngine engine = null;
OdaDataSourceDesign odaDataSource;
DataEngine de=null;
de = DataEngine.newDataEngine( config, null );
odaDataSource = new OdaDataSourceDesign( "Test Data Source" );
odaDataSource.setExtensionID( "org.eclipse.birt.report.data.oda.jdbc" );
odaDataSource.addPublicProperty( "odaURL",
"jdbc:classicmodels:sampledb" );
//sourceHandle.getProperty("odaURL").toString() );
odaDataSource.addPublicProperty( "odaDriverClass",
"org.eclipse.birt.report.data.oda.sampledb.Driver");//sourceHandle.getProperty("odaDriverClass").toString());
odaDataSource.addPublicProperty( "odaUser", "ClassicModels"
);//sourceHandle.getProperty("odaUser").toString() );
odaDataSource.addPublicProperty( "odaPassword", "" );
OdaDataSetDesign odaDataSet = new OdaDataSetDesign( "Test Data Set" );
odaDataSet.setDataSource( odaDataSource.getName( ) );
odaDataSet.setExtensionID(
"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
odaDataSet.setQueryText( "Select ORDERNUMBER from orders"
);//dsh.getQueryText() );
de.defineDataSource( odaDataSource );
de.defineDataSet( odaDataSet );
QueryDefinition queryDefinition = new QueryDefinition( );
queryDefinition.setDataSetName( odaDataSet.getName() );
queryDefinition.setAutoBinding(true);
IPreparedQuery pq = de.prepare( queryDefinition );
IQueryResults qr = pq.execute( null );
IResultIterator ri = qr.getResultIterator( );
int cc = ri.getResultMetaData().getColumnCount();
IResultMetaData rsmd = ri.getResultMetaData();
while ( ri.next( ) )
{
for ( int i = 0; i < cc; i++ )
System.out.print(ri.getValue(rsmd.getColumnName(i+1)) + " ");
System.out.println("");
}
ri.close( );
qr.close( );
de.shutdown( );
System.out.println("Finished");
// We're done!
}
}
Jason
On 1/26/2012 9:46 AM, js wrote:
> In my application I dynamically create a ReportDesignHandle with a xml
> datasource. I also create a OdaDataSetHandle and set a query string
> (that matches the content of the xml file):
>
>
> public DataSetHandle createDataSet(String dataSetName, String
> dataSourceName, String queryText) {
> OdaDataSetHandle dataSetHandle =
> elementFactory.newOdaDataSet(dataSetName,
> "org.eclipse.birt.report.data.oda.xml.dataSet");
> try {
> dataSetHandle.setDataSource(dataSourceName);
> dataSetHandle.setName(dataSetName);
> dataSetHandle.setQueryText(queryText);
> } catch (SemanticException e) {
> logger.error("Data source name: " + dataSourceName + " could not be
> set!", e);
> }
> return dataSetHandle;
> }
>
>
> After I have done this I would like to compute a Resultset to see that
> my query text makes sense and evaluates to working values. Is this
> possible?
>
> I have tried to create a RunAndRenderTask and a IRunTask using the
> ReportDesignHandle as input and inspect the corresponding IReportContext
> and IReportDocument (followed by an IDataExtractionTask) object. But I
> cannot see any info about my columnMapping and rowMappings from the
> queryText.
>
|
|
|
|
Re: Reading resultset from ReportDesignHandle? [message #784507 is a reply to message #783962] |
Fri, 27 January 2012 16:20 |
|
I am a bit confused on what you are trying to do. If you create a data
set and then a table you can create the column bindings that are
attached to the table using code. Is there a reason you want to add the
cached meta data?
Jason
On 1/26/2012 3:54 PM, js Mising name wrote:
> Thanks I will give et a try!
>
> If I manually add eg. a table to the report and drag a colum mapping
> from the dataset into the details row and save the report its possible
> to read/print the column mappings:
>
>
> OdaDataSetHandle de = (OdaDataSetHandle) ds;
> CachedMetaDataHandle cachedMeta = de.getCachedMetaDataHandle();
> List<?> cols = (List<?>) cachedMeta.getResultSet().getValue();
> for (int i = 0; i < cols.size(); i++) {
> ResultSetColumn rsc = (ResultSetColumn) cols.get(i);
> String name = rsc.getColumnName();
> System.out.println(name);
> }
>
>
> Is it possible to trigger/populate the cachedMetaData automatically from
> code after setting the queryText?
|
|
|
|
Powered by
FUDForum. Page generated in 0.03892 seconds