| Oracle9i OLAP Developer's Guide to the OLAP API Release 2 (9.2) Part Number A95297-01 |
|
Making Queries Using Source Methods, 5 of 8
In order to select values based on their hierarchical position you need to navigate the hierarchy. To navigate within a hierarchy you need to create two primary Source objects: a primary Source that corresponds to the hierarchy, and a primary Source that represents the parent-child relationships within this hierarchy.
To create a Source that represents a default hierarchy, you take the following steps:
MdmDimension by taking the following steps:
MdmDimension is a union dimension by checking to see if it has an MdmUnionDimensionDefinition.MdmDimension has an MdmUnionDimensionDefinition, then check to see if it has a regions that are MdmHierarchy objects.MdmDimension has regions that are MdmHierarchy objects, select the MdmHierarchy that is its default hierarchy.Source object, by calling the getSource method on it.The getMyDefaultHierarchy retrieves the default hierarchy of an MdmDimension is shown below. This method calls the getMyRegions method that retrieves the regions of an MdmDimension which, in turn, calls the getMyMdmUnionDimensionDefinition method that checks to see if the MdmDimension is a union dimension.
// method that gets all of the Regions of an MdmDimension private MdmHierarchy getMyDefaultHierarchy(MdmDimension mdmDim) { List hierarchies = getMyRegions(mdmDim); if ( hierarchies == null ) return null; for (Iterator iterator = hierarchies.iterator(); iterator.hasNext();) { MdmHierarchy hier = (MdmHierarchy) iterator.next(); if (hier.hasMdmTag(MdmMetadataProvider.DEFAULT_HIERARCHY_TAG)) return hier; } return null; } // method that gets all of the Regions of an MdmDimension private List getMyRegions(MdmDimension mdmDimension ) { MdmUnionDimensionDefinition unionDimDef = getMyMdmUnionDimensionDefinition ( mdmDimension ); if ( unionDimDef != null ) return unionDimDef.getMyRegions(); return null; } // method that checks to see if MdmDimension is a UnionDimension private MdmUnionDimensionDefinition getMyMdmUnionDimensionDefinition( MdmDimension mdmDimension ) { MdmDimensionDefinition dimDef = mdmDimension.getDefinition(); if((dimDef == null) || (!(dimDef instanceof MdmUnionDimensionDefinition))) return null; return (MdmUnionDimensionDefinition) dimDef; return null; }
If an MdmHierarchy is a level hierarchy, it's values are in parent-child relationship to each other. To create a Source object that represents the parent-child relationships within a hierarchy, you take the following steps:
MdmAttribute that represents the parent-child relationships by using the getParentRelation method on the MdmHierarchy.Source from the MdmAttribute created in step 1 by using the getSource method.A feature of the OLAP API representation of a relation, such as a parent-child relation, is that it is directional. A Source object that represents a parent-child relation maps the children to the parent, but not the parents to the children. By contrast, in SQL a table that represent the relationship is non-directional. The basic reason is that the OLAP API, unlike SQL, uses the structure of Source objects to automatically determine how they join. Since in the OLAP API relations are directional, if you want a relation to be in the opposite direction, you need to invert it.
Assume that there is a Source named parentChild on a hierarchy named levelHierarchy. To create Source objects that represent other relationships, you join these two Source objects in different ways. In other words, as shown in Example 6-18, Example 6-19, and Example 6-20, you can create new Source objects that represent the children, siblings, and grandparents in the hierarchy by using the join method on the Source that represents the parentChild relation. You can also drill down a hierarchy as shown in "Drilling Down a Hierarchy: Example".
Source childParent = levelHierarchy.join(parentChild, levelHierarchy.value());
Source siblingParent = levelHierarchy.join(parentChild, parent);
Source grandParent = parentChild.join(levelHierarchy, parentChild);
Assume that there is an MdmDimension object for which you have created a Source named productsDim. Assume also that this MdmDimension object has a default hierarchy for which you have created an MdMHierarchy called prodStdHierObj and a Source called prodHeir. Example 6-21 drills down the "Trousers - Women" division of the hierarchy.
// Get the parent relation from the hierarchy MdmAttribute prodHierParentObj = prodStdHierObj.getParentRelation(); StringSource prodHierParent = prodHierParentObj.getSource(); // Select children of Trousers - Women // - Reverse the parent relation to get a children relation Source prodHierChildren = prodHier.join(prodHierParent, prodHier.value()); // - Note the join is hidden because we only want the children of // - Trousers - Women, and not Trousers - Women itself Source trousersChildren = prodHierChildren.join(prodHier, context.getDataProvider().createConstantSource("Trousers - Women"), false); // Select Shirts - Boys, Trousers - Women, and Shorts - Men Source prodHierSel = prodHier.selectValues(new String[] {"Shirts - Boys","Trousers - Women","Shorts - Men"}); // Insert the children of Trousers - Women after Trousers - Women // (which is 2nd value) Source drilledProdHierSel = prodHierSel.appendValues(trousersChildren); // This selection has the effect of sorting the result in hierarchical order. Source result = prodHier.selectValues(drilledProdHierSel);
|
![]() Copyright © 2000, 2002 Oracle Corporation. All Rights Reserved. |
|