Class RolapHierarchy
- java.lang.Object
-
- mondrian.olap.OlapElementBase
-
- mondrian.olap.HierarchyBase
-
- mondrian.rolap.RolapHierarchy
-
- All Implemented Interfaces:
Annotated,Hierarchy,OlapElement
- Direct Known Subclasses:
RolapCubeHierarchy
public class RolapHierarchy extends HierarchyBase
RolapHierarchyimplementsHierarchyfor 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
RolapCubeHierarchysubclass. When the measures hierarchy is of that class, we will move the method down.)- Since:
- 10 August, 2001
- Author:
- jhyde
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRolapHierarchy.LimitedRollupMemberSubstitute for a member in a hierarchy whose rollup policy is 'partial' or 'hidden'.protected static classRolapHierarchy.RolapCalculatedMeasureCalculated member which is also a measure (that is, a member of the [Measures] dimension).(package private) static classRolapHierarchy.RolapNullMemberARolapNullMemberis the null member of its hierarchy.-
Nested classes/interfaces inherited from interface mondrian.olap.OlapElement
OlapElement.LocalizedProperty
-
-
Field Summary
Fields Modifier and Type Field Description (package private) RolapHierarchyclosureForprotected RolapLevelnullLevelThe level that the null member belongs too.protected MondrianDef.RelationOrJoinrelationprotected MondrianDef.HierarchyxmlHierarchy-
Fields inherited from class mondrian.olap.HierarchyBase
allLevelName, allMemberName, description, dimension, hasAll, levels, name, subName, uniqueName
-
Fields inherited from class mondrian.olap.OlapElementBase
caption, visible
-
-
Constructor Summary
Constructors Constructor Description RolapHierarchy(RolapDimension dimension, String subName, String caption, boolean visible, String description, boolean hasAll, RolapHierarchy closureFor, Map<String,Annotation> annotationMap)Creates a hierarchy.RolapHierarchy(RolapDimension dimension, MondrianDef.Hierarchy xmlHierarchy, MondrianDef.CubeDimension xmlCubeDimension)Creates aRolapHierarchy.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidaddToFrom(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) voidaddToFrom(SqlQuery query, RolapStar.Table table)Adds a table to the FROM clause of the query.(package private) voidaddToFromInverse(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.protected intcomputeHashCode()Computes this object's hash code.static Map<String,Annotation>createAnnotationMap(MondrianDef.Annotations annotations)(package private) RolapDimensioncreateClosedPeerDimension(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.MembercreateMember(Member parent, Level level, String name, Formula formula)Creates a member of this hierarchy.(package private) MemberReadercreateMemberReader(Role role)Creates a member reader which enforces the access-control profile ofrole.booleanequals(Object o)(package private) ExpgetAggregateChildrenExpression()Returns an expression which will compute a member's value by aggregating its children.(package private) StringgetAlias()RolapMembergetAllMember()Returns the 'all' member.Map<String,Annotation>getAnnotationMap()Returns a list of annotations.MembergetDefaultMember()Returns the default member of this hierarchy.protected org.apache.log4j.LoggergetLogger()(package private) 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.(package private) MemberReadergetMemberReader()MembergetNullMember()Returns a special member representing the "null" value.intgetOrdinalInCube()Returns the ordinal of this hierarchy in its cube.MondrianDef.RelationOrJoingetRelation()RolapSchemagetRolapSchema()StringgetSharedHierarchyName()Returns the name of the source hierarchy, if this hierarchy is shared, otherwise null.(package private) MondrianDef.RelationgetTable(String tableName)StringgetUniqueKeyLevelName()Gets "unique key level name" attribute of this Hierarchy, if set.(package private) MondrianDef.RelationgetUniqueTable()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.HierarchygetXmlHierarchy()(package private) voidinit(MondrianDef.CubeDimension xmlDimension)Initializes a hierarchy within the context of a cube.booleanisRagged()A hierarchy is ragged if it contains one or more levels with hidden members.(package private) RolapLevelnewMeasuresLevel()voidsetDefaultMember(Member defaultMember)Sets default member of this Hierarchy.(package private) voidsetMemberReader(MemberReader memberReader)(package private) booleantableExists(String tableName)-
Methods inherited from class mondrian.olap.HierarchyBase
equals, getAllLevelName, getAllMemberName, getDescription, getDimension, getHierarchy, getLevels, getName, getQualifiedName, getSubName, getUniqueName, getUniqueNameSsas, hasAll, lookupChild
-
Methods inherited from class mondrian.olap.OlapElementBase
clone, getCaption, getLocalized, hashCode, isVisible, setCaption, toString
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface mondrian.olap.OlapElement
getCaption, getLocalized, isVisible
-
-
-
-
Field Detail
-
xmlHierarchy
protected MondrianDef.Hierarchy xmlHierarchy
-
relation
protected MondrianDef.RelationOrJoin relation
-
nullLevel
protected final RolapLevel nullLevel
The level that the null member belongs too.
-
closureFor
final RolapHierarchy closureFor
-
-
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- DimensionsubName- Name of this hierarchyhasAll- Whether hierarchy has an 'all' memberclosureFor- Hierarchy for which the new hierarchy is a closure; null for regular hierarchies
-
RolapHierarchy
RolapHierarchy(RolapDimension dimension, MondrianDef.Hierarchy xmlHierarchy, MondrianDef.CubeDimension xmlCubeDimension)
Creates aRolapHierarchy.- Parameters:
dimension- the dimension this hierarchy belongs toxmlHierarchy- the xml object defining this hierarchyxmlCubeDimension- the xml object defining the cube dimension for this object
-
-
Method Detail
-
createAnnotationMap
public static Map<String,Annotation> createAnnotationMap(MondrianDef.Annotations annotations)
-
getLogger
protected org.apache.log4j.Logger getLogger()
- Specified by:
getLoggerin classOlapElementBase
-
equals
public boolean equals(Object o)
- Overrides:
equalsin classOlapElementBase
-
computeHashCode
protected int computeHashCode()
Description copied from class:OlapElementBaseComputes this object's hash code. Called at most once.- Overrides:
computeHashCodein classOlapElementBase- 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()
-
getAnnotationMap
public Map<String,Annotation> getAnnotationMap()
Description copied from interface:AnnotatedReturns a list of annotations.The map may be empty, never null.
- Returns:
- Map from annotation name to annotations.
-
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)
-
getTable
MondrianDef.Relation getTable(String tableName)
-
getRolapSchema
public RolapSchema getRolapSchema()
-
getRelation
public MondrianDef.RelationOrJoin getRelation()
-
getXmlHierarchy
public MondrianDef.Hierarchy getXmlHierarchy()
-
getDefaultMember
public Member getDefaultMember()
Description copied from interface:HierarchyReturns 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:HierarchyReturns a special member representing the "null" value. This never occurs on an axis, but may occur if functions such asLead,NextMemberandParentMemberwalk 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:HierarchyCreates a member of this hierarchy. If this is the measures hierarchy, a calculated member is created, andformulamust 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
sharedHierarchyNameholds 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
sharedHierarchyNamewill 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. Ifexpressionis 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 toexpression- 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. Ifexpressionis 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 toexpression- 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. Iftableis 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 totable- table to add to the query
-
createMemberReader
MemberReader createMemberReader(Role role)
Creates a member reader which enforces the access-control profile ofrole.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 limitedExample. 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:
isRaggedin classHierarchyBase
-
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.Closureelement 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 clauseclos- 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
-
-