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...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Data Sources and Query ExecutersWhen you enter a HiveQL query, <strong>iReport</strong> retrieves all available fields. In the next two screens, select the fields you wish todisplay in your report, and how you want to group them. After defining your HiveQL query and choosing your fields, yourreport is configured to receive data from your Hadoop Hive data source.The Hive JDBC driver does not yet fully implement the JDBC specifications, and it does not yet work correctly with theUR metadata layer (Data Domains). If reporting against a Hive data source and you are usingUR, use Topics rather than Domains.11.6.11 How to Implement a New JRDataSourceSometimes the JRDataSource supplied with UR cannot satisfy your needs. In these cases, it is possible to write anew JRDataSource. This operation is not complex; in fact, all you have to do is create a class that implements theJRDataSource interface that exposes two simple methods: next and getFieldValue:Code Example 11-6The JRDataSource interfacepackage net.sf.jasperreports.engine;public interface JRDataSource{public boolean next() throws JRException;public Object getFieldValue(JRField jrField) throws JRException;}The next method is used to set the current record into the data source. It has to return true if a new record to elaborate exists;otherwise it returns false.If the next method has been called positively, the getFieldValue method has to return the value of the requested field ornull. In particular, the requested field name is contained in the JRField object passed as a parameter. Also, JRField is aninterface through which it is possible to get the information associated with a field—the name, description, and Java type thatrepresents it (as mentioned previously in Chapter 11.5, “Understanding the JRDataSource Interface,” on page 181).Now try writing your personalized data source. The idea is a little original—you have to write a data source that explores thedirectory of a file system and returns the found objects (files or directories). The fields you will make to manage your datasource will be the file name, which you will name FILENAME; a flag that indicates whether the object is a file or a directory,which you will name IS_DIRECTORY; and the file size, if available, which you will name SIZE.There will be two constructors for your data source: the first will receive as a parameter the directory to scan, the second willhave no parameters and will use the current directory to scan.Once instantiated, the data source will look for the files and the directories present in the way you indicate and fill the arrayfiles.The next method will increase the index variable that you use to keep track of the position reached in the array files, and itwill return true until you reach the end of the array.203

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

Saved successfully!

Ooh no, something went wrong!