13.07.2015 Views

iReport Ultimate Guide - Nimsoft Library

iReport Ultimate Guide - Nimsoft Library

iReport Ultimate Guide - Nimsoft Library

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Data Sources and Query ExecutersThis data source acts like a Bean data source on a set of objects of type java.io.File, but it is able to provide two fields thatare not accessible when using a File as bean: lastModified and size.Simple, right? Now that you have the query executer and the query executer factory, you can try your new language in <strong>iReport</strong>.But before doing that, let’s see how we can improve the user experience by implementing a FieldsProvider.11.8.2 Creating a FieldsProviderA custom query executer i sa very personalized way to provide data. Like a simple data source, a query executer does notprovide any information about the name of the fields that will be available inside the report. For SQL, <strong>iReport</strong> provides amechanism to detect the available fields by executing the query and to find out which fields are exposed by the result set.Moreover, for SQL, <strong>iReport</strong> provides a query designer that helps to create the query itself. Similar tools are provided forlanguages like XPath, for which there is a tool to explore the XML file, generate the query, and map the fields.<strong>iReport</strong> also provides a way to plug-in a FieldsProvider for a custom language. When creating a new query executer for acustom language, it makes sense to provide a FieldsProvider to help the user with the new language.In the previous section we discussed a very simple language for which we provided a query executer. The language is just apath name (such as C:\My Query Executer). The query executer we wrote uses this “query” to list the files inside the directoryspecified by the query. Okay, this “language” is really too simple to think about a designer, but we can try. Our designer willbe just a file chooser dialog to select a directory on the disk. Then we can think about a way to “auto-detect” the fieldsprovided by our data source. All these features will be added to <strong>iReport</strong> by implementing a FieldsProvider.So let’s take a step back. When you write a query in the Report query dialog box, be it a simple SQL statement or a very longand complex expression in a custom language, it is very useful to have a tool capable of analyzing the query and, if necessary,executing it to detect and extract the available fields, or a tool to help you with field mapping, or a visual designer in whichyou can easily design the query itself.<strong>iReport</strong> provides natively tools of this sort for SQL, HQL, EJBQL, and MDX. For example, when editing an SQL query, thelist of available fields can be read using the Read Fields button, and when editing an HQL query, you can explore the result toselect the fields you desire.To extend these capabilities or replace the ones available for a specific language, you can write a fields provider. Through thisinterface, a visual designer, a tool to help with field mapping, and a tool to read available fields from a query can be providedfor each language type.A fields provider is plugged into <strong>iReport</strong> similarly to the way a query executer is plugged in, that is, by using the QueryExecuters tab in the Options dialog (Figure 11-40). Table 11-2 lists the default values of the query executer factory and thefields provider class for each built-in language of UR.Table 11-2 Default Language Query Executer Factory and Fields Provider ClassesLanguage Query Executer Factory Fields Provider Classsql (or SQL)hql (or HQL)ejbql (or EJBQL)mdx (or MDX)xmla-mdxxPath (or XPath)net.sf.jasperreports.engine.query.JRJdbcQueryExecuterFactorynet.sf.jasperreports.engine.query.JRHibernateQueryExecuterFactorynet.sf.jasperreports.engine.query.JRJpaQueryExecuterFactorynet.sf.jasperreports.olap.JRMondrianQueryExecuterFactorynet.sf.jasperreports.engine.query.JRXmlaQueryExecuterFactorynet.sf.jasperreports.engine.query.JRXPathQueryExecuterFactorycom.jaspersoft.ireport.designer.data.fieldsproviders.SQLFieldsProvidercom.jaspersoft.ireport.designer.data.fieldsproviders.HQLFieldsProvidercom.jaspersoft.ireport.designer.data.fieldsproviders.EJBQLFieldsProvidercom.jaspersoft.ireport.designer.data.fieldsproviders.MDXFieldsProvidercom.jaspersoft.ireport.designer.data.fieldsproviders.CincomMDXFieldsProvidercom.jaspersoft.ireport.designer.data.fieldsproviders.XMLFieldsProvider217

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

Saved successfully!

Ooh no, something went wrong!