| • | A JasperReports Library data source is an implementation of the JRDataSource interface that provides data organized in rows and columns to the JasperReports Library filler; it produces a JasperPrint object. Each field declared in the JRXML corresponds to a column in the JRDataSource output. |
| • | A JasperReports Server data source is a persistent object in the repository; it is typically created by stepping through a wizard. The data source stores properties that tell JasperReports Server how to create a JRDataSource (typically in collaboration with a JRQueryExecuter). These properties vary with the type of data source; for example, a JDBC data source needs a JDBC driver, URL, user, and password. A data source can be defined as a public repository object that can be used by any report unit (for example, the repository includes the /datasources/JserverJdbcDS if you installed the sample data), or as a local object defined during the creation of a specific report unit. |
When JasperReports Server receives a request to run a report unit, it maps the report unit’s data source to an implementation of ReportDataSourceService, which returns a JRDataSource based on the data source’s persistent properties. The JRDataSource is used to fill the report and produce a JasperPrint object, from which the server generates HTML or other supported output formats.
Each JasperReports Server data source implementation must support the following features:
| • | Read and write persistent properties in the JasperReports Server repository. |
| • | Provide a user interface for creating and editing instances that are integrated with the JasperReports Server web interface. |
| • | Create a JRDataSource using the property values for a specific data source instance, or pass parameters to a JRQueryExecuter that produces the JRDataSource. |
JasperReports Server’s built-in data sources rely on several Java classes, along with specialized Spring bean files, WebFlow configurations, message files, and JSP files. The custom data source framework provides the same functionality by using a Spring bean file, a message catalog, and a minimum of one Java file (more are required to support optional features).
Query Executers
A query executer is an implementation of the JRQueryExecuter interface in JasperReports Library. It interprets the queryString in the JRXML and produces a JRDataSource. JasperReports Library (either standalone or running in JasperReports Server) determines which query executer to use by looking at the language attribute of the queryString and looking up a query executer factory registered for that language.
JasperReports Server data sources can use two different methods to create a JRDataSource:
| • | The JasperReports Server data source can create a JRDataSource directly, without a queryString in the JRXML; or |
| • | The server can pass implementation-specific objects to the query executer through the report parameter map. The query executer then uses the objects from the parameter map, as well as the contents of the queryString, to create the JRDataSource. |
Selecting the method to use depends on the nature of the data source, as well as whether you want to use a queryString to control your data source. A good example of a data source using a query executer is the JDBC data source: it passes a JDBC connection to the JDBC query executer, which it uses to pass the SQL queryString to the database.
The examples described in the following sections demonstrate both methods:
| • | The custom bean data source creates a JRDataSource directly, which returns a hard-coded list of JavaBeans. |
| • | The webscraper data source can either create a JRDataSource directly, using the properties supplied by the data source instance, or it can get those properties from a queryString in the JRXML. In this case, a data source instance isn’t required. The sample reports for this data source each demonstrate one of these approaches. |
Recommended Comments
There are no comments to display.