Class SqlContextConstraint
- java.lang.Object
-
- mondrian.rolap.SqlContextConstraint
-
- All Implemented Interfaces:
MemberChildrenConstraint
,SqlConstraint
,TupleConstraint
- Direct Known Subclasses:
RolapNativeSet.SetConstraint
public class SqlContextConstraint extends Object implements MemberChildrenConstraint, TupleConstraint
limits the result of a Member SQL query to the current evaluation context. All Members of the current context are joined against the fact table and only those rows are returned, that have an entry in the fact table.For example, if you have two dimensions, "invoice" and "time", and the current context (e.g. the slicer) contains a day from the "time" dimension, then only the invoices of that day are found. Used to optimize NON EMPTY.
The
TupleConstraint
methods may silently ignore calculated members (depends on thestrict
c'tor argument), so these may return more members than the current context restricts to. The MemberChildren methods will never accept calculated members as parents, these will cause an exception.- Since:
- Nov 2, 2005
- Author:
- av
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addConstraint(SqlQuery sqlQuery, RolapCube baseCube, AggStar aggStar)
Called from LevelMembers: restricts the SQL resultset to the current context.void
addLevelConstraint(SqlQuery sqlQuery, RolapCube baseCube, AggStar aggStar, RolapLevel level)
Will be called once for the level that contains the children of a Member.Children query.void
addMemberConstraint(SqlQuery sqlQuery, RolapCube baseCube, AggStar aggStar, List<RolapMember> parents)
Addsparents
to the current context and restricts the SQL resultset to that new context.void
addMemberConstraint(SqlQuery sqlQuery, RolapCube baseCube, AggStar aggStar, RolapMember parent)
Called from MemberChildren: addsparent
to the current context and restricts the SQL resultset to that new context.Object
getCacheKey()
Returns a key that becomes part of the key for caching the result of the SQL query.Evaluator
getEvaluator()
MemberChildrenConstraint
getMemberChildrenConstraint(RolapMember parent)
When the members of a level are fetched, the result is grouped by into parents and their children.protected boolean
isJoinRequired()
Returns whether a join with the fact table is required.static boolean
isValidContext(Evaluator context, boolean strict)
static boolean
isValidContext(Evaluator context, boolean disallowVirtualCube, Level[] levels, boolean strict)
boolean
supportsAggTables()
-
-
-
Method Detail
-
isValidContext
public static boolean isValidContext(Evaluator context, boolean strict)
- Parameters:
context
- evaluation contextstrict
- false if more rows than requested may be returned (i.e. the constraint is incomplete)- Returns:
- false if this contstraint will not work for the current context
-
isValidContext
public static boolean isValidContext(Evaluator context, boolean disallowVirtualCube, Level[] levels, boolean strict)
- Parameters:
context
- evaluation contextdisallowVirtualCube
- if true, check for virtual cubeslevels
- levels being referenced in the current contextstrict
- false if more rows than requested may be returned (i.e. the constraint is incomplete)- Returns:
- false if constraint will not work for current context
-
addMemberConstraint
public void addMemberConstraint(SqlQuery sqlQuery, RolapCube baseCube, AggStar aggStar, RolapMember parent)
Called from MemberChildren: addsparent
to the current context and restricts the SQL resultset to that new context.- Specified by:
addMemberConstraint
in interfaceMemberChildrenConstraint
- Parameters:
sqlQuery
- the query to modifybaseCube
- base cube for virtual membersaggStar
- Aggregate star, if we are reading from an aggregate table,parent
- the parent member that restricts the returned children
-
addMemberConstraint
public void addMemberConstraint(SqlQuery sqlQuery, RolapCube baseCube, AggStar aggStar, List<RolapMember> parents)
Addsparents
to the current context and restricts the SQL resultset to that new context.- Specified by:
addMemberConstraint
in interfaceMemberChildrenConstraint
- Parameters:
sqlQuery
- Query to modifybaseCube
- Base cube for virtual membersaggStar
- Aggregate table, or null if query is against fact tableparents
- List of parent members that restrict the returned children
-
addConstraint
public void addConstraint(SqlQuery sqlQuery, RolapCube baseCube, AggStar aggStar)
Called from LevelMembers: restricts the SQL resultset to the current context.- Specified by:
addConstraint
in interfaceTupleConstraint
- Parameters:
sqlQuery
- the query to modifybaseCube
- base cube for virtual cube constraintsaggStar
- aggregate star to use
-
isJoinRequired
protected boolean isJoinRequired()
Returns whether a join with the fact table is required. A join is required if the context contains members from dimensions other than level. If we are interested in the members of a level or a members children then it does not make sense to join only one dimension (the one that contains the requested members) with the fact table for NON EMPTY optimization.
-
addLevelConstraint
public void addLevelConstraint(SqlQuery sqlQuery, RolapCube baseCube, AggStar aggStar, RolapLevel level)
Description copied from interface:MemberChildrenConstraint
Will be called once for the level that contains the children of a Member.Children query. If the condition requires so, it may join the levels table to the fact table.- Specified by:
addLevelConstraint
in interfaceMemberChildrenConstraint
- Specified by:
addLevelConstraint
in interfaceTupleConstraint
- Parameters:
sqlQuery
- the query to modifybaseCube
- base cube for virtual membersaggStar
- Aggregate table, or null if query is against fact tablelevel
- the level that contains the children
-
getMemberChildrenConstraint
public MemberChildrenConstraint getMemberChildrenConstraint(RolapMember parent)
Description copied from interface:TupleConstraint
When the members of a level are fetched, the result is grouped by into parents and their children. These parent/children are stored in the parent/children cache, whose key consists of the parent and the MemberChildrenConstraint#hashKey(). So we need a matching MemberChildrenConstraint to store the parent with its children into the parent/children cache.The returned MemberChildrenConstraint must be one that would have returned the same children for the given parent as the MemberLevel query has found for that parent.
If null is returned, the parent/children will not be cached (but the level/members still will be).
- Specified by:
getMemberChildrenConstraint
in interfaceTupleConstraint
-
getCacheKey
public Object getCacheKey()
Description copied from interface:SqlConstraint
Returns a key that becomes part of the key for caching the result of the SQL query. So SqlConstraint instances that produce the same SQL resultset must return equal keys in terms of equal() and hashCode().- Specified by:
getCacheKey
in interfaceSqlConstraint
- Returns:
- valid key or null to prevent the result from being cached
-
getEvaluator
public Evaluator getEvaluator()
- Specified by:
getEvaluator
in interfaceTupleConstraint
- Returns:
- the evaluator currently associated with the constraint; null if there is no associated evaluator
-
supportsAggTables
public boolean supportsAggTables()
- Specified by:
supportsAggTables
in interfaceTupleConstraint
- Returns:
- true if the constraint can leverage an aggregate table
-
-