mondrian.rolap
Class SqlContextConstraint

java.lang.Object
  extended by 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 the strict 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
 

Field Summary
(package private)  List<Object> cacheKey
           
 
Constructor Summary
SqlContextConstraint(RolapEvaluator evaluator, boolean strict)
          Creates a SqlContextConstraint.
 
Method Summary
 void addConstraint(SqlQuery sqlQuery, RolapCube baseCube)
          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)
          Adds parents 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: adds parent 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)
           
static boolean isValidContext(Evaluator context, boolean disallowVirtualCube, Level[] levels)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cacheKey

List<Object> cacheKey
Constructor Detail

SqlContextConstraint

SqlContextConstraint(RolapEvaluator evaluator,
                     boolean strict)
Creates a SqlContextConstraint.

Parameters:
evaluator - Evaluator
strict - defines the behaviour if the evaluator context contains calculated members. If true, an exception is thrown, otherwise calculated members are silently ignored. The methods MemberChildrenConstraint.addMemberConstraint(mondrian.rolap.sql.SqlQuery, mondrian.rolap.RolapCube, mondrian.rolap.aggmatcher.AggStar, RolapMember) and MemberChildrenConstraint.addMemberConstraint(mondrian.rolap.sql.SqlQuery, mondrian.rolap.RolapCube, mondrian.rolap.aggmatcher.AggStar, java.util.List) will never accept a calculated member as parent.
Method Detail

isValidContext

public static boolean isValidContext(Evaluator context)
Returns:
false if this contstraint will not work for the current context

isValidContext

public static boolean isValidContext(Evaluator context,
                                     boolean disallowVirtualCube,
                                     Level[] levels)
Parameters:
context - evaluation context
disallowVirtualCube - if true, check for virtual cubes
levels - levels being referenced in the current context
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: adds parent to the current context and restricts the SQL resultset to that new context.

Specified by:
addMemberConstraint in interface MemberChildrenConstraint
Parameters:
sqlQuery - the query to modify
baseCube - base cube for virtual members
aggStar - 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)
Adds parents to the current context and restricts the SQL resultset to that new context.

Specified by:
addMemberConstraint in interface MemberChildrenConstraint
Parameters:
sqlQuery - the query to modify
baseCube - base cube for virtual members
aggStar - Aggregate table, or null if query is against fact table
parents - list of parent members that restrict the returned children.

addConstraint

public void addConstraint(SqlQuery sqlQuery,
                          RolapCube baseCube)
Called from LevelMembers: restricts the SQL resultset to the current context.

Specified by:
addConstraint in interface TupleConstraint
Parameters:
sqlQuery - the query to modify
baseCube - base cube for virtual cube constraints

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 interface MemberChildrenConstraint
Specified by:
addLevelConstraint in interface TupleConstraint
Parameters:
sqlQuery - the query to modify
baseCube - base cube for virtual members
aggStar - Aggregate table, or null if query is against fact table
level - 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 interface TupleConstraint

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 interface SqlConstraint
Returns:
valid key or null to prevent the result from being cached

getEvaluator

public Evaluator getEvaluator()
Specified by:
getEvaluator in interface TupleConstraint
Returns:
the evaluator currently associated with the constraint; null if there is no associated evaluator

SourceForge.net_Logo