Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Urgent Help Required - Dynamically read the dataset result using BIRT APIs(Dynamically read the dataset result using BIRT APIs)
icon4.gif  Urgent Help Required - Dynamically read the dataset result using BIRT APIs [message #669392] Tue, 10 May 2011 07:39 Go to next message
shine_1611 is currently offline shine_1611Friend
Messages: 20
Registered: April 2011
Location: Mumbai
Junior Member
Hello Everyone,

I am trying to create a dataset using BIRT APIs and then i want to read through it so that I can get all the data from the Dataset.
Is this possible ? if yes then can anyone let me know now to do it?
I searched alot of forum and notice they try to create a table and directly set the dataset to that design Table. But I do not want to create a table I want these detail to bind with Dropdown.

here is my code to connect with Dataset, that is working but what next I should do?

dsHandle = designFactory.newOdaDataSet("TestDataSet","org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet " )
dsHandle.setDataSource( "DataSource" )
String qry = "Select Product,Name from Product"
dsHandle.setQueryText( qry ) designHandle.getDesignHandle().getModuleHandle().getDataSets ( ).add( dsHandle );

Thanks
Shivani
Re: Urgent Help Required - Dynamically read the dataset result using BIRT APIs [message #669487 is a reply to message #669392] Tue, 10 May 2011 13:56 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Shivani,

Can you give some more detail? You want to create a dataset and
datasource in code and then have it run and return you results?

Jason

On 5/10/2011 3:39 AM, forums-noreply@eclipse.org wrote:
> Hello Everyone,
>
> I am trying to create a dataset using BIRT APIs and then i
> want to read through it so that I can get all the data from
> the Dataset.
> Is this possible ? if yes then can anyone let me know now to
> do it?
> I searched alot of forum and notice they try to create a
> table and directly set the dataset to that design Table.
> But I do not want to create a table I want these detail to
> bind with Dropdown.
>
> here is my code to connect with Dataset, that is working but
> what next I should do?
>
> dsHandle =
> designFactory.newOdaDataSet("TestDataSet","org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet
>
> " )
> dsHandle.setDataSource( "DataSource" )
> String qry = "Select Product,Name from Product"
> dsHandle.setQueryText( qry )
> designHandle.getDesignHandle().getModuleHandle().getDataSets
> ( ).add( dsHandle );
>
> Thanks
> Shivani
Re: Urgent Help Required - Dynamically read the dataset result using BIRT APIs [message #669526 is a reply to message #669487] Tue, 10 May 2011 15:13 Go to previous messageGo to next message
shine_1611 is currently offline shine_1611Friend
Messages: 20
Registered: April 2011
Location: Mumbai
Junior Member
Hi Jason,

Yes want to get read data from DataSet.
I am able to connect to DATASource and Dataset.
now I want to read the resultset which will be returned in the Dataset and those results I want to bind to a control like dropdown.

So I want to know how to read the resultset. What will be the code for that.

here is the example

I have table Class

ID Name
1 Super
2 High
3 Low

so when I connect to the datasource and write query to fill the dataset "Select * from Class" after that
I want to read "Name" data.

I hope this is clear..

Thanks
Shivani

[Updated on: Tue, 10 May 2011 17:57]

Report message to a moderator

Re: Urgent Help Required - Dynamically read the dataset result using BIRT APIs [message #669570 is a reply to message #669526] Tue, 10 May 2011 18:20 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Generally the engine runs the query and produces the output. If you
want to do this yourself you could just connect to jdbc with standard
sql apis. BIRT does have an API called the data engine API which can be
used although this api is still subject to change. Here is an example.

Jason

package REAPI;


import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.data.engine.api.DataEngine;
import org.eclipse.birt.data.engine.api.DataEngineContext;
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.OdaDataSourceDesi gn;
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;
import org.eclipse.birt.report.model.api.IDesignEngineFactory;
import org.eclipse.birt.report.model.api.OdaDataSetHandle;
import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.SessionHandle;

import com.ibm.icu.util.ULocale;
/**
* 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_5_1/birt-runtime-2_5_1/ReportEngine");
IDesignEngine engine = null;
/*try{


Platform.startup( config );
IDesignEngineFactory factory = (IDesignEngineFactory) Platform
.createFactoryObject(
IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY );
engine = factory.createDesignEngine( config );

}catch( Exception ex){
ex.printStackTrace();
} */

/*
SessionHandle session = engine.newSessionHandle( ULocale.ENGLISH ) ;

// Create a new report design.

ReportDesignHandle design =
session.openDesign("c:/tmp/dataextract.rptdesign");

OdaDataSourceHandle sourceHandle = (OdaDataSourceHandle)
design.findDataSource( "Data Source" );
OdaDataSetHandle dsh = (OdaDataSetHandle)design.findDataSet("dataset");
*/


OdaDataSourceDesign odaDataSource;


DataEngine de=null;

//config.setRourcePath()

de = DataEngine.newDataEngine( config, null
);//DataEngineContext.newInstance(config,
DataEngineContext.DIRECT_PRESENTATION,
//null,
//null,
//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!
}
}

On 5/10/2011 11:13 AM, forums-noreply@eclipse.org wrote:
> Hi Jason,
>
> Yes I am able to have a DATASource and Dataset.
> not I want to read the resultset which we will get from Dataset.
> And those results I want to bind to a control like
> dropdown.
>
> So I want to know how to read the resultset. What will be
> the code for that.
>
> here is the example
>
> I have table Class
>
> ID Name
> 1 Super
> 2 High
> 3 Low
>
> so when I connect to the datasource and write query to fill
> the dataset "Select * from Class" after that I want to read "Name" data.
>
> I hope this is clear..
>
> Thanks
> Shivani
Re: Urgent Help Required - Dynamically read the dataset result using BIRT APIs [message #669680 is a reply to message #669570] Wed, 11 May 2011 07:18 Go to previous messageGo to next message
shine_1611 is currently offline shine_1611Friend
Messages: 20
Registered: April 2011
Location: Mumbai
Junior Member
Thank you so much Jason!!
I will give it a try I think this is what I was looking for.

Shivani
Re: Urgent Help Required - Dynamically read the dataset result using BIRT APIs [message #692456 is a reply to message #669680] Mon, 04 July 2011 13:20 Go to previous messageGo to next message
M P is currently offline M PFriend
Messages: 3
Registered: June 2011
Junior Member
HI Jason,

i am not getting records using this .

It returns 0 columns and 1 rows .. Sad

can you guess why ?

Re: Urgent Help Required - Dynamically read the dataset result using BIRT APIs [message #692938 is a reply to message #692456] Tue, 05 July 2011 13:57 Go to previous message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Are running the code exactly or have you altered it?
You might want to put the code in a try catch
try {
// js code
} catch (e) {
importPackage( Packages.java.io );
out = new PrintWriter( new FileWriter( "c:/temp/dataenginetest.txt",
true ) );
out.println( "Error " + e);
out.close();

}

Jason

On 7/4/2011 9:20 AM, M P wrote:
> HI Jason,
>
> i am not getting records using this .
>
> It returns 0 columns and 1 rows .. :(
> can you guess why ?
>
Previous Topic:Accessing Report Context from Chart Interactivity JavaScript
Next Topic:Generate Report from Xtext Editor model
Goto Forum:
  


Current Time: Fri Apr 26 02:34:17 GMT 2024

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

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

Back to the top