iReport Ultimate Guide - Nimsoft Library
iReport Ultimate Guide - Nimsoft Library iReport Ultimate Guide - Nimsoft Library
iReport Ultimate Guideone will have its own query (or data source), fields, parameters, variables, and so on. Subdatasets are only used to feed acrosstab or a chart.Each record is a set of fields. These fields must be declared in the report in order to be used, as explained in Chapter 6. Butwhat is the difference between using a query inside a report and providing data using a JRDataSource?Basically, there is no difference. In fact, what happens behind the scenes when iReport uses a query instead of aJRDataSource is that UR executes the query using a built-in or user-defined query executor that will produce aJRDataSource. There are circumstances when providing a JDBC connection to the engine and using a query defined atreport level can simplify the use of subreports.A JRDataSource is a consumable object, which means that you cannot use the same instance of JRDataSource to fill morethan one report or subreport. A typical error is trying to use the same JRDataSource object (for example, one provided to thereport as a parameter) to feed a subreport placed in the Detail band. If the Detail band is printed more than once (and normallyit is printed for every record present in the main data source), the subreport will be filled for each main record, and every timethe subreport will iterate on the same JRDataSource. This will give results only the first time the data source is used.At the end of this chapter, you will know how to avoid this kind of error, and you’ll have all the tools you need in order todecide the best way to fill your report with any of these:• A query in a language supported by UR.• A built-in data source.• A custom data source.• A custom query language with the relative query executor.11.2 Understanding Data Sources and Connections in iReportiReport allows you to manage and configure different types of data sources to fill reports. These data sources are stored in theiReport configuration and activated when needed.When I talk about data sources, you need to understand there is a distinction between real data sources (or objects thatimplement the JRDataSource interface) and connections, used in combination with a query that is defined inside the report.In addition, the term “data source” used in UR is not the same as the concept in javax.sql.Datasource, which isonly a means of getting a physical connection to the database (usually with JNDI the lookup). The data source object I refer toin the UR realm contains concrete data.Here is a list of the data source and connection types provided by iReport:• JDBC connection• JavaBean collection data source• XML data source• CSV data source• Hibernate connection• Spring-loaded Hibernate connection• Hadoop Hive data source• JRDataSourceProvider• Custom data source• Mondrian OLAP connection• XMLA connection• EJBQL connection• Empty data sourceFinally, there is a special mode to execute a report, called query executor mode, that you can use to force the report’s creationwithout passing any connection or data source to the report engine.All the connections are “opened” and passed directly to UR during report generation. For many connections, URprovides one or more built-in parameters that can be used inside the report for several purposes (for example, tofill a subreport that needs the same connection as the parent).172
Data Sources and Query Executers• The XML data source allows you to take data from an XML document.• A CSV (comma-separated values) data source allows you to open a CSV file for use in a report.• The JavaBean set data source, custom data source, and JRDataSourceProvider allow you to print data using purposelywritten Java classes.• The Hibernate connection provides the environment to execute HQL (Hibernate Query Language) queries (thisconnection can be configured using Spring, as well).• EJBQL (Enterprise JavaBean Query Language) queries can be used with an EJBQL connection.• MDX queries can be used with a native direct connection to a Mondrian server or using the standard XML/A interface tointerrogate a generic OLAP database.An empty data source is something like a generator of records having zero fields. This kind of data source is used for testpurposes or to achieve very particular needs (like static content reports or subreports).Connections and data sources are managed through the menu command Tools > Report Datasources, which opens theconfigured connections list (Figure 11-1). To set up a new data source, you can also click the Report Datasources buttonon the toolbar.Figure 11-1Report Data Sources dialogAs mentioned previously, a connection and a data source are different objects. However, from this point on, I will usethese two words interchangeably because their functions are so similar.Even if you keep an arbitrary number of data sources ready to use, iReport works always with only one source at a time. Youcan set the active data source in several ways. The easiest and most intuitive way is to select the data source from the combobox located on the tool bar. (see Figure 11-2). You can also set the active data source by selecting a data source in theConnections/Datasources dialog box and clicking the Set as default button.173
- Page 121 and 122: 7.3 Other Group OptionsBands and Gr
- Page 123 and 124: Fonts and StylesCHAPTER 8FONTS AND
- Page 125 and 126: Fonts and StylesThe list of availab
- Page 127 and 128: Fonts and StylesFigure 8-5Font Exte
- Page 129 and 130: Fonts and StylesFigure 8-7Font Exte
- Page 131 and 132: Fonts and StylesFigure 8-10The new
- Page 133 and 134: Fonts and StylesTo apply a style to
- Page 135 and 136: Fonts and StylesFigure 8-17The outl
- Page 137 and 138: TemplatesCHAPTER 9TEMPLATESOne of t
- Page 139 and 140: TemplatesFigure 9-2Columnar reportA
- Page 141 and 142: TemplatesFigure 9-4Group by step in
- Page 143 and 144: TemplatesIf a static text element i
- Page 145 and 146: TemplatesFigure 9-8Your custom temp
- Page 147 and 148: TemplatesFigure 9-10New template in
- Page 149 and 150: TemplatesFigure 9-12Preview of repo
- Page 151 and 152: SubreportsCHAPTER 10 SUBREPORTSSubr
- Page 153 and 154: SubreportsFigure 10-3Subreport elem
- Page 155 and 156: SubreportsFigure 10-4Subreport Para
- Page 157 and 158: SubreportsFigure 10-7Just a list of
- Page 159 and 160: SubreportsFigure 10-11 Subreport Wi
- Page 161 and 162: SubreportsFigure 10-14 The final re
- Page 163 and 164: Subreports3. Click the Add button t
- Page 165 and 166: Subreports10.4 Using the Subreport
- Page 167 and 168: SubreportsFigure 10-21 Subreport co
- Page 169 and 170: SubreportsFigure 10-23 Setting Subr
- Page 171: Data Sources and Query ExecutersCHA
- Page 175 and 176: Data Sources and Query ExecutersFig
- Page 177 and 178: Data Sources and Query ExecutersFig
- Page 179 and 180: Data Sources and Query ExecutersFig
- Page 181 and 182: Data Sources and Query ExecutersFig
- Page 183 and 184: Data Sources and Query ExecutersFig
- Page 185 and 186: Data Sources and Query ExecutersFig
- Page 187 and 188: Data Sources and Query Executers•
- Page 189 and 190: Data Sources and Query ExecutersAft
- Page 191 and 192: Data Sources and Query ExecutersIns
- Page 193 and 194: Data Sources and Query Executerspub
- Page 195 and 196: Data Sources and Query ExecutersFig
- Page 197 and 198: Data Sources and Query ExecutersFig
- Page 199 and 200: Data Sources and Query Executersbe
- Page 201 and 202: Data Sources and Query ExecutersFig
- Page 203 and 204: Data Sources and Query ExecutersWhe
- Page 205 and 206: Data Sources and Query ExecutersCod
- Page 207 and 208: Data Sources and Query ExecutersPre
- Page 209 and 210: Data Sources and Query ExecutersFig
- Page 211 and 212: Data Sources and Query Executersspe
- Page 213 and 214: Data Sources and Query Executers•
- Page 215 and 216: Data Sources and Query Executersof
- Page 217 and 218: Data Sources and Query ExecutersThi
- Page 219 and 220: Data Sources and Query ExecutersCod
- Page 221 and 222: Data Sources and Query ExecutersIf
Data Sources and Query Executers• The XML data source allows you to take data from an XML document.• A CSV (comma-separated values) data source allows you to open a CSV file for use in a report.• The JavaBean set data source, custom data source, and JRDataSourceProvider allow you to print data using purposelywritten Java classes.• The Hibernate connection provides the environment to execute HQL (Hibernate Query Language) queries (thisconnection can be configured using Spring, as well).• EJBQL (Enterprise JavaBean Query Language) queries can be used with an EJBQL connection.• MDX queries can be used with a native direct connection to a Mondrian server or using the standard XML/A interface tointerrogate a generic OLAP database.An empty data source is something like a generator of records having zero fields. This kind of data source is used for testpurposes or to achieve very particular needs (like static content reports or subreports).Connections and data sources are managed through the menu command Tools > Report Datasources, which opens theconfigured connections list (Figure 11-1). To set up a new data source, you can also click the Report Datasources buttonon the toolbar.Figure 11-1Report Data Sources dialogAs mentioned previously, a connection and a data source are different objects. However, from this point on, I will usethese two words interchangeably because their functions are so similar.Even if you keep an arbitrary number of data sources ready to use, <strong>iReport</strong> works always with only one source at a time. Youcan set the active data source in several ways. The easiest and most intuitive way is to select the data source from the combobox located on the tool bar. (see Figure 11-2). You can also set the active data source by selecting a data source in theConnections/Datasources dialog box and clicking the Set as default button.173