Reading resultset from ReportDesignHandle? [message #783829] |
Thu, 26 January 2012 09:46  |
Eclipse User |
|
|
|
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 #783888 is a reply to message #783829] |
Thu, 26 January 2012 11:59   |
Eclipse User |
|
|
|
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 #1061838 is a reply to message #784507] |
Tue, 04 June 2013 06:20  |
Eclipse User |
|
|
|
Hi
I am currently trying to read resultset of a dataset using birt java api.
Here is it -
I want to read rptdesign and get the dataset and datasource values using them and dataengine api example I want to execute the dataset and get the result set for my next use.
I am able to get OdaDataSetHandle and OdaDataSourceHandle from rptdesign using following code.
//all report engine initialization code...
//IReportRunnable design = eng.openReportDesign("C:/temp/ttt.rptdesign");
List<OdaDataSetHandle> dataSets = design.getDesignHandle().getDesignHandle().getAllDataSets();
for(OdaDataSetHandle temp : dataSets){
System.out.println("DataSource - "+temp.getQueryText());
System.out.println(temp.getDataSourceName());
/*System.out.println(temp);
if(temp instanceof DataSetHandle){
System.out.println(((DataSetHandle)temp).getDataSourceName());
}*/
}
List<OdaDataSourceHandle> dataSources = design.getDesignHandle().getDesignHandle().getAllDataSources();
for(OdaDataSourceHandle temp : dataSources){
System.out.println("getDriverName - "+temp.getDriverName());
System.out.println(temp.getDisplayName());
/*System.out.println(temp);
if(temp instanceof DataSetHandle){
System.out.println(((DataSetHandle)temp).getDataSourceName());
}*/
}
But I am not able to convert them into OdaDataSetDesign and OdaDatSourceDesign which is required by the data-engine.
Here is the sample data-engine program
// Configure the Engine and start the Platform
DesignConfig config = new DesignConfig();
config.setBIRTHome(" ");
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");
|
|
|
Powered by
FUDForum. Page generated in 0.05312 seconds