You can enable lazy loading at several levels. In ascending levels of precedence, these are:
Repository lazyLoadItems Property
Set the repository’s lazyLoadItems
property to true
. As installed, the Oracle Commerce Platform enables lazy loading on a number of its versioned and non-versioned repositories. To verify whether a given repository uses lazy loading, check its lazyLoadItems
property.
Item Descriptor loadingStrategy Attribute
Set the loadingStrategy
attribute to lazy
. You can set the loadingStrategy
property on the item type to collect, or on the multi-valued property that references that item type. The loadingStrategy
setting of a multi-valued property takes precedence over the referenced item type.
The following example shows how you might define the multi-valued property categoryProducts
, which references a list of product
components, and sets its loadingStrategy
attribute to lazy
:
<property category-resource="categoryProducts" name="fixedChildProducts" data-type="list" component-item-type="product" column-name="child_prd_id" queryable="true" display-name-resource="fixedChildProducts"> <attribute name="loadingStrategy" value="lazy"/> <attribute name="propertySortPriority" value="-4"/> <attribute name="references" value="true"/> </property>
Note: If you preload an item type to a repository’s cache on startup, you must disable lazy loading for the item-type until the preload operation is complete (see Preloading Caches earlier in this chapter).
API
You can set the loading strategy programmatically any time after startup. The following code shows how you might use the atg.adapter.gsa.LoadingStrategyContext
methods pushLoadStrategy()
and popLoadStrategy()
, to override and restore the current thread’s loading strategy, respectively:
try { LoadingStrategyContext.pushLoadStrategy("lazy"); // or set to "eager" // access a collection property that references other items List listItems = (List) someItem.getPropertyValue("collectionProperty"); // or run a query RepositoryItem [] queryResults = rqlStatement.executeQuery(view, null); } finally { LoadingStrategyContext.popLoadStrategy(); }
For full information about the LoadingStrategyContext
class and all its methods, see the online ATG Platform API Reference.