MdmAttribute mdmProdParentAttr = mdmProdHier.getParentAttribute();
// Get the package attribute and the Source for it.
MdmAttribute mdmPackageAttr = getContext().getAttributeByName(mdmProdDim,
"PACKAGE_AW");
Source prodPkgAttr = mdmPackageAttr.getSource();
// Get the Source objects for the metadata objects.
StringSource prodDim = (StringSource) mdmProdDim.getSource();
StringSource prodHier = (StringSource) mdmProdHier.getSource();
Source prodParent = mdmProdParentAttr.getSource();
// Sort products hierarchically, parents first, in ascending order
// without using the package attribute.
Source result1 = prodHier.recursiveJoin(prodDim.value(),
prodHier.getDataType(),
prodParent,
Source.COMPARISON_RULE_ASCENDING);
// Sort products hierarchically, parents first, in ascending order
// by package attribute value with null values first.
// Nulls first is the default, so this should this should produce
// the same results as COMPARISON_RULE_ASCENDING.
Source sortedHierNullsFirst =
prodHier.recursiveJoin(prodPkgAttr,
prodPkgAttr.getDataType(),
prodParent,
Source.COMPARISON_RULE_ASCENDING_NULLS_FIRST);
Source result2 = prodPkgAttr.join(sortedHierNullsFirst);
// Sort all products hierarchically, parents first, in ascending order
// by package attribute value with null values first.
Source sortedHierNullsLast =
prodHier.recursiveJoin(prodPkgAttr,
prodPkgAttr.getDataType(),
prodParent,
Source.COMPARISON_RULE_DESCENDING_NULLS_FIRST);
Source result3 = prodPkgAttr.join(sortedHierNullsLast);
prepareAndCommit();
println("\nresult1, using COMPARISON_RULE_ASCENDING, without package attribute:");
getContext().displayResult(result1);