views:

1683

answers:

2

I'm looking at embedding JasperReports into an existing web app for reporting. The webapp sits on top of an existing database which is ancient and complex, and really not suitable for report writers to use to write reports against directly.

What I want to look at is writing some kind of wrapper around our existing data access layer (written to make our life easier talking to aforementioned ancient and complex db). Does anyone have any experience of writing custom data sources for JasperResports, or of doing anything like this?

Updated

I guess I probably wasn't clear in my question - which is probably because my requirements aren't clear either. I want to provide some way that the end-users can use something like iReport to author reports against the database, and then to use JasperReportServer for scheduling/viewing of the reports. However, the database is really, really nasty and was never designed for use in this way. We've got a access layer around it that the webapp uses to talk to it. I want to keep my end users away from the DB altogether, and the idea of a custom data source that used the access layer seemed a good option. However, I've found very little documentation on how to do that. Maybe it's just a whole lot easier than I think it is, and I'm just trying to make a dead simple thing too complicated.

Updated

Thanks for the answers. I don't think my problem has been solved, but I think the answers have helped to inform the requirements phase.

+2  A: 

Jasper reports allows you to use a "JavaBean" data source. You can load your data into any Java Bean structure and build the reports against that. Works well.

See the "Custom Data Source" section here.

Richard Nichols
Thanks. I've seen that bit already, and it only shows a basic example. I think I can see how to pull the various parameters out of the report. What I can't see is how to present the available fields to the report author.
CK
The way we did this is by creating a jar file with all the Java Beans for the reports in it. Then you add the jar file to the class path in iReport. The we put in the provider class as shown in Figure 3.5 in the link above. It has been a while but I think that is how it worked.
jschoen
+2  A: 

Every JasperReports template can have two different data sources. One is hooking it directly to a database using some jdbc driver or, in your case, providing a collection of java beans (POJO's), usually list.

JasperReports template is similar to a method definition. It has a name, i.e. compiled JR object and parameters (data source and a list of input parameters of some of the most popular Java types).

My suggestion is to use iReport tool. Open some example that comes with the JasperReports bundle, analyze it and tweak it. It's not so complicated.

UPDATE

Letting customers authoring JasperReports templates, compiling and adding to the classpath means that you'll need to open your system too much. Usually clients provide description of a desired report and developer(s) create the data source and design the template. JasperReports can have parameters. If these parameters are exposed through UI users can change the behavior of reports in the runtime.

If you really need to allow more flexibility then use the API provided by JasperReports for authoring templates. I could imagine some simple DLS for advanced users to communicate with your system creating on-fly reports.

Boris Pavlović
I didn't know they could have multiple data sources. The plan is to use iReport for report authoring. I think what I'm missing here is about querying my access layer, none of the examples I've seen have shown anything about that. I've updated the question.
CK