Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Add parameters to already existing DataSetHandle (using the birt API)
Add parameters to already existing DataSetHandle (using the birt API) [message #553095] Mon, 16 August 2010 13:20 Go to next message
Eclipse User
Originally posted by: vm.vm.com

I am trying to read an existing .rptdesign file and add some parameter to
one of the dataSets. Currently I do it through a manual modification of the
queryText property:


public class Test{


private ReportDesignHandle rpt;
public Test(ReportDesignHandle rpt) {
this.rpt = rpt;
}

public void update(){
List<DataSetHandle> currentDataSets = rpt.getAllDataSets();
for (DataSetHandle ds : currentDataSets) {
String currentQuery = (String) ds.getProperty("queryText");
System.out.println(currentQuery);
if (ds.getName().equals("ds0")) {
String query =
" table0#-TNAME-#table0#:#[/root/data]#:#{data0;STRING;/data[@ id=\ "var0\"]/@value},"
+ "{data1;STRING;/data[@id=\"var1\"]/@value},"
+ "{data2;STRING;/data[@id=\"var2\"]/@value},"
+ "{data3;STRING;/data[@id=\"var3\"]/@value}"; // this is a new
parameter!
try {
((OdaDataSetHandle) ds).setQueryText(query);
} catch (SemanticException e) {
e.printStackTrace();
}
}
}

}


but to make this work I need to manually refresh the dataSet afterwards in
the Data Explorer to make the parameter appear.

Is there a better way to add parameter to an already existing dataSet or a
way to trigger the refresh call in the code to make the parameter visible
when the user opens the .rptdesign file?
Re: Add parameters to already existing DataSetHandle (using the birt API) [message #553184 is a reply to message #553095] Mon, 16 August 2010 15:31 Go to previous message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

Try code similar to:

void buildDataSet2( ) throws SemanticException
{

OdaDataSetHandle dsHandle = designFactory.newOdaDataSet( "ds2",
"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
dsHandle.setDataSource( "Data Source" );
String qry = "Select * from orderdetails where ordernumber = ?";

dsHandle.setQueryText( qry );
designHandle.getDataSets( ).add( dsHandle );
OdaDataSetParameter parameter =
StructureFactory.createOdaDataSetParameter();
parameter.setName( "param1" );
parameter.setPosition(1);
parameter.setDataType("integer");
parameter.setAllowNull(true);
parameter.setDefaultValue("10105");
parameter.setIsOptional(false);
parameter.setIsOutput(false);
parameter.setIsInput(true);

PropertyHandle parameterHandle = dsHandle.getPropertyHandle(
DataSetHandle.PARAMETERS_PROP );
parameterHandle.addItem( parameter );


}

Jason

On 8/16/2010 9:20 AM, vm wrote:
> I am trying to read an existing .rptdesign file and add some parameter
> to one of the dataSets. Currently I do it through a manual modification
> of the queryText property:
>
>
> public class Test{
>
>
> private ReportDesignHandle rpt;
> public Test(ReportDesignHandle rpt) {
> this.rpt = rpt;
> }
>
> public void update(){
> List<DataSetHandle> currentDataSets = rpt.getAllDataSets();
> for (DataSetHandle ds : currentDataSets) {
> String currentQuery = (String) ds.getProperty("queryText");
> System.out.println(currentQuery);
> if (ds.getName().equals("ds0")) {
> String query =
> " table0#-TNAME-#table0#:#[/root/data]#:#{data0;STRING;/data[@ id=\ "var0\"]/@value},"
>
> + "{data1;STRING;/data[@id=\"var1\"]/@value},"
> + "{data2;STRING;/data[@id=\"var2\"]/@value},"
> + "{data3;STRING;/data[@id=\"var3\"]/@value}"; // this is a new parameter!
> try {
> ((OdaDataSetHandle) ds).setQueryText(query);
> } catch (SemanticException e) {
> e.printStackTrace();
> }
> }
> }
>
> }
>
>
> but to make this work I need to manually refresh the dataSet afterwards
> in the Data Explorer to make the parameter appear.
>
> Is there a better way to add parameter to an already existing dataSet or
> a way to trigger the refresh call in the code to make the parameter
> visible when the user opens the .rptdesign file?
>
>
>
Previous Topic:[2.5.2]Display thin Table on wide page
Next Topic:BirtViewer and the Jazz Data Source
Goto Forum:
  


Current Time: Wed Sep 17 23:51:15 GMT 2014

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

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