Enabling Data Snapshots

The data snapshot feature was introduced in JasperReports Server release 4.7 to store report data in the server. Data snapshots create a significant change in the user experience:

Without data snapshots – Whenever users run a report, the server queries the data source and displays the latest data. When the same report is run over and over, the data source is often returning the same data every time. This is the behavior of all releases before 4.7, and the default behavior of release 4.7.
With data snapshots – The first time a report runs, it queries the data source and stores a copy of the data with the report in the repository. Users who view the report later see the data from the saved snapshot, not from querying the data source. Reports accessed through web service APIs are also based on the saved snapshot. For large reports or frequently viewed reports, the persisted snapshot provides a significant performance gain and reduces load on your data sources. Every user who has access to the report will see the data from the same snapshot. For users who require it, the report viewer provides a button to manually refresh the data snapshot anytime. In addition, when the scheduler runs a job on a report it always updates the snapshot. Data snapshots are implemented in JasperReports Server 4.7 and later, but must be enabled manually.

We encourage enabling data snapshots with the following recommendations:

If you have a new installation of JasperReports Server, enable snapshots to get the full server functionality. In the future, persistent data snapshots may be enabled by default.
If you are upgrading from a release earlier than 4.7, first proceed with the upgrade procedure and verify the outcome, as instructed in the JasperReports Server Installation Guide. Then, before enabling data snapshots, notify your users about this new functionality.
Data snapshots are stored in the server’s repository, which must be sized accordingly. If you have a large number of reports, or very large reports, consider the performance of your repository database before enabling snapshots. If your users rely on data that changes frequently or if they expect to see real-time data when opening a report, do not enable snapshots. Alternatively, you can enable snapshots selectively as described below.

Global Data Snapshot Configuration

The server-level settings determine whether the snapshot feature is available on the server:

Data Snapshots Server-Level Configuration

Configuration File

.../WEB-INF/applicationContext-data-snapshots.xml

Property

Bean

Description

snapshot
Persistence
Enabled

dataSnapshot
Service

When set to true, it allows the JasperReports Server report viewer to save data snapshots in the repository and open them the next time the report is run. By default, this is set to false.

There is also a property named snapshotRecordingEnabled that caches a snapshot in the report viewer memory when sorting and filtering columns interactively. This allows the report viewer to refresh the display without querying the database every time. Regardless of persistence, snapshotRecordingEnabled improves report viewing performance and decreases database load, so it should remain set to true.

Report-level Data Snapshot Configuration

You can disable snapshots on a specific report by setting the following property in the report’s JRXML:

net.sf.jasperreports.data.cache.persistable=false

This report-level property depends on the snapshot mechanism in JasperReports Server. This property has no effect in other report viewers without such a mechanism, like the viewer integrated in Jaspersoft Studio.

There are two ways to control snapshots at the report level. In the case above:

Data snapshots are enabled on the server, so most reports use them.
Reports that don't benefit from data snapshots can explicitly disable snapshots in their own JRXML.

As with all report-level properties, you can set server-wide default values, as described in Configuring JasperReports Library:

Data Snapshots Default Report-Level Configuration

Configuration File

.../WEB-INF/classes/jasperreports.properties

Property

Description

net.sf.jasperreports.data.cache.
persistable=false

When set to false, the server-wide default for reports is to not use data snapshots, however, they are still available if a report overrides this value to true in its own JRXML.

Because the report-level property takes precedence over the server-level property, this enables a second way to control snapshots:

Data snapshots are enabled on the server.
But the server-wide default is set to false, so most reports don't use them.
Reports that benefit from data snapshots can explicitly enable snapshots in their own JRXML with:

net.sf.jasperreports.data.cache.persistable=true

Data Snapshots in the Scheduler

Scheduled jobs always run the report by accessing the data source, so the output has up-to-the-minute data. When data snapshots are enabled on reports, the job always updates the data snapshot with this new data after it runs. This way, when you schedule a report, it also refreshes the data snapshot periodically -- hourly, daily, weekly, or whatever suits your data requirements.

When data snapshots are enabled on the server, the scheduler interface has an extra option to output the data snapshot. This option, as shown in the following figure, generates a copy of the report with the new data snapshot. This copy is stored in the repository as a JasperReport, identical to the report being run. Over time, this will create an archive of your report data.

If you clear the Data Snapshot Output Format option, no copy of the report is saved with the new data snapshot, but the data snapshot on the original report is still updated when the job runs. Also, you must select at least one other output format to schedule the report.

The Data Snapshot Output Option in the Scheduler

Finally, when data snapshots are enabled, you can also update them through REST web services calls. When specifying the report to run with the rest_v2/reportExecutions service, you can add arguments to explicitly update or not update the associated data snapshot. For more information, see the JasperReports Server Web Services Guide.

Version: 
Feedback
randomness