Birt data source parameters from a property file

别来无恙 提交于 2019-11-29 04:49:56
MystikSpiral

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!

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");
    
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!