A useful WC Sites “Tree” query

Sometimes WC Sites developers are required to efficiently obtain the hierarchical list of objects stored in the various “tree” tables as used by the product (e.g. LocaleTree, PublicationTree, SitePlanTree, AssetRelationTree). For example one might need to obtain the hierarchical list of locales for the current dimensionset (e.g. to deal with exceptions to the default fallback logic). As with all such “treet” tables, the hierarchical relationship of locales per dimensionset is nested within the table itself. Rather than iterate over the hierarchy to build our list, we can use an Oracle-specific “start with…connect by” type query which efficiently returns the list of dimensions of the dimensionset identifying each locale’s level.

SELECT oid,otype,level FROM LocaleTree START WITH nid = (SELECT nid FROM LocaleTree WHERE oid = (SELECT id FROM DimensionSet WHERE name = ‘dim_default’)) CONNECT BY nparentid = PRIOR nid ORDER BY level

The above query returns a listobject with the following output (shown here as tabularized):

oid otype level
1234567890 Dimension 1

For comparison, the DimensionSet’s hierarchy is iteratively rendered as an HTML form in the Admin GUI (see screenshot below) using the following built-in element (note that it does not use any Oracle-specific queries):

OpenMarket/Xcelerate/Admin/LocaleHierarchy/LocaleHierarchyView (Inputs: DimensionSet=xxx&id=yyy)

Screen Shot 2014-11-12 at 1.13.05 PM

Add Your Comment