001/*
002// This software is subject to the terms of the Eclipse Public License v1.0
003// Agreement, available at the following URL:
004// http://www.eclipse.org/legal/epl-v10.html.
005// You must accept the terms of that agreement to use this software.
006//
007// Copyright (C) 2004-2005 TONBELLER AG
008// Copyright (C) 2006-2012 Pentaho and others
009// All Rights Reserved.
010*/
011package mondrian.rolap.sql;
012
013import mondrian.olap.Evaluator;
014import mondrian.rolap.*;
015import mondrian.rolap.aggmatcher.AggStar;
016
017/**
018 * Restricts the SQL result of {@link mondrian.rolap.TupleReader}. This is also
019 * used by
020 * {@link SqlMemberSource#getMembersInLevel(RolapLevel, TupleConstraint)}.
021 *
022 * @see mondrian.rolap.TupleReader
023 * @see mondrian.rolap.SqlMemberSource
024 *
025 * @author av
026 */
027public interface TupleConstraint extends SqlConstraint {
028    /**
029     * Modifies a Level.Members query.
030     *
031     * @param sqlQuery the query to modify
032     * @param aggStar aggregate star to use
033     * @param baseCube base cube for virtual cube constraints
034     */
035    public void addConstraint(
036        SqlQuery sqlQuery,
037        RolapCube baseCube,
038        AggStar aggStar);
039
040    /**
041     * Will be called multiple times for every "group by" level in
042     * Level.Members query, i.e. the level that contains the members and all
043     * parent levels except All.
044     * If the condition requires so,
045     * it may join the levels table to the fact table.
046     *
047     * @param sqlQuery the query to modify
048     * @param baseCube base cube for virtual cube constraints
049     * @param aggStar Aggregate table, or null if query is against fact table
050     * @param level the level which is accessed in the Level.Members query
051     */
052    public void addLevelConstraint(
053        SqlQuery sqlQuery,
054        RolapCube baseCube,
055        AggStar aggStar,
056        RolapLevel level);
057
058    /**
059     * When the members of a level are fetched, the result is grouped
060     * by into parents and their children. These parent/children are
061     * stored in the parent/children cache, whose key consists of the parent
062     * and the MemberChildrenConstraint#hashKey(). So we need a matching
063     * MemberChildrenConstraint to store the parent with its children into
064     * the parent/children cache.
065     *
066     * <p>The returned MemberChildrenConstraint must be one that would have
067     * returned the same children for the given parent as the MemberLevel query
068     * has found for that parent.
069     *
070     * <p>If null is returned, the parent/children will not be cached (but the
071     * level/members still will be).
072     */
073    MemberChildrenConstraint getMemberChildrenConstraint(RolapMember parent);
074
075    /**
076     * @return the evaluator currently associated with the constraint; null
077     * if there is no associated evaluator
078     */
079    public Evaluator getEvaluator();
080}
081
082// End TupleConstraint.java