Saturday, August 29, 2009

Mondrian - dynamic schema and datasources xml

A typical catalog entry in datasources.xml file looks like;

<catalog name="FoodMart">
<datasourceinfo>
Provider=mondrian;Jdbc=jdbc:mysql://localhost/mydb;JdbcUser=root;JdbcPassword=root;
JdbcDrivers=com.mysql.jdbc.Driver;
</datasourceinfo>
<definition>/WEB-INF/queries/Foodmart.xml</definition>
</catalog>


Instead of static schema definition file (Foodmart.xml), add a schema processor to define the schema dynamically. In such case, <definition> contains some non-existent file path. Besides this 'dummy' path, all standard and custom parameters (p1, p2) are accessible in the schema processor class.

<catalog name="cat1">
<datasourceinfo>
Provider=mondrian;Jdbc=jdbc:mysql://localhost/mydb;JdbcUser=root;JdbcPassword=root;
JdbcDrivers=com.mysql.jdbc.Driver;DynamicSchemaProcessor=com.xyz.MySchemaProcessor;
p1=value1;p2=value2
</datasourceinfo>
<definition>dummy.xml</definition>
</catalog>


If every department in your organization needs a separate catalog entry, for security and separation, either all those catalog entries can be defined static or generate the datasources.xml dynamically during the system start-up. While generating the content dynamically, make sure to provide unique catalog names and <definition> paths.

<catalog name="cat1">
<datasourceinfo>
Provider=mondrian;Jdbc=jdbc:mysql://localhost/mydb;JdbcUser=root;JdbcPassword=root;
JdbcDrivers=com.mysql.jdbc.Driver;DynamicSchemaProcessor=com.xyz.MySchemaProcessor;
p1=value1;p2=value2
</datasourceinfo>
<definition>dummy1.xml</definition>
</catalog>
<catalog name="cat2">
<datasourceinfo>
Provider=mondrian;Jdbc=jdbc:mysql://localhost/differentdb;JdbcUser=root;
JdbcPassword=root; JdbcDrivers=com.mysql.jdbc.Driver;
DynamicSchemaProcessor=com.xyz.MySchemaProcessor; p1=value111;p2=value222
</datasourceinfo>
<definition>dummy2.xml</definition>
</catalog>

No comments: