mondrian.rolap
Class RolapHierarchy

java.lang.Object
  extended by mondrian.olap.OlapElementBase
      extended by mondrian.olap.HierarchyBase
          extended by mondrian.rolap.RolapHierarchy
All Implemented Interfaces:
Hierarchy, OlapElement
Direct Known Subclasses:
RolapCubeHierarchy

public class RolapHierarchy
extends HierarchyBase

RolapHierarchy implements Hierarchy for a ROLAP database.

Since:
10 August, 2001
Author:
jhyde
 

Nested Class Summary
static class RolapHierarchy.LimitedRollupMember
          Substitute for a member in a hierarchy whose rollup policy is 'partial' or 'hidden'.
protected static class RolapHierarchy.RolapCalculatedMeasure
          Calculated member which is also a measure (that is, a member of the [Measures] dimension).
(package private) static class RolapHierarchy.RolapNullMember
          A RolapNullMember is the null member of its hierarchy.
 
Field Summary
(package private)  Type memberType
          Type for members of this hierarchy.
protected  RolapLevel nullLevel
          The level that the null member belongs too.
protected  MondrianDef.RelationOrJoin relation
           
protected  MondrianDef.Hierarchy xmlHierarchy
           
 
Fields inherited from class mondrian.olap.HierarchyBase
allLevelName, allMemberName, description, dimension, hasAll, levels, name, subName, uniqueName
 
Fields inherited from class mondrian.olap.OlapElementBase
caption
 
Constructor Summary
RolapHierarchy(RolapDimension dimension, MondrianDef.Hierarchy xmlHierarchy, MondrianDef.CubeDimension xmlCubeDimension)
          Creates a RolapHierarchy.
RolapHierarchy(RolapDimension dimension, String subName, boolean hasAll)
           
 
Method Summary
(package private)  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.
(package private)  void addToFrom(SqlQuery query, RolapStar.Table table)
          Adds a table to the FROM clause of the query.
protected  int computeHashCode()
          Computes this object's hash code.
(package private)  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.
 Member createMember(Member parent, Level level, String name, Formula formula)
          Creates a member of this hierarchy.
(package private)  MemberReader createMemberReader(Role role)
          Creates a member reader which enforces the access-control profile of role.
 boolean equals(Object o)
           
(package private)  Exp getAggregateChildrenExpression()
          Returns an expression which will compute a member's value by aggregating its children.
(package private)  String getAlias()
           
 RolapMember getAllMember()
          Returns the 'all' member.
 Member getDefaultMember()
          Returns the default member of this hierarchy.
protected  org.apache.log4j.Logger getLogger()
           
(package private)  MemberReader getMemberReader()
           
 Member getNullMember()
          Returns a special member representing the "null" value.
 MondrianDef.RelationOrJoin getRelation()
           
 RolapSchema getRolapSchema()
           
 String getSharedHierarchyName()
          Returns the name of the source hierarchy, if this hierarchy is shared, otherwise null.
(package private)  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.
 MondrianDef.Hierarchy getXmlHierarchy()
           
(package private)  void init(MondrianDef.CubeDimension xmlDimension)
          Initializes a hierarchy within the context of a cube.
 boolean isRagged()
          A hierarchy is ragged if it contains one or more levels with hidden members.
(package private)  RolapLevel newMeasuresLevel()
           
 void setDefaultMember(Member defaultMember)
          Sets default member of this Hierarchy.
(package private)  void setMemberReader(MemberReader memberReader)
           
(package private)  boolean tableExists(String tableName)
           
 
Methods inherited from class mondrian.olap.HierarchyBase
equals, getAllLevelName, getAllMemberName, getDescription, getDimension, getHierarchy, getLevels, getName, getQualifiedName, getSubName, getUniqueName, hasAll, lookupChild, lookupChild
 
Methods inherited from class mondrian.olap.OlapElementBase
clone, getCaption, hashCode, setCaption, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface mondrian.olap.OlapElement
getCaption
 

Field Detail

xmlHierarchy

protected MondrianDef.Hierarchy xmlHierarchy

relation

protected MondrianDef.RelationOrJoin relation

memberType

final Type memberType
Type for members of this hierarchy. Set once to avoid excessive newing.


nullLevel

protected final RolapLevel nullLevel
The level that the null member belongs too.

Constructor Detail

RolapHierarchy

RolapHierarchy(RolapDimension dimension,
               String subName,
               boolean hasAll)

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

getLogger

protected org.apache.log4j.Logger getLogger()
Specified by:
getLogger in class OlapElementBase

equals

public boolean equals(Object o)
Overrides:
equals in class OlapElementBase

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

init

void init(MondrianDef.CubeDimension xmlDimension)
Initializes a hierarchy within the context of a cube.


setMemberReader

void setMemberReader(MemberReader memberReader)

getMemberReader

MemberReader getMemberReader()

newMeasuresLevel

RolapLevel newMeasuresLevel()

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)

getRolapSchema

public RolapSchema getRolapSchema()

getRelation

public MondrianDef.RelationOrJoin getRelation()

getXmlHierarchy

public MondrianDef.Hierarchy getXmlHierarchy()

getDefaultMember

public Member getDefaultMember()
Description copied from interface: Hierarchy
Returns the default member of this hierarchy.

If a hierarchy is subject to access-control, the default member may not be visible, so use SchemaReader.getHierarchyDefaultMember(mondrian.olap.Hierarchy).


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.


getAlias

String getAlias()

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


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.

Pre-condition:
role != null
Post-condition:
return != null

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

SourceForge.net_Logo