views:

43

answers:

2

I have a BIRT report which connects to our test database. In the productive environment I would like to supply a datasource which is provided by the container through jndi.

How would I set the datasource programmatically for the given report?

    ...
    IReportRunnable design = birtEngine.openReportDesign ( new File ( properties.getProperty ( "reportPath" ), report + ".rptdesign" ).getAbsolutePath () );
    IRunAndRenderTask task = birtEngine.createRunAndRenderTask ( design );

    PDFRenderOption options = new PDFRenderOption ();
    options.setOutputFormat ( PDFRenderOption.OUTPUT_FORMAT_PDF );
    options.setOutputStream ( out );
    task.setRenderOption ( options );
    for ( Entry<String, Object> entry : parameters.entrySet () )
    {
        task.setParameterValue ( entry.getKey (), entry.getValue () );
    }

    task.run ();
    task.close ();
    ...

I guess I would have to modify the design but on the other hand task has a method setDataSource but that looks a bit like I would have to supply some xml dom elements.

A: 

Setting just the data source at run-time will be problematic because the data set is bound to a single data source and your controls on the report are then bound to a specific data set. This hierarchy would be pretty sticky to try and build yourself each time the report runs.

You can parameterize all aspects of the Data Source definition making your design portable through all environments. When editing your Data Source, look at the Property Binding grouping on the left hand side. This should give you ample flexibility to make your data source more portable. You can specify run-time parameters for JDBC URL elements or a run-time JNDI profile.

Hope this helps.

MystikSpiral
A: 

You can create a Report Parameter for the database connection string.

Then, set the JNDI URL under Data Source -> Property Binding -> JNDI URL, as: params["Database"].value
(Where "Database" is the name of the report parameter)

Adam