iReport Ultimate Guide - Nimsoft Library

iReport Ultimate Guide - Nimsoft Library iReport Ultimate Guide - Nimsoft Library

13.07.2015 Views

iReport Ultimate Guide170

Data Sources and Query ExecutersCHAPTER 11 DATA SOURCES AND QUERY EXECUTERSThere are several ways that UR can provide data to fill a report. For example, you can put an SQL query directlyinside a report and provide a connection to a database against which to execute the query and read the resulting record set, oryou can use a more sophisticated custom technology to provide a table-like set of values.iReport provides direct support for a rich set of query languages, including SQL, HQL, EJBQL, and MDX, and supports otherlanguages like XPath (XML Path Language). Moreover, in iReport, you can use custom languages by registering plug-inengines called query executors to interpret and execute the report query.If you don’t want to use a query language, or you simply don’t want to put the query inside a report, you can use a URdata source. Basically, a JR data source is an object that iterates on a record set that is organized like a simpletable.All the data sources implement the JRDataSource interface. UR provides many ready-to-use implementations ofdata sources to wrap generic data structures, like arrays or collections of JavaBeans, result sets, table models, CSV and XMLfiles, and so on. In this chapter I will present some of these data sources, and you will see how easy it is to create a custom datasource to fit any possible need. Finally, you will see how to define a custom query language and a custom query executor, aswell as how to use them.iReport provides support for all these things: you can define JDBC (Java Database Connectivity) connections to execute SQLqueries, set up Hibernate connections using Spring, and test your own JRDataSource or your custom query language.This chapter has the following sections:• How a UR Data Source Works• Understanding Data Sources and Connections in iReport• Creating and Using JDBC Connections• Working with Your JDBC Connection• Understanding the JRDataSource Interface• Data Source Types• Importing and Exporting Data Sources11.1 How a UR Data Source WorksUR is a records-based engine; to print a report, you have to provide a set of records. When the report runs,UR will iterate on this record set, creating and filling the bands according to the report definition. Bands, groups,variables—their elaboration is strictly tied to the record set used to fill the report. This is why UR defines only onequery per report. However, multiple queries/data sources can be used when inserting subreports or defining subdatasets. Each171

Data Sources and Query ExecutersCHAPTER 11 DATA SOURCES AND QUERY EXECUTERSThere are several ways that UR can provide data to fill a report. For example, you can put an SQL query directlyinside a report and provide a connection to a database against which to execute the query and read the resulting record set, oryou can use a more sophisticated custom technology to provide a table-like set of values.<strong>iReport</strong> provides direct support for a rich set of query languages, including SQL, HQL, EJBQL, and MDX, and supports otherlanguages like XPath (XML Path Language). Moreover, in <strong>iReport</strong>, you can use custom languages by registering plug-inengines called query executors to interpret and execute the report query.If you don’t want to use a query language, or you simply don’t want to put the query inside a report, you can use a URdata source. Basically, a JR data source is an object that iterates on a record set that is organized like a simpletable.All the data sources implement the JRDataSource interface. UR provides many ready-to-use implementations ofdata sources to wrap generic data structures, like arrays or collections of JavaBeans, result sets, table models, CSV and XMLfiles, and so on. In this chapter I will present some of these data sources, and you will see how easy it is to create a custom datasource to fit any possible need. Finally, you will see how to define a custom query language and a custom query executor, aswell as how to use them.<strong>iReport</strong> provides support for all these things: you can define JDBC (Java Database Connectivity) connections to execute SQLqueries, set up Hibernate connections using Spring, and test your own JRDataSource or your custom query language.This chapter has the following sections:• How a UR Data Source Works• Understanding Data Sources and Connections in <strong>iReport</strong>• Creating and Using JDBC Connections• Working with Your JDBC Connection• Understanding the JRDataSource Interface• Data Source Types• Importing and Exporting Data Sources11.1 How a UR Data Source WorksUR is a records-based engine; to print a report, you have to provide a set of records. When the report runs,UR will iterate on this record set, creating and filling the bands according to the report definition. Bands, groups,variables—their elaboration is strictly tied to the record set used to fill the report. This is why UR defines only onequery per report. However, multiple queries/data sources can be used when inserting subreports or defining subdatasets. Each171

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!