Class RolapHierarchy

  • All Implemented Interfaces:
    Annotated, Hierarchy, OlapElement
    Direct Known Subclasses:
    RolapCubeHierarchy

    public class RolapHierarchy
    extends HierarchyBase
    RolapHierarchy implements Hierarchy for a ROLAP database.

    The ordinal of a hierarchy within a particular cube is found by calling getOrdinalInCube(). Ordinals are contiguous and zero-based. Zero is always the [Measures] dimension.

    NOTE: It is only valid to call that method on the measures hierarchy, and on members of the RolapCubeHierarchy subclass. When the measures hierarchy is of that class, we will move the method down.)

    Since:
    10 August, 2001
    Author:
    jhyde
    • Constructor Detail

      • RolapHierarchy

        RolapHierarchy​(RolapDimension dimension,
                       String subName,
                       String caption,
                       boolean visible,
                       String description,
                       boolean hasAll,
                       RolapHierarchy closureFor,
                       Map<String,​Annotation> annotationMap)
        Creates a hierarchy.
        Parameters:
        dimension - Dimension
        subName - Name of this hierarchy
        hasAll - Whether hierarchy has an 'all' member
        closureFor - Hierarchy for which the new hierarchy is a closure; null for regular hierarchies
      • RolapHierarchy

        RolapHierarchy​(RolapDimension dimension,
                       MondrianDef.Hierarchy xmlHierarchy,
                       MondrianDef.CubeDimension xmlCubeDimension)
        Creates a RolapHierarchy.
        Parameters:
        dimension - the dimension this hierarchy belongs to
        xmlHierarchy - the xml object defining this hierarchy
        xmlCubeDimension - the xml object defining the cube dimension for this object
    • Method Detail

      • computeHashCode

        protected int computeHashCode()
        Description copied from class: OlapElementBase
        Computes this object's hash code. Called at most once.
        Overrides:
        computeHashCode in class OlapElementBase
        Returns:
        hash code
      • setMemberReader

        void setMemberReader​(MemberReader memberReader)
      • getAnnotationMap

        public Map<String,​Annotation> getAnnotationMap()
        Description copied from interface: Annotated
        Returns a list of annotations.

        The map may be empty, never null.

        Returns:
        Map from annotation name to annotations.
      • getUniqueTable

        MondrianDef.Relation getUniqueTable()
        If this hierarchy has precisely one table, returns that table; if this hierarchy has no table, return the cube's fact-table; otherwise, returns null.
      • tableExists

        boolean tableExists​(String tableName)
      • getNullMember

        public Member getNullMember()
        Description copied from interface: Hierarchy
        Returns a special member representing the "null" value. This never occurs on an axis, but may occur if functions such as Lead, NextMember and ParentMember walk off the end of the hierarchy.
      • getAllMember

        public RolapMember getAllMember()
        Returns the 'all' member.
      • createMember

        public Member createMember​(Member parent,
                                   Level level,
                                   String name,
                                   Formula formula)
        Description copied from interface: Hierarchy
        Creates a member of this hierarchy. If this is the measures hierarchy, a calculated member is created, and formula must not be null.
      • getSharedHierarchyName

        public String getSharedHierarchyName()
        Returns the name of the source hierarchy, if this hierarchy is shared, otherwise null.

        If this hierarchy is a public -- that is, it belongs to a dimension which is a usage of a shared dimension -- then sharedHierarchyName holds the unique name of the shared hierarchy; otherwise it is null.

        Suppose this hierarchy is "Weekly" in the dimension "Order Date" of cube "Sales", and that "Order Date" is a usage of the "Time" dimension. Then sharedHierarchyName will be "[Time].[Weekly]".

      • addToFromInverse

        void addToFromInverse​(SqlQuery query,
                              MondrianDef.Expression expression)
        Adds to the FROM clause of the query the tables necessary to access the members of this hierarchy in an inverse join order, used with agg tables. If expression is not null, adds the tables necessary to compute that expression.

        This method is idempotent: if you call it more than once, it only adds the table(s) to the FROM clause once.

        Parameters:
        query - Query to add the hierarchy to
        expression - Level to qualify up to; if null, qualifies up to the topmost ('all') expression, which may require more columns and more joins
      • addToFrom

        void addToFrom​(SqlQuery query,
                       MondrianDef.Expression expression)
        Adds to the FROM clause of the query the tables necessary to access the members of this hierarchy. If expression is not null, adds the tables necessary to compute that expression.

        This method is idempotent: if you call it more than once, it only adds the table(s) to the FROM clause once.

        Parameters:
        query - Query to add the hierarchy to
        expression - Level to qualify up to; if null, qualifies up to the topmost ('all') expression, which may require more columns and more joins
      • addToFrom

        void addToFrom​(SqlQuery query,
                       RolapStar.Table table)
        Adds a table to the FROM clause of the query. If table is not null, adds the table. Otherwise, add the relation on which this hierarchy is based on.

        This method is idempotent: if you call it more than once, it only adds the table(s) to the FROM clause once.

        Parameters:
        query - Query to add the hierarchy to
        table - table to add to the query
      • createMemberReader

        MemberReader createMemberReader​(Role role)
        Creates a member reader which enforces the access-control profile of role.

        This method may not be efficient, so the caller should take care not to call it too often. A cache is a good idea.

        Parameters:
        role - Role
        Returns:
        Member reader that implements access control
        Pre-condition:
        role != null
        Post-condition:
        return != null
      • getLowestMembersForAccess

        List<Member> getLowestMembersForAccess​(Evaluator evaluator,
                                               Role.HierarchyAccess hAccess,
                                               Map<Member,​Access> membersWithAccess)
        Goes recursively down a hierarchy and builds a list of the members that should be constrained on because of access controls. It isn't sufficient to constrain on the current level in the evaluator because the actual constraint could be even more limited

        Example. If we only give access to Seattle but the query is on the country level, we have to constrain at the city level, not state, or else all the values of all cities in the state will be returned.

      • isRagged

        public boolean isRagged()
        A hierarchy is ragged if it contains one or more levels with hidden members.
        Specified by:
        isRagged in class HierarchyBase
      • getAggregateChildrenExpression

        Exp getAggregateChildrenExpression()
        Returns an expression which will compute a member's value by aggregating its children.

        It is efficient to share one expression between all calculated members in a parent-child hierarchy, so we only need need to validate the expression once.

      • createClosedPeerDimension

        RolapDimension createClosedPeerDimension​(RolapLevel src,
                                                 MondrianDef.Closure clos,
                                                 MondrianDef.CubeDimension xmlDimension)
        Builds a dimension which maps onto a table holding the transitive closure of the relationship for this parent-child level.

        This method is triggered by the MondrianDef.Closure element in a schema, and is only meaningful for a parent-child hierarchy.

        When a Schema contains a parent-child Hierarchy that has an associated closure table, Mondrian creates a parallel internal Hierarchy, called a "closed peer", that refers to the closure table. This is indicated in the schema at the level of a Level, by including a Closure element. The closure table represents the transitive closure of the parent-child relationship.

        The peer dimension, with its single hierarchy, and 3 levels (all, closure, item) really 'belong to' the parent-child level. If a single hierarchy had two parent-child levels (however unlikely this might be) then each level would have its own auxiliary dimension.

        For example, in the demo schema the [HR].[Employee] dimension contains a parent-child hierarchy:

         <Dimension name="Employees" foreignKey="employee_id">
           <Hierarchy hasAll="true" allMemberName="All Employees"
                 primaryKey="employee_id">
             <Table name="employee"/>
             <Level name="Employee Id" type="Numeric" uniqueMembers="true"
                    column="employee_id" parentColumn="supervisor_id"
                    nameColumn="full_name" nullParentValue="0">
               <Closure parentColumn="supervisor_id"
                           childColumn="employee_id">
                  <Table name="employee_closure"/>
               </Closure>
               ...
         
        The internal closed peer Hierarchy has this structure:
         <Dimension name="Employees" foreignKey="employee_id">
             ...
             <Hierarchy name="Employees$Closure"
                 hasAll="true" allMemberName="All Employees"
                 primaryKey="employee_id" primaryKeyTable="employee_closure">
               <Join leftKey="supervisor_id" rightKey="employee_id">
                 <Table name="employee_closure"/>
                 <Table name="employee"/>
               </Join>
               <Level name="Closure"  type="Numeric" uniqueMembers="false"
                   table="employee_closure" column="supervisor_id"/>
               <Level name="Employee" type="Numeric" uniqueMembers="true"
                   table="employee_closure" column="employee_id"/>
             </Hierarchy>
         

        Note that the original Level with the Closure produces two Levels in the closed peer Hierarchy: a simple peer (Employee) and a closed peer (Closure).

        Parameters:
        src - a parent-child Level that has a Closure clause
        clos - a Closure clause
        Returns:
        the closed peer Level in the closed peer Hierarchy
      • setDefaultMember

        public void setDefaultMember​(Member defaultMember)
        Sets default member of this Hierarchy.
        Parameters:
        defaultMember - Default member
      • getUniqueKeyLevelName

        public String getUniqueKeyLevelName()

        Gets "unique key level name" attribute of this Hierarchy, if set. If set, this property indicates that all level properties are functionally dependent (invariant) on their associated levels, and that the set of levels from the root to the named level (inclusive) effectively defines an alternate key.

        This allows the GROUP BY to be eliminated from associated queries.

        Returns:
        the name of the "unique key" level, or null if not specified
      • getOrdinalInCube

        public int getOrdinalInCube()
        Returns the ordinal of this hierarchy in its cube.

        Temporarily defined against RolapHierarchy; will be moved to RolapCubeHierarchy as soon as the measures hierarchy is a RolapCubeHierarchy.

        Returns:
        Ordinal of this hierarchy in its cube