Jump to content
We've recently updated our Privacy Statement, available here ×
  • How to Dynamically Point Domain to Data Sources with Different Schema Names Based on Logged in User


    stasp
    • Version: v6.4, v6.4.2, v6.4.0, v6.3, v6.3.1, v6.3.0, v6.2, v6.2.1, v6.2.0, v6.1, v6.1.1, v6.1.0 Product: JasperReports® Server

    Use Case Overview

    This approach is useful in a scenario where you have multiple databases with the same table structure but different schema names, and need to point your TIBCO JasperReports® Server Domain to different Data Sources depending on logged in User, or depending on an Organization which the logged in User belongs to.


    The Solution

    Since JasperReports Server v6.1.0, there is an option of using Attributes in data source definition. An Attribute can be defined at global, Organization or User level and assigned a value (or comma separated list of values). A common use case is to create an Attribute with the same name but different values for each Organization and use it in a Data Source definition. This data source will be used for the Domain, and then will connect to different databases depending on what Attribute value corresponds to current User.

    More information on defining data sources based on attributes can be found in our JasperReports Server Admin Guide:

    https://community.jaspersoft.com/documentation/tibco-jasperreports-server-administrator-guide/v640/attributes-data-source-definitions

    Our case, however, is a little different, because we have different schema names. Still, it is possible to dynamically specify database schema name in Domain XML file using Attributes. The way to achieve this is as follows:

    • create a Domain using any JDBC or JNDI Data Source, as long as the table structure in database is consistent with other databases

    • export the design of your current domain WITH schema name as prefix:

      domain_export_design.png.3e2646b6d503c6da95242cfea53de207.png

    • in the Domain schema XML modify the database schema entry by replacing the static value with a reference to a User's attribute. In the example below 'schema_name' is the name of User Attribute which is assigned different schema names for different users:

      domain_schema_attribute.png.39c02c5fc5977f60aa77b6c7ef94cd95.png

    • save the changes

    • now open the existing Domain or create a new one from JasperReports Server repository interface

    • select to upload the schema you just modified:

      domain_schema_upload.png.77ac9d0e5e241e7fdffd65117ecb4aa9.png

    • Submit the changes. DO NOT open the Domain Designer

    Now when you are going to open Ad Hoc Designer using this Domain as a data source, the schema should be picked up from the attribute of the current user.


    A Word of Caution

    The drawback of this approach is that manually adding attribute reference to the XML design of a Domain is not supported by the Domain Designer, so you will not be able to modify the Domain from web interface without breaking the schema reference. If you need to modify anything in the Domain, you'll have to update the database schema reference and re-upload the XML again.

    domain_export_design.png.423816de00d12e447981db5974791dfd.png

    domain_schema_attribute.png.65e1c44c10c6f844d02c22d0613f2b14.png

    domain_schema_upload.png.ba100c4b0b4de141d2cf00f085b0642a.png


    User Feedback

    Recommended Comments

    There are no comments to display.



    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

×
×
  • Create New...