This is small article on how to implement a custom datasource or a custom query executor in Jasper Reports Server, focused on the missing information in other tutorials/documentation available on web. Before we start lets be clear on some of the related facts –
- Implementing a custom datasource in Jasper reports server is DIFFERENT from implementing a datasource to work with iReports, in both concept and method used.
- A custom datasource is a datastructure that holds the information to be presented and is NOT a query executor (Meaning its not a datasource in “JDBC” or iReport sense).
- A query executor may create and return a custom datasource OR an instance of one of the predefined datasources. For most of the cases, using one of the predefined datasources with a custom query executor are good enough and need to create a cutom datasource seldom arises. (please refer JasperServer documentation for information on predefined datasources).
Please refer the attached sample application (from jasper server source) to understand how custom data source and query executors are created.
Please note these with regard to the sample application –
- In addition to the xml configurations in the given sample, the new query language “webscraper” has to be added in the file WEB-INF/flows/queryBeans.xml
- Once this is done, if the language specified in the queryString node of a JRXML is webscraper, WebScraperQueryExecuterFactory (and then WebScraperQueryExecuter) will be invoked to execute that query. This is irrespective of the datasource you have set for that report.
- A custom datasource has real use only when it works with a custom query executor, or when it can be created and filled with required information without the need for a query (from the report XML).
Kj [/.] Sreekumar programs computers as a hobby and profession. Into programming from his school days, Sree uses Codemarvels to key in facts and fixes he finds interesting while working on different projects. Some of the articles here give away a few shades of his philosophical leanings too.