KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > rolap > RolapCacheRegion


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/rolap/RolapCacheRegion.java#1 $
3 // This software is subject to the terms of the Common Public License
4 // Agreement, available at the following URL:
5 // http://www.opensource.org/licenses/cpl.html.
6 // Copyright (C) 2007-2007 Julian Hyde
7 // All Rights Reserved.
8 // You must accept the terms of that agreement to use this software.
9 */

10 package mondrian.rolap;
11
12 import java.util.*;
13
14 /**
15  * A <code>RolapCacheRegion</code> represents a region of multidimensional space
16  * in the cache.
17  *
18  * <p>The region is represented in terms of the columns of a given
19  * {@link mondrian.rolap.RolapStar}, and constraints on those columns.
20  *
21  * <p>Compare with {@link mondrian.olap.CacheControl.CellRegion}: a
22  * <code>CellRegion</code> is in terms of {@link mondrian.olap.Member} objects
23  * (logical); whereas a <code>RolapCacheRegion</code> is in terms of columns
24  * (physical).
25  */

26 public class RolapCacheRegion {
27     private final BitKey bitKey;
28     private final Map<Integer JavaDoc, StarColumnPredicate> columnPredicates =
29         new HashMap<Integer JavaDoc, StarColumnPredicate>();
30     private Map<List<RolapStar.Column>, StarPredicate> predicates =
31         new HashMap<List<RolapStar.Column>, StarPredicate>();
32
33     public RolapCacheRegion(RolapStar star, List<RolapStar.Measure> starMeasureList) {
34         bitKey = BitKey.Factory.makeBitKey(star.getColumnCount());
35         for (RolapStar.Measure measure : starMeasureList) {
36             bitKey.set(measure.getBitPosition());
37         }
38     }
39
40     public BitKey getConstrainedColumnsBitKey() {
41         return bitKey;
42     }
43
44     /**
45      * Adds a predicate which applies to a single column.
46      *
47      * @param column Constrained column
48      * @param predicate Predicate
49      */

50     public void addPredicate(
51         RolapStar.Column column,
52         StarColumnPredicate predicate)
53     {
54         int bitPosition = column.getBitPosition();
55         assert !bitKey.get(bitPosition);
56         bitKey.set(bitPosition);
57         columnPredicates.put(bitPosition, predicate);
58     }
59
60     /**
61      * Returns the predicate associated with the
62      * <code>columnOrdinal</code>th column.
63      *
64      * @param columnOrdinal Column ordinal
65      * @return Predicate, or null if not constrained
66      */

67     public StarColumnPredicate getPredicate(int columnOrdinal) {
68         return columnPredicates.get(columnOrdinal);
69     }
70
71     /**
72      * Adds a predicate which applies to multiple columns.
73      *
74      * <p>The typical example of a multi-column predicate is a member
75      * constraint. For example, the constraint "m between 1997.Q3 and
76      * 1998.Q2" translates into "year = 1997 and quarter >= Q3 or year =
77      * 1998 and quarter <= Q2".
78      *
79      * @param predicate Predicate
80      */

81     public void addPredicate(StarPredicate predicate)
82     {
83         final List<RolapStar.Column> columnList =
84             predicate.getConstrainedColumnList();
85         predicates.put(
86             new ArrayList<RolapStar.Column>(columnList),
87             predicate);
88         for (RolapStar.Column column : columnList) {
89             bitKey.set(column.getBitPosition());
90         }
91     }
92
93     /**
94      * Returns a collection of all multi-column predicates.
95      *
96      * @return Collection of all multi-column constraints
97      */

98     public Collection<StarPredicate> getPredicates() {
99         return predicates.values();
100     }
101 }
102
103 // End RolapCacheRegion.java
104
Popular Tags