iReport Ultimate Guide - Nimsoft Library
iReport Ultimate Guide - Nimsoft Library iReport Ultimate Guide - Nimsoft Library
iReport Ultimate Guideparameters). Another solution would be to pass all this information to the query executer implementation and delegate thequery parsing to it.The query executer has a simple interface, too. Again, there are three methods:• One that will produce the JRDataSource to fill the report (createDatasource).• One to clean up everything at the end of the execution (close).• And a method to interrupt the query execution (cancelQuery).Code Example 11-11 Query executer interface/*** Query executer interface.* An implementation of this interface is created when the input data* of a report/dataset is specified by a query.* The implementation will run the query and create a JRDataSource* from the result.* The query executers would usually be initialized by a JRQueryExecuterFactory* with the query and the parameter values.*/public interface JRQueryExecuter{/*** Executes the query and creates a JRDataSource out of the result.** @return a JRDataSource wrapping the query execution result.* @throws JRException*/public JRDataSource createDatasource() throws JRException;/*** Closes resources kept open during the datasource iteration.* This method is called after the report is filled or the dataset is* iterated.* If a resource is not needed after the datasource has been created,* it should be released at the end of createDatasource.*/public void close();/*** Cancels the query if it’s currently running.* This method will be called from a different thread if the client* decides to cancel the filling process.** @return true iff the query was running and it has been* cancelled* @throws JRException*/public boolean cancelQuery() throws JRException;}The very simple query executer we are creating will do nothing when the close and the cancelQuery methods are invoked.The main method, createDatasource, will create an instance of CustomDataSource, providing the report query as a path214
Data Sources and Query Executersof the directory name to list. The aim of the operation, in fact, is to return a list of file names encapsulated in a bean array datasource.Our CustomQueryExecuter will look like the following:Code Example 11-12 The source of our QueryExecuter implementationpackage samples.queryexecuter;import java.io.File;import net.sf.jasperreports.engine.JRDataSource;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.data.JRBeanArrayDataSource;import net.sf.jasperreports.engine.query.JRQueryExecuter;public class CustomQueryExecuter implements JRQueryExecuter {File directory = null;public CustomQueryExecuter(File directory){this.directory = directory;}public JRDataSource createDatasource() throws JRException {// Creates a list of files and present them using the CustomDataSourceif (directory != null && directory.exists() && directory.isDirectory()){File[] files = directory.listFiles();return new CustomDataSource(files);}throw new JRException("Invalid directory!");}public void close() {// Nothing to do in this implementation}}public boolean cancelQuery() throws JRException {// Too fast to be interrupted... :-)return false;}Up to now we have created the CustomQueryExecuterFactory and the CustomQueryExecuter, which uses a class calledCustomDataSource. This class extends the JRBeanArrayDataSource. In this sample, we may just use aJRBeanArrayDataSource, but the implementation of another custom data source can be useful to introduce the next task:creating and using a FieldsProvider.215
- 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 and 172: Data Sources and Query ExecutersCHA
- Page 173 and 174: Data Sources and Query Executers•
- 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: Data Sources and Query Executers•
- 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
- Page 223 and 224: ChartsCHAPTER 12 CHARTSUR provides
- Page 225 and 226: ChartsFigure 12-3Chart selection wi
- Page 227 and 228: ChartsFigure 12-6Dataset configurat
- Page 229 and 230: settings). These four fields have t
- Page 231 and 232: ChartsFigure 12-10 Chart Theme Desi
- Page 233 and 234: ChartsFigure 12-12 Example chart th
- Page 235 and 236: Run your report. iReport should dis
- Page 237 and 238: Charts1. First create a report.Figu
- Page 239 and 240: Charts4. Right-click on the chart a
- Page 241 and 242: Flash ChartsCHAPTER 13 FLASH CHARTS
- Page 243 and 244: Flash ChartsThe layout properties f
- Page 245 and 246: Flash ChartsThe following figure sh
- Page 247 and 248: Flash ChartsTable 13-2Entity IDs of
- Page 249 and 250: Flash ChartsTable 13-3Entity expres
- Page 251 and 252: Flash ChartsFigure 13-10 Specifying
- Page 253 and 254: Flash ChartsFigure 13-12 Bar chart
- Page 255 and 256: Flash ChartsFigure 13-16 The Charts
- Page 257 and 258: Flash ChartsFigure 13-19 Advanced o
- Page 259 and 260: Flash ChartsFigure 13-22 Entering t
- Page 261 and 262: Flash ChartsFigure 13-24 Specifying
- Page 263 and 264: Flash ChartsSpark LineSpark ColumnS
Data Sources and Query Executersof the directory name to list. The aim of the operation, in fact, is to return a list of file names encapsulated in a bean array datasource.Our CustomQueryExecuter will look like the following:Code Example 11-12 The source of our QueryExecuter implementationpackage samples.queryexecuter;import java.io.File;import net.sf.jasperreports.engine.JRDataSource;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.data.JRBeanArrayDataSource;import net.sf.jasperreports.engine.query.JRQueryExecuter;public class CustomQueryExecuter implements JRQueryExecuter {File directory = null;public CustomQueryExecuter(File directory){this.directory = directory;}public JRDataSource createDatasource() throws JRException {// Creates a list of files and present them using the CustomDataSourceif (directory != null && directory.exists() && directory.isDirectory()){File[] files = directory.listFiles();return new CustomDataSource(files);}throw new JRException("Invalid directory!");}public void close() {// Nothing to do in this implementation}}public boolean cancelQuery() throws JRException {// Too fast to be interrupted... :-)return false;}Up to now we have created the CustomQueryExecuterFactory and the CustomQueryExecuter, which uses a class calledCustomDataSource. This class extends the JRBeanArrayDataSource. In this sample, we may just use aJRBeanArrayDataSource, but the implementation of another custom data source can be useful to introduce the next task:creating and using a FieldsProvider.215