Finding the Hierarchies of a Dimension

The QueryBuilder automatically finds the hierarchies of a dimension in the Java-client user interface.

To find all of the hierarchies of a dimension programmatically, you call the getHierarchies method of the MDDimension that represents the dimension. To find the default hierarchy, you call the getDefaultHierarchy method of the MDDimension.

Example: Finding all of the hierarchies that are defined for a dimension

The following code finds the hierarchies in a dimension (mdProdDim) and stores the descriptions of the hierarchies in a String array.


// mdManager is the MetadataManager MDDimension mdProductDimension = null; MDHierarchy[] mdHierarchies = null; String[] strHierarchyDescriptions = null; try{    // get the Product dimension    mdProductDimension = mdManager.getDimension(MDU.OBJECT_NAME, "PRODUCT");    // get the hierarchies    mdHierarchies = mdProductDimension.getHierarchies();    strHierarchyDescriptions = new String[mdHierarchy.length];    for (int i = 0; ((mdHierarchies != null) && (i < mdHierarchies.length)); i ++ ){        strHierarchyDescriptions[i] = mdHierarchies[i].getShortLabel();    } catch (MetadataManagerException e){    e.printStackTrace(); }

Example: Finding the default hierarchy

The following code finds the default hierarchy for the Product dimension.


// mdManager is the MetadataManager MDDimension mdProductDimension = null; MDHierarchy mdDefaultProductHierarchy = null; try{  // get the Product dimension   mdProductDimension = mdManager.getDimension(MDU.OBJECT_NAME, "PRODUCT");  mdDefaultProductHierarchy = mdProductDimension.getDefaultHierarchy(); } catch (MetadataManagerException e){    e.printStackTrace(); }