## Data Manager

The Data Manager in JReport Designer allows you to control the data retrieval of your queries, including the number of rows to be displayed and the duration required for the retrieval. It can also keep access information from previous runs of a query (including imported SQL, stored procedure and UDS which function as queries).

This topic shows the usage of the Data Manager as follows:

### Limiting the query run time and number of records

There may be many records in a table on which you are to build a report. After you have generated the query and designed the rough report, you may only want to preview several lines of records for testing, in which case, you can take advantage of the two query properties - Maximum Rows and Maximum Duration which allow you to limit the run time and number of records, saving time and resources. Taking InvoiceReport.cls as an example:

1. Click File > Open in JReport Designer.
2. In the Open Report dialog, click the Browse button to open the catalog file SampleReports.cat in `<install_root>\Demo\Reports\SampleReports`, then open InvoiceReport.cls in the catalog.
3. Adjust the Maximum Rows and Maximum Duration properties of the query Invoice on which the report is built to suitable levels. You can adjust the values in either of the following ways:
   - In the Catalog Browser, right-click the query and select Properties from the shortcut menu. In the Properties sheet, change the property values as required, then press Enter on your keyboard to apply the change.
   - In the Resource View panel, right-click the query and click Properties on the shortcut menu. In the Properties dialog, edit the property values as required and then press Enter to confirm.

   Here, modify the value of Maximum Rows to 10 and change the value of Maximum Duration to 1 second. This specifies the maximum elapsed time to be one second, and that within this duration no more than ten records will be fetched.

   Tip: If you find that you are unable to edit the properties, make sure that you have unchecked the Forbid editing data object properties option in the Options dialog (File > Options > Catalog > Forbid editing data object properties).

4. View the report. You will find that only ten rows are fetched within one second.

Notes:

- You can decide where the two properties will be applied, on JReport side or on the database side, by configuring the JdbcDriversConfig.properties file. For details, see Specifying where to implement the maximum query run time and number of records.
- If the value of the Maximum Rows/Maximum Duration property is 0 or a negative number, it means the number will be unlimited.
- If the number you specify for Maximum Rows/Maximum Duration is equal to or more than that required for running all the records in your report, Maximum Rows and Maximum Duration will be unlimited.
- It is not recommended to specify both of the properties at the same time. Sometimes the time information for large-data reports may not be very accurate. For example, if you specify 5 seconds, you may find that it takes 7 seconds, since this time also includes the time for writing the history information to a file.
- Click the Refetch Data button on the toolbar of the View tab to run the report again if you find that the specified properties have not taken effect.
- These two properties apply to the specified query, not the report. For a report with a subreport, specifying the properties for a query used by the primary report will not have any effect on the subreport's query, and vice versa. For example, Report A.cls uses query Q1, and Report B.cls uses query Q2. B.cls is inserted to A.cls as a subreport. Maximum Rows for Q1 is modified to 3. The primary report will now only fetch three records, whereas Q2 for subreport B.cls will not be affected. To limit the subreport records, you will have to restrict Q2.

### Viewing a query's running history

An important function of the Data Manager is to keep track of the run information of queries. By default, the information is not recorded and shown in the Data Manager to improve performance. If you want to show the history information, you need to first add the command line `alwaysShowDMRecord=true` in the file report.ini in `<in` `stall_root>\bin`, and then specify the Maximum Duration and Maximum Rows properties of the queries in JReport Designer. Then, the history information will be recorded in a file in `<install_root>\dm`. In this folder, JReport generates a subfolder for each catalog. For example, if the JReport sample report is run, a folder SampleReports will be created in `<install_root>\dm`. In addition, a file with a .dmt extension corresponding to the query will be created in the subfolder to store the run history information.

To change the Data Manager information output location (the default is `<install_root>\dm`), edit report.ini in `<install_root>\bin`. Change the location in the argument `dmPath=C\:\\JReport\\Designer\\dm` to the location where you would like the information to go to. For instance, `dmPath=C\:\\temp\\dm`. Make sure that the folder you specify in the report.ini argument already exists.

#### Viewing the Designer-side run history information of a query

1. Open the file report.ini in `<designer_install_root>\bin` and add the command line `alwaysShowDMRecord=true` as follows. Here, it is assumed that JReport Designer has been installed to `C:\JReport\Designer`.

       #paths
       #Thu Apr 19 13:57:30 GMT+08:00 2007
       dmPath=C\:\\JReport\\Designer\\dm
       helpPath=C\:\\JReport\\Designer\\help
       templatePath=C\:\\JReport\\Designer\\template
       tempPath=C\:\\JReport\\Designer\\temp
       stylePath=C\:\\JReport\\Designer\\style
       alwaysShowDMRecord=true

2. Start JReport Designer and open a report and adjust the Maximum Rows and Maximum Duration properties of the query on which the report is built to suitable values.
3. Click the View tab to view the report.
4. In the Resource View panel (or the Catalog Browser panel), right-click the query the report uses and choose Data Manager from the shortcut menu. You will now find that the run information of the query is displayed in the Data Manager dialog. You can sort the items by Date, Time, Rows, Duration, Report, simply by clicking the column title.

The following is an example to demonstrate how to use the Data Manager with the sample report InvoiceReport.cls. Here assumed that the command line `alwaysShowDMRecord=true` has been added to the file report.ini in `<designer_in` `stall_root>\bin`:

1. Click File > Open on the menu bar.
2. In the Open Report dialog, click the Browse button to open the catalog file SampleReports.cat in `<designer_install_root>\Demo\Reports\SampleReports`, then open the sample report InvoiceReport.cls but do not view it.
3. Click View > Catalog Browser.
4. In the Catalog Browser, right-click the query Invoice and select Data Manager. The Data Manager dialog is shown without any history information, since the report has not yet been run.
5. Close the Data Manager, then specify Maximum Rows as 5 and Maximum Duration as 3 in the Catalog Browser for the Invoice query.
6. Click the View tab to run the report. After the report result is shown, go to the Data Manager. You will now see the history of this first run of the query. The history information will include when the report is run - date and time, the running duration, the number of rows displayed, and the report that uses the query.
7. Close the report, and use the query Invoice to create another report report1.cls.
8. Run report1.cls, then the run information will be appended as a record in the Data Manager, but the Report field it shows will be report1.

#### Viewing the Server-side run history information of a query

1. Open the report.ini file in `<server_install_root>\bin` and add the command line `alwaysShowDMRecord=true` to it.
2. Publish a report that has had its query properties Maximum Rows and/or Maximum Duration set in JReport Designer to JReport Server (for details, see Publishing resources remotely).
3. Run the report on JReport Server. The Server Engine will save the query run information, but does not have a GUI to display it. In order to view the information, you will need to use the Data Manager in JReport Designer.
4. Open the report on JReport Server and start JReport Designer. Make sure that you have pointed the dmPath argument in the file report.ini in `<designer_install_root>\bin` to the output location (containing the dm folder) of the server. Then in JReport Designer, open the corresponding query in the Catalog Browser to show its server-side run history information.