Add parameters to already existing DataSetHandle (using the birt API) [message #553095] |
Mon, 16 August 2010 09:20  |
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 11:31  |
Eclipse User |
|
|
|
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?
>
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.04710 seconds