Skip Headers

Oracle9i OLAP Developer's Guide to the OLAP API
Release 2 (9.2)

Part Number A95297-01
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback

Go to previous page Go to beginning of chapter Go to next page

Making Queries Using Source Methods, 5 of 8


Selecting Values Based on Hierarchical Position

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.

Creating a Primary Source that Represents a Default Hierarchy

To create a Source that represents a default hierarchy, you take the following steps:

  1. Retrieve the default hierarchy of the MdmDimension by taking the following steps:
    1. Check to see if the MdmDimension is a union dimension by checking to see if it has an MdmUnionDimensionDefinition.
    2. If the MdmDimension has an MdmUnionDimensionDefinition, then check to see if it has a regions that are MdmHierarchy objects.
    3. If the MdmDimension has regions that are MdmHierarchy objects, select the MdmHierarchy that is its default hierarchy.
  2. Make the default hierarchy a 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.

Example 6-17 Retrieving a Default Hierarchy

// 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;
  }

Creating a Primary Source for the Parent-Child Relationship

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:

  1. Create an MdmAttribute that represents the parent-child relationships by using the getParentRelation method on the MdmHierarchy.
  2. Create a Source from the MdmAttribute created in step 1 by using the getSource method.

Creating Source Objects for Other Relationships

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".

Example 6-18 Selecting the Children

Source childParent = levelHierarchy.join(parentChild,
   levelHierarchy.value());

Example 6-19 Selecting Siblings

Source siblingParent = levelHierarchy.join(parentChild, parent);

Example 6-20 Selecting Grandparents

Source grandParent = parentChild.join(levelHierarchy, parentChild);

Drilling Down a Hierarchy: Example

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.

Example 6-21 Drilling Down a 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);

Go to previous page Go to beginning of chapter Go to next page
Oracle
Copyright © 2000, 2002 Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback