mondrian.rolap
Class SqlConstraintUtils

java.lang.Object
  extended by mondrian.rolap.SqlConstraintUtils

public class SqlConstraintUtils
extends Object

Utility class used by implementations of SqlConstraint, used to generate constraints into SqlQuery.

Since:
Nov 21, 2005
Author:
av
 

Method Summary
static void addContextConstraint(SqlQuery sqlQuery, AggStar aggStar, Evaluator evaluator, boolean restrictMemberTypes)
          For every restricting member in the current context, generates a WHERE condition and a join to the fact table.
static void addMemberConstraint(SqlQuery sqlQuery, RolapCube baseCube, AggStar aggStar, List<RolapMember> members, boolean restrictMemberTypes, boolean crossJoin)
          Creates a "WHERE exp IN (...)" condition containing the values of all parents.
static void addMemberConstraint(SqlQuery sqlQuery, RolapCube baseCube, AggStar aggStar, RolapMember parent, boolean restrictMemberTypes)
          Creates a "WHERE parent = value" constraint.
static String constrainLevel(RolapLevel level, SqlQuery query, RolapCube baseCube, String columnValue, boolean caseSensitive)
          Generates a sql expression constraining a level by some value
static boolean containsCalculatedMember(Member[] members)
           
static void joinLevelTableToFactTable(SqlQuery sqlQuery, RolapCube baseCube, AggStar aggStar, Evaluator e, RolapCubeLevel level)
          Ensures that the table of level is joined to the fact table
(package private) static List<Member> removeCalculatedMembers(List<Member> members)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addContextConstraint

public static void addContextConstraint(SqlQuery sqlQuery,
                                        AggStar aggStar,
                                        Evaluator evaluator,
                                        boolean restrictMemberTypes)
For every restricting member in the current context, generates a WHERE condition and a join to the fact table.

Parameters:
sqlQuery - the query to modify
aggStar - Aggregate table, or null if query is against fact table
restrictMemberTypes - defines the behavior if the current context contains calculated members. If true, an exception is thrown.
evaluator - Evaluator

removeCalculatedMembers

static List<Member> removeCalculatedMembers(List<Member> members)

containsCalculatedMember

public static boolean containsCalculatedMember(Member[] members)

joinLevelTableToFactTable

public static void joinLevelTableToFactTable(SqlQuery sqlQuery,
                                             RolapCube baseCube,
                                             AggStar aggStar,
                                             Evaluator e,
                                             RolapCubeLevel level)
Ensures that the table of level is joined to the fact table

Parameters:
sqlQuery - sql query under construction
aggStar -
e - evaluator corresponding to query
level - level to be added to query

addMemberConstraint

public static void addMemberConstraint(SqlQuery sqlQuery,
                                       RolapCube baseCube,
                                       AggStar aggStar,
                                       RolapMember parent,
                                       boolean restrictMemberTypes)
Creates a "WHERE parent = value" constraint.

Parameters:
sqlQuery - the query to modify
baseCube - base cube if virtual
aggStar - Definition of the aggregate table, or null
parent - the list of parent members
restrictMemberTypes - defines the behavior if parent is a calculated member. If true, an exception is thrown

addMemberConstraint

public static void addMemberConstraint(SqlQuery sqlQuery,
                                       RolapCube baseCube,
                                       AggStar aggStar,
                                       List<RolapMember> members,
                                       boolean restrictMemberTypes,
                                       boolean crossJoin)
Creates a "WHERE exp IN (...)" condition containing the values of all parents. All parents must belong to the same level.

If this constraint is part of a native cross join, there are multiple constraining members, and the members comprise the cross product of all unique member keys referenced at each level, then generating IN expressions would result in incorrect results. In that case, "WHERE ((level1 = val1a AND level2 = val2a AND ...) OR (level1 = val1b AND level2 = val2b AND ...) OR ..." is generated instead.

Parameters:
sqlQuery - the query to modify
baseCube - base cube if virtual
aggStar - (not used)
members - the list of members for this constraint
restrictMemberTypes - defines the behavior if parents contains calculated members. If true, and one of the members is calculated, an exception is thrown.
crossJoin - true if constraint is being generated as part of a native crossjoin

constrainLevel

public static String constrainLevel(RolapLevel level,
                                    SqlQuery query,
                                    RolapCube baseCube,
                                    String columnValue,
                                    boolean caseSensitive)
Generates a sql expression constraining a level by some value

Parameters:
level - the level
query - the query that the sql expression will be added to
baseCube - base cube for virtual levels
columnValue - value constraining the level
caseSensitive - if true, need to handle case sensitivity of the member value
Returns:
generated string corresponding to the expression

SourceForge.net_Logo