. How to Use a Dynamic Data Source in BIRT

Key words: BIRT  Dynamic data source

BIRT doesn’t offer a direct support for dynamic data sources. The usual workaround is to add a piece of script in the following way to the beforeOpen event of the report Data Source:

...

importPackage(Packages.java.io);

importPackage(Packages.java.util);

fin = new java.io.FileInputStream(new   String("d:/config.txt"));

props = new java.util.Properties( );

props.load(fin);

extensionProperties.odaDriverClass = new   String(props.getProperty("driver"));

extensionProperties.odaURL = new String(props.getProperty("url"));

extensionProperties.odaUser = new   String(props.getProperty("username"));

extensionProperties.odaPassword = new   String(props.getProperty("password"));

fin.close()

...

The hardcoding solution, which either needs to overhaul the report template files or makes each report inherit a shared library, is not convenient. It is particularly inconvenient when there are a large number of reports to be built and when many programmers are using BIRT because you need to go into detail on all aspects.

A much simpler solution would be available if we could use esProc to achieve a dynamic data source. esProc’s unique macro replacement feature allows passing different values to a parameter to connect to dynamic sources. This reuses code effectively and efficiently.

One example: Data sources myDB and oraDB represent two databases. Both contain an ORDER table of same structure. We need to query the ORDER tables from the databases dynamically according to different parameter values and build a report to present orders whose amount is greater than 1000. The query process is shown below:

undefined

esProc SPL gets it done using a one-liner:


A

1

=${pSource}.query("select   * from ORDER where Amount>1000")

pSource is the report parameter denoting data source name; the syntax ${…} parses a string into an expression.

With the help of esProc SPL, BIRT can effortlessly achieve dynamic computing goals. For more examples, read Some Examples of Achieving Dynamic Data Sources in BIRT.

esProc provides JDBC driver to conveniently integrate with BIRT and other reporting tools. Read How to Call an SPL Script in BIRT to find how to use and deploy esProc JDBC.

Read Getting Started with esProc to download and install esProc, get a license for free and find related documentation.