Link Datalayers

When datalayers run, they retrieve and cache data. Performance may be improved by minimizing the re-running of datalayers, especially if long-running queries are involved, by allowing a datalayer to share data that's already been cached by another datalayer. This topic discusses the technique of linking datalayers for this purpose.


About Linking Datalayers

Developers are always looking for ways to improve performance, particularly where database queries are concerned. You can improve the performance of your Logi applications by eliminating repeated queries of the same data, through use of a feature that allows data retrieved into one datalayer to be saved and re-used elsewhere within the application. Two elements are used in this process: the first one, Data Layer Link, identifies the data to be saved and made available; and the second one, DataLayer.Linked, provides a way to access and re-use that data.  

Making a DataLayer Link Available

The following example illustrates how to make the data in a datalayer re-usable:
 

  1. As shown above, the example definition contains an Input Select List and DataLayer.SQL elements. The datalayer uses a regular SQL query to retrieve data from the database to present as options in a selection list.
  2. Beneath the datalayer, a Data Layer Link element has been added. The effect of the element is to "save" a copy of the data for future use.

     You must give the element a unique ID.

 

If you use elements to filter, sort, and otherwise manipulate the data in the datalayer, then the positionof the Data Layer Link element in the element tree is significant. For example, above left, the raw data, as it was retrieved from the database, will be available for re-use. But, above right, because the link comes after (below) the other elements, the filtered and sorted data will be available.

You can even use multiple Data Layer Link elements beneath a datalayer. In the example above, both the raw and the filtered, sorted data would be available for re-use, for different consumers.

The data in the datalayer is now available for re-use, saving us the performance load of running one or more queries later in our application.

Back to top

 

Linking Within the Same Definition

When we have a need to re-use the data from the datalayer, we can do so using the DataLayer.Linked element:
 

  1. As shown above, in the same definition, a Data Table has been added and we'd like to use it to present some of the same data retrieved earlier for the selection list.
  2. A DataLayer.Linked element has been added beneath the Data Table.
  3. Its Link ID attribute has been set to the ID of the Data Layer Link element we used earlier. This makes the data retrieved earlier available for use in the table.
  4. Linked data can subsequently be manipulated using standard elements, such as the Sort Filter.

That's all there is to it. Multiple DataLayer.Linked elements can be used in a definition; because each one represents the original data, sorts and filters applied to one will not affect the data in another.

This technique is especially useful when presenting the same data in different ways in a single report; for example, by using a table and a chart of some kind. Logi charts can use DataLayer.Linked as their datalayer and re-use the data retrieved for the table.

 Due to order-of-operations differences, datalayers that have the Handle Quotes Inside Tokens attribute set to True will not process quotes as expected when used underneath Chart Canvas elements. In this scenario, we recommend that you use the datalayer under Local Data and link it, using the techniques described in this topic, to a datalayer for the chart.

 A datalayer used to retrieve data for a chart cannot be linked later in the definition for use with a data table. This is because the data retrieved into a datalayer for a chart is processed somewhat differently than data retrieved for a table. However, the reverse usage, a datalayer beneath a data table linked to a datalayer beneath a chart later in the definition is okay. Some developers, faced with this restriction, prefer to use a Local Data element to retrieve the data, then link its datalayer to both a chart and data table later in the definition.

Back to top

 

Linking Across Different Definitions

We've seen that data can be re-used by linking datalayers within the same definition. They can also be re-used in the same manner across different definitions. This is done by making the definition that wants to re-use the data a "target" of the definition that originally retrieves the data. The target report then includes a DataLayer.Linked element.
 

  1. As shown above, the "parent" definition has been modified to include Label, Action.Report, and Target.Report elements. This makes the label text become a link that displays the next ("detail") report.
  2. To make the re-usable data available in the detail report, the Target.Report element's Link Data Layers attribute has been set to True, as shown above, right.
  3. In the detail report definition, a DataLayer.Linked element is used in the same manner shown in the previous section in order to access the re-usable data.

 You can only share data using this technique among definitions within the same Logi application. You cannot share it with other Logi applications.

 If you're considering opening your child report in a new window, keep in mind that linked data is only available in the same session. For example, if you specify "New Window" in your Target element's Frame ID attribute and run the parent report inside Studio's Preview window, the linked datalayer won't be found. This happens because the new window opened for the child report will be outside of Studio and will start its own new session.

However, under most default browser configurations, when you run the parent report in a browser window, the new window for the child report will be opened in new tab, which uses the same session, and the linked datalayer will be found. But, if your browser is configured to open a new window for each new URL and that causes a new session to be started, then the linked datalayer will not be found by the child report.

The ability to link datalayers within and across definitions is a powerful feature in Logi applications and a good technique for developers who want to reduce the number of datalayer queries they need to run.

Back to top