Class 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
    • Method Detail

      • isValidContext

        public static boolean isValidContext​(Evaluator context,
                                             boolean strict)
        Parameters:
        context - evaluation context
        strict - 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 context
        disallowVirtualCube - if true, check for virtual cubes
        levels - levels being referenced in the current context
        strict - 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: 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 - 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,
                                  AggStar aggStar)
        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
        aggStar - 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 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
      • supportsAggTables

        public boolean supportsAggTables()
        Specified by:
        supportsAggTables in interface TupleConstraint
        Returns:
        true if the constraint can leverage an aggregate table