Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Reading resultset from ReportDesignHandle?
Reading resultset from ReportDesignHandle? [message #783829] Thu, 26 January 2012 14:46 Go to next message
js Missing name is currently offline js Missing nameFriend
Messages: 73
Registered: July 2009
Member
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 16:59 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

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 #783962 is a reply to message #783888] Thu, 26 January 2012 20:54 Go to previous messageGo to next message
js Missing name is currently offline js Missing nameFriend
Messages: 73
Registered: July 2009
Member
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?
Re: Reading resultset from ReportDesignHandle? [message #784507 is a reply to message #783962] Fri, 27 January 2012 16:20 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

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?
Re: Reading resultset from ReportDesignHandle? [message #1061838 is a reply to message #784507] Tue, 04 June 2013 10:20 Go to previous message
pramod khare is currently offline pramod khareFriend
Messages: 1
Registered: June 2013
Junior Member
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");

Previous Topic:WebViewer with Internet Explorer
Next Topic:Dynamic Image that changes with parameter
Goto Forum:
  


Current Time: Fri Apr 26 04:46:26 GMT 2024

Powered by FUDForum. Page generated in 0.02952 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top