Wednesday, 26 November 2008

The Definitive Guide to JasperReports - Part3

Couple of Weeks back i started reading The Definitive Guide to JasperReports By Teodor Danciu , Lucian Chirita.

Nice book written by Teodor Danciu , Lucian Chirita.

I wanted to share few qoutations i found from this book found from the next 2 chapters (5-6).

1) To increase the memory available for the Java application, first use the -Xmx option when launching the JVM, since the default value for this parameter is fairly small. However, if you do this with large datasets (e.g., containing tens of thousands or more records and resulting in documents that have thousands or more pages), the JVM may run out of memory.

2) net.sf.jasperreports.engine.design.JasperDesign

Instances of this class are the raw material that the JasperReports library uses to generate reports. Such instances are usually obtained by parsing the JRXML report template files using the library’s internal XML-parsing utility classes. But they can also be built programmatically by the application that uses JasperReports through API calls if working with JRXML files is not an option. Third-party GUI design tools use the JasperReports API to create these report template objects. Among the supplied samples that come with the project source files, there is one inside /demo/samples/noxmldesign that you can check to see how to dynamically create a JasperDesign object without editing a JRXML report design file.

net.sf.jasperreports.engine.JasperCompileManager

This is the class that exposes all the library’s report compilation functionality. It has various methods that allow the users to compile JRXML report templates found in files on disk or that come from input streams. It also lets you compile in-memory report templates by directly passing a net.sf.jasperreports.engine.design.JasperDesign object and receiving the corresponding net.sf.jasperreports.engine.JasperReport object.Other utility methods include report template verification and JRXML report template generation for in-memory constructed net.sf.jasperreports.engine.design.JasperDesign class instances. These instances are especially useful in GUI tools that simplify report design work.

net.sf.jasperreports.engine.data.JRXmlDataSource

If application data resides inside XML files, and you need this data to generate reports, the built-in XPath-based implementations of the JRDataSource interface are useful. With the help of an XPath query, the XML data can take a tabular form and be fed into the report-filling process to generate documents.The /demo/samples/xmldatasource sample in the distribution package shows how this special data source implementation can be used with XML data.

net.sf.jasperreports.engine.JasperFillManager

This class is the façade to the report-filling functionality of the JasperReports library. It exposes a variety of methods that receive a report template in the form of an object, file, or input stream, and also produces a document in various output forms (object, file, or output stream). Along with the report template, the report-filling engine must also receive data from the data source, as well as the values for the report parameters, to generate the documents.

Parameter values are always supplied in a java.util.Map object, in which the keys are the report parameter names.The data source can be supplied in two different forms, depending on the situation.

Normally, it is supplied as a net.sf.jasperreports.engine.JRDataSource object, as just mentioned.

However, since most reports are filled with data from relational databases, JasperReports has a built-in default behavior that lets people specify an SQL query in the report template itself. This SQL query is executed to retrieve the data for filling the report at runtime.

In such cases, the only thing JasperReports needs is a java.sql.Connection object, instead of the usual data source object. It needs this connection object to connect to the relational database management system through JDBC and execute the report query.

It automatically creates a net.sf.jasperreports.engine.JRResultSetDataSource behind the scenes to wrap the java.sql.ResultSet object returned after the execution of the query and passes it to the normal report-filling process.

net.sf.jasperreports.engine.xml.JRPrintXmlLoader

Generated documents can be stored in XML format if they are exported using the net.sf.jasperreports.engine.export.JRXmlExporter. After they’re exported, you can parse them back into net.sf.jasperreports.engine.JasperPrint objects by using this JRPrintXmlLoader.

About the Author

Teodor Danciu is the founder and architect of the JasperReports library, the most popular open source reporting tool, and is now working for JasperSoft. Before joining JasperSoft, Teodor worked for almost 8 years with several French IT companies as a software engineer and team leader on ERP and other medium-to-large database-related enterprise applications using mainly Java technologies and the J2EE platform. Teodor holds a B.S. in computer science from the Academy of Economic Studies in Bucharest.

Lucian Chirita joined Teodor Danciu at JasperSoft in the development of JasperReports library back in 2005, and he quickly became one of the main contributors to the project. Prior to joining JasperSoft, Lucian had 3 years of software engineering experience on several Java/J2EE products and applications. His contributions to JasperReports include support for crosstabs and integration with data query technologies such as Hibernate and OLAP. Lucian holds an M.S. in computer science from the University of Bucharest.

No comments: