Birt data source parameters from a property file
Asked Answered
L

3

7

I have multiple BIRT reports that obtains the data from the same jdbc data source.

Is it possible to obtain the conection parameters (Driver URL, User Name, and Password) from an external property file or similar?

Lithophyte answered 27/8, 2009 at 11:2 Comment(0)
A
8

One you create a functional data source, you can add that data source to a report library that can be imported and used by all BIRT reports in your system. The source inside the library can have static connection attributes, or you can abstract them using externalized properties.

If you want to externalize the connection info, you will need to tweak the Data source itself. Inside the Data Source Editor, there is a "Property Binding" section that allows you to abstract all the values governing the data connection. From there you can bind the values (using the expression editor) to either report parameters or a properties file.

To bind to a report parameter, use this syntax: params[parametername].value as the expression.

To bind to a properties file, set the Resource file in the Report's top-level properties. From there you can just use the property key value to bind the entry to the Data Source.

Good Luck!

Amish answered 27/8, 2009 at 14:20 Comment(4)
Thanks! That was helpful. I had to use in the property binding values the following line of code: reportContext.getMessage("propertyKey", reportContext.getLocale());Lithophyte
For those that aren't familiar with BIRT, the Property Binding tab is found when you double click on the Data Source. It is not what is displayed in the Properties View within Eclipse.Obvolute
Please give an example of how to use the property key from the property file. It is not exactly clear how this is archived.Dissatisfactory
For property file, <key>=<value> . ex : db.driver=com.mysql.jdbc.Driver Then to bind this property, use following, reportContext.getMessage("db.driver", reportContext.getLocale());Incunabula
L
5

An alternative to the good @Mystik's "Property binding" solution is externalizing to a connection profile.

  • Create a data source (say "DS"), setting up a correct configuration of the parameters to connect to a DB.
  • Right click on "DS" > Externalize to Connection Profile... > check both options, set a name for the Connection Profile, Ok > set the path and filename were to save the Connection Profile Store (say "reportName.cps"), uncheck Encrypt... (in this way we can modify information in the XML file by hand).

Now we have "reportName.cps", an XML file that we can modify according to the environment where we place our report (development, production,...). The problem is that "DS" has loaded statically those info from "reportName.cps". It loads them dinamically if it can find "reportName.cps" in the absolute path we specified. So changing environment the file path will be different and the report won't find our file. To tell the report the correct location of the file and load it dynamically let's write a script:

  • Setup a beforeOpen script to use the connection profile that is deployed in the resource folder which can be different for every environment:

    var myresourcefolder = reportContext.getDesignHandle().getResourceFolder();
    this.setExtensionProperty("OdaConnProfileStorePath", myresourcefolder + "/reportName.cps");
    
Ladoga answered 10/6, 2011 at 7:33 Comment(0)
B
0

For those struggling configuring a connection profile, the files must look as follow (exemple using PostgreSQL as an exemple):

db-config-birt.xml (or whatever name)

<?xml version="1.0"?>
<DataTools.ServerProfiles version="1.0">
    <profile autoconnect="No" desc="" id="uuid" name="MyPostgreSQL"
             providerID="org.eclipse.birt.report.data.oda.jdbc">
        <baseproperties>
            <property name="odaDriverClass" value="org.postgresql.Driver"/>
            <property name="odaURL" value="jdbc:postgresql://XX:5432/YY"/>
            <property name="odaPassword" value="zzz"/>
            <property name="odaUser" value="abc"/>
        </baseproperties>
    </profile>
</DataTools.ServerProfiles>

The key points here are:

  • The xml MUST start with <?xml version="1.0"?> (or <?xml version="1.0" encoding="UTF-8" standalone="no"?> but when I was using it, I have having a parsing exception while deploying on Tomcat)

  • The properties keys MUST be odaDriverClass, odaURL, odaPassword, odaUser (order doesn't matter)

This file must have the right to be accessed, for e.g. chmod 664 this file

If any of the 2 conditions above aren't met, Birt will throw a laconic :

org.eclipse.birt.report.engine.api.EngineException: An exception occurred during processing. Please see the following message for details:
Cannot open the connection for the driver: org.eclipse.birt.report.data.oda.jdbc.
org.eclipse.birt.report.data.oda.jdbc.JDBCException: Missing properties in Connection.open(Properties). ;
org.eclipse.datatools.connectivity.oda.OdaException: Unable to find or access the named profile (MyPostgreSQL) in profile store path (/opt/tomcat/mytomcat/conf/db-config-birt.xml). ;
org.eclipse.datatools.connectivity.oda.OdaException ;

Then in the report (myreport.rptdesign), in the XML of it, the datasource must then look like that:

myreport.rptdesign (or whatever name)

<data-sources>
    <oda-data-source extensionID="org.eclipse.birt.report.data.oda.jdbc" name="MyPostgreSQL" id="320">
        <property name="OdaConnProfileName">MyPostgreSQL</property>
        <property name="OdaConnProfileStorePath">/opt/tomcat/mytomcat/conf/db-config-birt.xml</property>
    </oda-data-source>
</data-sources>

Obviously, you will adapt the OdaConnProfileStorePath to suit your needs

Blamable answered 9/6, 2022 at 20:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.