iReport Ultimate Guide - Nimsoft Library
iReport Ultimate Guide - Nimsoft Library iReport Ultimate Guide - Nimsoft Library
iReport Ultimate GuideCode Example 11-9Interface JRQueryExecuterFactory provided by UR, continued* These parameters will be created as system-defined parameters for each* report/dataset having a query of this type.* The returned array should contain consecutive pairs of parameter* names and parameter classes* (e.g. {"Param1", String.class, "Param2", "List.class"}).* @return array of built-in parameter names and types associated* with this query type*/public Object[] getBuiltinParameters();/*** Creates a query executer.* This method is called at fill time for reports/datasets having a* query supported by* this factory.* @param dataset the dataset containing the query, fields, etc.* @param parameters map of value parameters (instances of* {@link JRValueParameter JRValueParameter})* indexed by name** @return a query executer* @throws JRException*/public JRQueryExecuter createQueryExecuter(JRDataset dataset, Map parameters) throws JRException;/*** Decides whether the query executers created by this factory support* a query parameter type.* This check is performed for all $P{..} parameters in the query.** @param className the value class name of the parameter* @return whether the parameter value type is supported*/public boolean supportsQueryParameterType(String className);}There are three methods to implement: getBuiltinParameters, createQueryExecuter, andsupportsQueryParameterType:• The first method returns an array containing names and types of built-in parameters that the query executer makesavailable. This feature is useful when the query is executed against some kind of session object or against a connection toan external entity, such as a database or a server.For example, the query executer factory for SQL provides the built-in parameter REPORT_CONNECTION, storing thejava.sql.Connection instance used to execute the query. This object can be used by subreports to execute their SQLqueries. Similarly, the query executer factory for HQL provides as a parameter the Hibernate session required to performthe query.• The second method (createQueryExecuter) is responsible for creating the query executer instance, making it possiblythe most important one of the three methods.212
Data Sources and Query Executers• Finally, you can filter the accepted parameter types by implementing the supportsQueryParameterType method,which returns true if the class name given as an argument is accepted, and false otherwise.In this implementation, you will not return any built-in parameter, and you will accept all types of parameters (actually, yourquery executer factory ignores any $P{} directives in the query).Here is the code:Code Example 11-10 CustomQueryExecuterFactory source codeimport java.io.File;import java.util.Map;import net.sf.jasperreports.engine.JRDataset;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.query.JRQueryExecuter;import net.sf.jasperreports.engine.query.JRQueryExecuterFactory;/**** @version $Id: CustomQueryExecuterFactory.java 0 2009-12-08 11:45:45 CET gtoffoli $* @author Giulio Toffoli (giulio@jaspersoft.com)**/public class CustomQueryExecuterFactory implements JRQueryExecuterFactory {public Object[] getBuiltinParameters() {return new Object[]{};}public JRQueryExecuter createQueryExecuter(JRDataset jrd, Map map)throws JRException {File directory = null;try {directory = new File(jrd.getQuery().getText());} catch (Exception ex){throw new JRException(ex);}}return new CustomQueryExecuter(directory);}public boolean supportsQueryParameterType(String string) {return true;}The only relevant portion of this implementation is the createQueryExecuter method, which looks into the dataset passedas argument for the query string. We assume that the query is a directory path (remember that our data source lists the filescontained in a specified directory path). With the directory path we instance a CustomQueryExecuter, the class that willmake use of the parsed query (or the File object created starting from the query).If you would like to add support for parameters in the query string, this may be the right place to implement the parameters’parsing and replacement. We have everything we need: the query string, the dataset, and the map with the values of the213
- 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 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: Data Sources and Query Executersspe
- 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
- 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
<strong>iReport</strong> <strong>Ultimate</strong> <strong>Guide</strong>Code Example 11-9Interface JRQueryExecuterFactory provided by UR, continued* These parameters will be created as system-defined parameters for each* report/dataset having a query of this type.* The returned array should contain consecutive pairs of parameter* names and parameter classes* (e.g. {"Param1", String.class, "Param2", "List.class"}).* @return array of built-in parameter names and types associated* with this query type*/public Object[] getBuiltinParameters();/*** Creates a query executer.* This method is called at fill time for reports/datasets having a* query supported by* this factory.* @param dataset the dataset containing the query, fields, etc.* @param parameters map of value parameters (instances of* {@link JRValueParameter JRValueParameter})* indexed by name** @return a query executer* @throws JRException*/public JRQueryExecuter createQueryExecuter(JRDataset dataset, Map parameters) throws JRException;/*** Decides whether the query executers created by this factory support* a query parameter type.* This check is performed for all $P{..} parameters in the query.** @param className the value class name of the parameter* @return whether the parameter value type is supported*/public boolean supportsQueryParameterType(String className);}There are three methods to implement: getBuiltinParameters, createQueryExecuter, andsupportsQueryParameterType:• The first method returns an array containing names and types of built-in parameters that the query executer makesavailable. This feature is useful when the query is executed against some kind of session object or against a connection toan external entity, such as a database or a server.For example, the query executer factory for SQL provides the built-in parameter REPORT_CONNECTION, storing thejava.sql.Connection instance used to execute the query. This object can be used by subreports to execute their SQLqueries. Similarly, the query executer factory for HQL provides as a parameter the Hibernate session required to performthe query.• The second method (createQueryExecuter) is responsible for creating the query executer instance, making it possiblythe most important one of the three methods.212