Birt data source parameters from a property file

前端 未结 2 390
野趣味
野趣味 2020-12-17 00:52

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 Pass

相关标签:
2条回答
  • 2020-12-17 01:36

    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!

    0 讨论(0)
  • 2020-12-17 01:42

    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");
      
    0 讨论(0)
提交回复
热议问题