Jump to content

BIRT Developer Center
Download


DevShare Source for user-contributed BIRT articles, tips and code

Devshare Home >> Data Engine API to check Data Set values
- - - - -

Data Engine API to check Data Set values

Download Resource

Summary:

Example that uses the Data Engine API in beforeFactory Script to get values for a dataset.

Full Description:

Example that uses the Data Engine API in beforeFactory Script to get values for a dataset. The example has two tables and two datasets. In the beforeFactory the second table's data set is executed to see if it has any values. If it does the first table is dropped from the report. Note that the table must be named in the general properties.

Here is the script modified for a data set that has a parameter:
importPackage( Packages.org.eclipse.birt.report.model.api );
importPackage(Packages.java.lang);
importPackage(Packages.java.util);
importPackage(Packages.org.eclipse.birt.data.engine.api);
importPackage(Packages.org.eclipse.birt.report.model.api);
importPackage(Packages.org.eclipse.birt.data.engine.api.querydefn);
importPackage(Packages.org.eclipse.birt.data.engine.core);
importPackage(Packages.org.eclipse.birt.core.data);

var myconfig = reportContext.getReportRunnable().getReportEngine().getConfig();
var de = DataEngine.newDataEngine( myconfig, null );
var dsrc = reportContext.getDesignHandle().findDataSource("Data Source");
var dset = reportContext.getDesignHandle().findDataSet("Data Set2");
var odaDataSource = new OdaDataSourceDesign( "Test Data Source" );
odaDataSource.setExtensionID( "org.eclipse.birt.report.data.oda.jdbc" );
odaDataSource.addPublicProperty( "odaURL", dsrc.getProperty("odaURL").toString() );
odaDataSource.addPublicProperty( "odaDriverClass", dsrc.getProperty("odaDriverClass").toString());
odaDataSource.addPublicProperty( "odaUser", dsrc.getProperty("odaUser").toString() );
odaDataSource.addPublicProperty( "odaPassword", "" );  
 
var odaDataSet = new OdaDataSetDesign( "Test Data Set" );
odaDataSet.setDataSource( odaDataSource.getName( ) );
odaDataSet.setExtensionID( "org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
odaDataSet.setQueryText( dset.getQueryText() ); 
inputParamDefn = new ParameterDefinition( "param_1",DataType.INTEGER_TYPE );
inputParamDefn.setInputMode( true );
inputParamDefn.setPosition( 1 );
inputParamDefn.setDefaultInputValue( 10102 );
odaDataSet.addParameter( inputParamDefn );
if( params["order"].value != null ){
paramBinding = new InputParameterBinding( "param_1",new ScriptExpression( params["order"] ) );
}else{
paramBinding = new InputParameterBinding( "param_1",new ScriptExpression( 111111 ) );
}
de.defineDataSource( odaDataSource );
de.defineDataSet( odaDataSet );
  
queryDefinition = new QueryDefinition( );
queryDefinition.setDataSetName( odaDataSet.getName() );
queryDefinition.addInputParamBinding( paramBinding );
queryDefinition.setAutoBinding(true);
  
  
var pq = de.prepare( queryDefinition );
  
var qr = pq.execute( null );
rowcount=0;  
var ri = qr.getResultIterator( );  
while (  ri.next( ) )
{  
 rowcount++
}
ri.close( );
qr.close( );
de.shutdown( );
if( rowcount > 0 ){
 reportContext.getDesignHandle().findElement("Table1").drop();
}


0 Comments