mondrian.rolap
Class SqlTupleReader

java.lang.Object
  extended by mondrian.rolap.SqlTupleReader
All Implemented Interfaces:
TupleReader
Direct Known Subclasses:
HighCardSqlTupleReader

public class SqlTupleReader
extends java.lang.Object
implements TupleReader

Reads the members of a single level (level.members) or of multiple levels (crossjoin).

Allows the result to be restricted by a TupleConstraint. So the SqlTupleReader can also read Member.Descendants (which is level.members restricted to a common parent) and member.children (which is a special case of member.descendants). Other constraints, especially for the current slicer or evaluation context, are possible.

Caching

When a SqlTupleReader reads level.members, it groups the result into parent/children pairs and puts them into the cache. In order that these can be found later when the children of a parent are requested, a matching constraint must be provided for every parent.

Since:
Nov 11, 2005
Version:
$Id: //open/mondrian/src/main/mondrian/rolap/SqlTupleReader.java#70 $
Author:
av

Nested Class Summary
(package private) static class SqlTupleReader.WhichSelect
          Description of the position of a SELECT statement in a UNION.
 
Nested classes/interfaces inherited from interface mondrian.rolap.TupleReader
TupleReader.MemberBuilder
 
Field Summary
protected  TupleConstraint constraint
           
(package private)  int maxRows
           
(package private)  java.util.List<TargetBase> targets
           
 
Constructor Summary
SqlTupleReader(TupleConstraint constraint)
           
 
Method Summary
 void addLevelMembers(RolapLevel level, TupleReader.MemberBuilder memberBuilder, java.util.List<RolapMember> srcMembers)
          Adds a hierarchy to retrieve members from.
protected  void addLevelMemberSql(SqlQuery sqlQuery, RolapLevel level, RolapCube baseCube, SqlTupleReader.WhichSelect whichSelect, AggStar aggStar)
          Generates the SQL statement to access members of level.
(package private)  AggStar chooseAggStar(Evaluator evaluator)
          Obtains the AggStar instance which corresponds to an aggregate table which can be used to support the member constraint.
(package private)  java.lang.String generateSelectForLevels(javax.sql.DataSource dataSource, RolapCube baseCube, SqlTupleReader.WhichSelect whichSelect)
          Generates the SQL string corresponding to the levels referenced.
(package private)  java.util.Collection<RolapCube> getBaseCubeCollection(Query query)
           
 java.lang.Object getCacheKey()
          Returns an object that uniquely identifies the Result that this TupleReader would return.
 int getEnumTargetCount()
           
protected  Evaluator getEvaluator(TupleConstraint constraint)
          Obtains the evaluator used to find an aggregate table to support the Tuple constraint.
(package private)  int getMaxRows()
           
protected  boolean isLevelCollapsed(AggStar aggStar, RolapCubeLevel level)
          Determine if the given aggregate table has the dimension level specified within in (AggStar.FactTable) it, aka collapsed, or associated with foreign keys (AggStar.DimTable)
protected  boolean levelContainsMultipleColumns(RolapLevel level)
          Determine if a level contains more than a single column for its data, such as an ordinal column or property column
(package private)  java.lang.String makeLevelMembersSql(javax.sql.DataSource dataSource)
           
protected  void prepareTuples(javax.sql.DataSource dataSource, java.util.List<java.util.List<RolapMember>> partialResult, java.util.List<java.util.List<RolapMember>> newPartialResult)
           
 java.util.List<RolapMember> readMembers(javax.sql.DataSource dataSource, java.util.List<java.util.List<RolapMember>> partialResult, java.util.List<java.util.List<RolapMember>> newPartialResult)
          Performs the read.
 java.util.List<RolapMember[]> readTuples(javax.sql.DataSource jdbcConnection, java.util.List<java.util.List<RolapMember>> partialResult, java.util.List<java.util.List<RolapMember>> newPartialResult)
          Performs the read.
(package private)  void setMaxRows(int maxRows)
           
(package private)  java.lang.String sqlForEmptyTuple(javax.sql.DataSource dataSource, java.util.Collection<RolapCube> baseCubes)
           
(package private)  boolean targetIsOnBaseCube(TargetBase target, RolapCube baseCube)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

constraint

protected final TupleConstraint constraint

targets

java.util.List<TargetBase> targets

maxRows

int maxRows
Constructor Detail

SqlTupleReader

public SqlTupleReader(TupleConstraint constraint)
Method Detail

addLevelMembers

public void addLevelMembers(RolapLevel level,
                            TupleReader.MemberBuilder memberBuilder,
                            java.util.List<RolapMember> srcMembers)
Description copied from interface: TupleReader
Adds a hierarchy to retrieve members from.

Specified by:
addLevelMembers in interface TupleReader
Parameters:
level - level that the members correspond to
memberBuilder - used to build new members for this level
srcMembers - if set, array of enumerated members that make up this level

getCacheKey

public java.lang.Object getCacheKey()
Description copied from interface: TupleReader
Returns an object that uniquely identifies the Result that this TupleReader would return. Clients may use this as a key for caching the result.

Specified by:
getCacheKey in interface TupleReader

getEnumTargetCount

public int getEnumTargetCount()
Returns:
number of targets that contain enumerated sets with calculated members

prepareTuples

protected void prepareTuples(javax.sql.DataSource dataSource,
                             java.util.List<java.util.List<RolapMember>> partialResult,
                             java.util.List<java.util.List<RolapMember>> newPartialResult)

readMembers

public java.util.List<RolapMember> readMembers(javax.sql.DataSource dataSource,
                                               java.util.List<java.util.List<RolapMember>> partialResult,
                                               java.util.List<java.util.List<RolapMember>> newPartialResult)
Description copied from interface: TupleReader
Performs the read.

Specified by:
readMembers in interface TupleReader
Parameters:
dataSource - source for reading tuples
partialResult - partially cached result that should be used instead of executing sql query
newPartialResult - if non-null, return the result of the read; note that this is a subset of the full return list
Returns:
a list of RolapMember

readTuples

public java.util.List<RolapMember[]> readTuples(javax.sql.DataSource jdbcConnection,
                                                java.util.List<java.util.List<RolapMember>> partialResult,
                                                java.util.List<java.util.List<RolapMember>> newPartialResult)
Description copied from interface: TupleReader
Performs the read.

Specified by:
readTuples in interface TupleReader
Returns:
a list of RolapMember[]

makeLevelMembersSql

java.lang.String makeLevelMembersSql(javax.sql.DataSource dataSource)

getBaseCubeCollection

java.util.Collection<RolapCube> getBaseCubeCollection(Query query)

sqlForEmptyTuple

java.lang.String sqlForEmptyTuple(javax.sql.DataSource dataSource,
                                  java.util.Collection<RolapCube> baseCubes)

generateSelectForLevels

java.lang.String generateSelectForLevels(javax.sql.DataSource dataSource,
                                         RolapCube baseCube,
                                         SqlTupleReader.WhichSelect whichSelect)
Generates the SQL string corresponding to the levels referenced.

Parameters:
dataSource - jdbc connection that they query will execute against
baseCube - this is the cube object for regular cubes, and the underlying base cube for virtual cubes
whichSelect - Position of this select statement in a union
Returns:
SQL statement string

targetIsOnBaseCube

boolean targetIsOnBaseCube(TargetBase target,
                           RolapCube baseCube)

addLevelMemberSql

protected void addLevelMemberSql(SqlQuery sqlQuery,
                                 RolapLevel level,
                                 RolapCube baseCube,
                                 SqlTupleReader.WhichSelect whichSelect,
                                 AggStar aggStar)
Generates the SQL statement to access members of level. For example,
SELECT "country", "state_province", "city"
 FROM "customer"
 GROUP BY "country", "state_province", "city", "init", "bar"
 ORDER BY "country", "state_province", "city"
accesses the "City" level of the "Customers" hierarchy. Note that:

Parameters:
sqlQuery - the query object being constructed
level - level to be added to the sql query
baseCube - this is the cube object for regular cubes, and the underlying base cube for virtual cubes
whichSelect - describes whether this select belongs to a larger
aggStar - aggregate star if available select containing unions or this is a non-union select

getEvaluator

protected Evaluator getEvaluator(TupleConstraint constraint)
Obtains the evaluator used to find an aggregate table to support the Tuple constraint.

Parameters:
constraint -
Returns:
evaluator for constraint

levelContainsMultipleColumns

protected boolean levelContainsMultipleColumns(RolapLevel level)
Determine if a level contains more than a single column for its data, such as an ordinal column or property column

Parameters:
level - the level to check
Returns:
true if multiple relational columns are involved in this level

isLevelCollapsed

protected boolean isLevelCollapsed(AggStar aggStar,
                                   RolapCubeLevel level)
Determine if the given aggregate table has the dimension level specified within in (AggStar.FactTable) it, aka collapsed, or associated with foreign keys (AggStar.DimTable)

Parameters:
aggStar - aggregate star if exists
level - level
Returns:
true if agg table has level or not

chooseAggStar

AggStar chooseAggStar(Evaluator evaluator)
Obtains the AggStar instance which corresponds to an aggregate table which can be used to support the member constraint.

Parameters:
evaluator - the current evaluator to obtain the cube and members to be queried
Returns:
AggStar for aggregate table

getMaxRows

int getMaxRows()

setMaxRows

void setMaxRows(int maxRows)

Get Mondrian at SourceForge.net. Fast, secure and free Open Source software downloads