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) 2012-2012 Pentaho 008// All Rights Reserved. 009*/ 010package mondrian.rolap.sql; 011 012import mondrian.olap.Evaluator; 013import mondrian.olap.MondrianDef; 014import mondrian.rolap.*; 015import mondrian.rolap.aggmatcher.AggStar; 016import mondrian.spi.Dialect; 017import mondrian.util.Pair; 018 019import java.util.List; 020 021/** 022 * Restricts the SQL result set to members where particular columns have 023 * particular values. 024 * 025 * @version $Id$ 026 */ 027public class MemberKeyConstraint 028 implements TupleConstraint 029{ 030 private final Pair<List<MondrianDef.Expression>, List<Comparable>> cacheKey; 031 private final List<MondrianDef.Expression> columnList; 032 private final List<Dialect.Datatype> datatypeList; 033 private final List<Comparable> valueList; 034 035 public MemberKeyConstraint( 036 List<MondrianDef.Expression> columnList, 037 List<Dialect.Datatype> datatypeList, 038 List<Comparable> valueList) 039 { 040 this.columnList = columnList; 041 this.datatypeList = datatypeList; 042 this.valueList = valueList; 043 cacheKey = Pair.of(columnList, valueList); 044 } 045 046 public void addConstraint( 047 SqlQuery sqlQuery, RolapCube baseCube, AggStar aggStar) 048 { 049 for (int i = 0; i < columnList.size(); i++) { 050 MondrianDef.Expression expression = columnList.get(i); 051 final Comparable value = valueList.get(i); 052 final Dialect.Datatype datatype = datatypeList.get(i); 053 sqlQuery.addWhere( 054 SqlConstraintUtils.constrainLevel2( 055 sqlQuery, 056 expression, 057 datatype, 058 value)); 059 } 060 } 061 062 public void addLevelConstraint( 063 SqlQuery sqlQuery, 064 RolapCube baseCube, 065 AggStar aggStar, 066 RolapLevel level) 067 { 068 } 069 070 public MemberChildrenConstraint getMemberChildrenConstraint( 071 RolapMember parent) 072 { 073 return null; 074 } 075 076 public String toString() { 077 return "MemberKeyConstraint"; 078 } 079 080 081 public Object getCacheKey() { 082 return cacheKey; 083 } 084 085 public Evaluator getEvaluator() { 086 return null; 087 } 088} 089 090// End MemberKeyConstraint.java