Scripted data-sources: And yet another usecase for XActions gone

On the holy quest to cut back on the usage of XActions for everydays life, we come a lot closer to the goal now.

XActions are cool for solving the more complex cases of BI-Tasks. But for just getting the data for a friggin’ report they are the literal hammer trying to squash the mosquito. Yes, it works, but it leaves a mess behind. (Sorry, Marc, I tried to love XActions, but it felt like making love to a cactus. I just cant stand programming in XML for ordinary daily tasks.)

So we now have the Scriptable-Datasource working. The datasource itself was working since months in the engine, but as I learned the hard way: No feature is used when there is no GUI. And since last week the UI for defining those datasources is working. The scriptable datasource uses Apache’s Bean-Scripting-Framework to let you instantiate Swing TableModels during the report processing. The datasource has access to the current DataRow (the thing that holds the data for the current report-state), and thus is fully parametrizable. At the same time, you are free to pull in any third party code (like code that accesses your backend systems or instantiates EJBs) so that you are no longer limited to plain databases or precompiled JARs (via the Java-Call datafactory) to get your data in. And the best of all: Assuming that you have the right set of libraries on the classpath, you can use a large set of scripting languages to get your job done.

Nothing would be perfect without an example, right? So here we go:

import javax.swing.table.DefaultTableModel;

String[] columnNames = new String[5];
columnNames[0] = "Year";
columnNames[1] = "Q1";
columnNames[2] = "Q2";
columnNames[3] = "Q3";
columnNames[4] = "Q4";

DefaultTableModel model = new DefaultTableModel(columnNames, 3);
model.addRow(new Object[]{ new Integer(2001), new Integer(10), new Integer(10), new Integer(14), new Integer(21)});
model.addRow(new Object[]{ new Integer(2002), new Integer(14), new Integer(34), new Integer(10), new Integer(12)});
model.addRow(new Object[]{ new Integer(2003), new Integer(10), new Integer(11), new Integer(14), new Integer(15)});
return model;

And now back to the drawing board, as I still have to get the attribute-expression support for the “query”, “query-timeout” and “query-limit” attributes back in place. At that point, you will be able to compute the query that used for the report. But that’s definitely a topic for another blog entry.

This entry was posted in Development on by .
Thomas

About Thomas

After working as all-hands guy and lead developer on Pentaho Reporting for over an decade, I have learned a thing or two about report generation, layouting and general BI practices. I have witnessed the remarkable growth of Pentaho Reporting from a small niche product to a enterprise class Business Intelligence product. This blog documents my own perspective on Pentaho Reporting's development process and our our steps towards upcoming releases.

2 thoughts on “Scripted data-sources: And yet another usecase for XActions gone

  1. Andy Grohe

    Thomas,

    Can you provide a sample of this type of TableModel using Javascript instead of BSH?

    I think it would allow the RD to get data from any URL source via Ajax queries.

Comments are closed.