Pre-installed Custom Data Source Types
The following pre-installed data source types were implemented using the mechanism described in this chapter:
| • | Custom JDBC-query data source types – An implementation of the JDBC Query data source lets you connect to a JDBC data source and enter a query that returns a single relational table. The Cassandra, MongoDB, and Spark data source types are specific instances of the JDBC Query data source type, where the driver is hard-coded and the required connection information is specifically requested on the New Data Source page. |
| • | File-based data source types – Implementations of these data source types read a text file in JSON, XML, or XMLA format and allow you to query its contents as a relational table. For information about using the file-based data sources, see the JasperReports Server Administrator Guide. |
| • | My Custom Data Source Pro – This data source type extends the My Custom Data Source sample by adding Domain support. |
All of these data source types support the following:
| • | You can use SQL queries in reports to access the data as a relational table. |
| • | You can create a Domain on the data source, allowing you to alter the visibility and names of the fields extracted from the file. On the Display tab of the Domain Designer you can also specify which fields are measures. |
| • | You can create Ad Hoc views using the Domain based on your file data source, allowing you to explore and interact with data from the file. |
| • | You can create virtual data sources that combine several file data sources. You can even combine different file formats, such as XML and MongoDB, as long as their data structure is compatible so the tables can be joined. You can then create a Domain based on the virtual data source to join the tables and access the joined data in Ad Hoc views and reports. |
By default the pre-installed custom data source types do not appear in the New Data Source dialog and must be enabled first.
To make pre-installed custom data source types available in the UI:
| 1. | Open the file applicationContext-remote-services.xml for editing. |
| 2. | Locate the element <util:set id="customDataSourcesToHide">. |
| 3. | Comment out the custom data source types you want to display. |
In the following example, MongoDB Query and Spark Query data source types are commented out so they appear in the drop-down menu in the New Data Source dialog:
<util:set id="customDataSourcesToHide"> <value>xmlaQueryDataSource</value> <!-- value>sparkQueryDataSource</value --> <value>remoteXmlDataSource</value> <!-- value>mongoDBQueryDataSource</value --> <value>jsonDataSource</value> <value>jdbcQueryDataSource</value> <value>cassandraQueryDataSource</value></util:set>[/code] |
After a custom query data source type has been enabled, you can create a data source instance.
To create a data source using a query example:
| 1. | Log on as an administrator. |
| 2. | Click View > Repository, expand the folder tree, and right-click a folder to select Add Resource > Data Source from the context menu. Alternatively, you can select Create > Data Source from the main menu on any page and specify a folder location later. If you installed the sample data, the suggested folder is Data Sources. The New Data Source page appears. |
| 3. | In the Type field, select a data source that you enabled, for example MongoDB Query Data Source or Spark Query Data Source. The fields on the page change to prompt for the connection information required for your data source. |
You have the option to use attributes in the values of data source parameters. See the JasperReports Server Administrator Guide for more information.
| 4. | Fill in the required connection information and enter the query you want to use. |
| 5. | Enter a name for the data source and an optional description. The Resource ID is generated from the name you enter. If you haven't already specified a location, expand the folder tree and select the location for your data source. |
| 6. | Click Save in the dialog. The data source appears in the repository. |
Understanding the Pre-installed Custom Data Sources
The Java source for the pre-installed samples can be found in the following location:
http://code.jaspersoft.com/svn/repos/jasperserver/trunk/jasperserver-custom-datasources/
To access this location, you need to be authorized. You can access this by going to http://community.jaspersoft.com/project/jasperreports-server, clicking the Browse Source Code link, and then navigating to the location above.
You can find the message catalog and Spring bean definition file for each pre-installed data source type in the locations described in Files Used by a Custom Data Source Implementation. The file names are based on the data source name, for example, applicationContext-CassandraQueryDataSource.xml.
The JDBC query and flat file data source types each leverage an existing data adapter class in JasperReports Library to build a JasperReports Library data source. The data adapter class used depends on the data source type. In addition, the pre-installed samples implement Domain support using the CustomDomainMetaData class.
My Custom Data Source Pro is similar to My Custom Data Source, with the addition of Domain support; see Custom Bean Data Source Type for more information.
For example, the JDBC custom data source type uses a JDBCQueryDataSourceDefinition
class, based on JdbcDataAdapterImpl
, to allow the user to enter database connection information and a JDBC query in the New Data Source dialog. When a user creates or views a report, dashboard, or Ad Hoc view based on an implementation of this data source type, JasperReports Server creates a JasperReports data source as follows:
| • | Builds a custom data source using the JasperReports Library JDBC Data Adapter. |
| • | JDBCQueryDataSourceService creates a JDBC connection based on the driver, URL, username, and password entered by the user. |
| • | JRJdbcQueryExecuterFactory executes the user-defined query and retrieves the metadata layer necessary for Domain support. |
| • | JDBCQueryDataSourceService creates the JasperReports data source that is used by JasperReports Library filler. |
Recommended Comments
There are no comments to display.