Sample Reference - Schema Reference - Configuration Reference - API (Javadoc)
|
|
|
|
JasperReports - Virtualizer Sample (version 3.7.6) | ![]() |
|
|
|
Main Features in This Sample | |
| Generating Very Large Documents Using Report Virtualizers |
![]() | ![]() | ![]() | ![]() |
|
|
top | |||||
|
|||||
![]() | Generating Very Large Documents Using Report Virtualizers | Documented by Luke Shannon | |||
|
|||||
| Description / Goal |
| How to generate very large documents using report virtualizers that optimize memory consumption. | ||
| Since |
| 1.0.0 | ||
|
|||||
|
What is Virtualization?
A JasperReport goes through 3 stages in its life cycle:
can be generated as data is processed through the report logic populating multiple pages and the elements within. In a situation such as this there is always the risk that too many objects will be created resulting in a Out of Memory error before the Filling of the report has concluded. Virtualization is a feature that allows for some of the objects that would be stored in memory during the filling to be stored on the file system instead. The virtualizer is a simple interface JRVirtualizer There are currently three implementations of this interface: Each of this will be discussed in greater detail in the proceeding sections of this document. Running the Sample Prerequisites Ant is required. By running 'ant --version' you will be able to check if ant is set up on your system (at least version 1.5 is required): C:\>ant -version Apache Ant version 1.8.0 compiled on February 1 2010You can obtain ant from http://ant.apache.org/, instructions for installation can be found there as well. Starting the Data Source In a command prompt/terminal window browse to the demo/hsqldb folder of the JasperReports source and run the command 'ant runServer'. Leave window/terminal running (see below for sample output). C:\js-workspace\jasperreports\demo\hsqldb>ant runServer Buildfile: C:\js-workspace\jasperreports\demo\hsqldb\build.xml runServer: [java] [Server@83cc67]: [Thread[main,5,main]]: checkRunning(false) entered [java] [Server@83cc67]: [Thread[main,5,main]]: checkRunning(false) exited [java] [Server@83cc67]: Startup sequence initiated from main() method [java] [Server@83cc67]: Loaded properties from [C:\js-workspace\jasperreports\demo\hsqldb\server.properties] [java] [Server@83cc67]: Initiating startup sequence... [java] [Server@83cc67]: Server socket opened successfully in 19 ms. [java] [Server@83cc67]: Database [index=0, id=0, db=file:test, alias=] opened sucessfully in 1104 ms. [java] [Server@83cc67]: Startup sequence completed in 1125 ms. [java] [Server@83cc67]: 2010-03-10 11:32:30.423 HSQLDB server 1.8.0 is online [java] [Server@83cc67]: To close normally, connect and execute SHUTDOWN SQL [java] [Server@83cc67]: From command line, use [Ctrl]+[C] to abort abruptlyGenerating the Report Open up a separate command prompt/terminal window and browse to the root directory of the sample. By running 'ant -p' you will be presented with a list of options available. Of interest in this list is all the exporters available for testing. Each export type will generate a output type in the build/report folder. By running the command 'ant' the following actions will be performed:
You can now run 'ant view' to see a version of the report in the JasperViewer (an applet contained in the JasperReports package which can be used to view a .jrprint object). Each of the these task can be ran separately as well:
You now have a working version of the report you can review. Configuring Virtualization Virtualization is not configured in the JRXML. The JRXML in this sample is a very simple one. The details around the implementation of the virtualizer can be seen in the sample Java application that is used to run the report: VirtualizerApp.java. In the fillReport() method we can see where the virtualizer is instantiated: // creating the virtualizer JRFileVirtualizer virtualizer = new JRFileVirtualizer(2, "tmp");The JRFileVirtualizer is created with a maxSize of 2 and "tmp" as the name of the directory to store data. This means once 2 pages have been created in memory, the virtualizer will begin to store data required during the filling in the "tmp" directory. A single instance of this object can be shared over multiple reports. In the fillReport(JRFileVirtualizer virtualizer) method we can see how the virtualizer is configured for use during the filling process: //Preparing parameters Map parameters = new HashMap(); parameters.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);The virtualizer must be configured as a parameter passed in during filling. Types of Virtualizers When to use Virtualization Further Resources: JasperReports Ultimate Guide (available from the JasperSoft eShop) iReport Ultimate Guide (available from the JasperSoft eShop) |
||||
|
|
© 2001-2010 Jaspersoft Corporation www.jaspersoft.com |