KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > rolap > ChildByNameConstraint


1 /*
2 // This software is subject to the terms of the Common Public License
3 // Agreement, available at the following URL:
4 // http://www.opensource.org/licenses/cpl.html.
5 // Copyright (C) 2004-2005 TONBELLER AG
6 // Copyright (C) 2006-2006 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.Arrays JavaDoc;
13 import java.util.Map JavaDoc;
14
15 import mondrian.rolap.sql.SqlQuery;
16 import mondrian.rolap.aggmatcher.AggStar;
17
18 /**
19  * Constraint which optimizes the search for a child by name. This is used
20  * whenever the string representation of a member is parsed, e.g.
21  * [Customers].[All Customers].[USA].[CA]. Restricts the result to
22  * the member we are searching for.
23  *
24  * @author avix
25  * @version $Id: //open/mondrian/src/main/mondrian/rolap/ChildByNameConstraint.java#12 $
26  */

27 class ChildByNameConstraint extends DefaultMemberChildrenConstraint {
28     String JavaDoc childName;
29     Object JavaDoc cacheKey;
30
31     /**
32      * Creates a <code>ChildByNameConstraint</code>.
33      *
34      * @param childName Name of child
35      */

36     public ChildByNameConstraint(String JavaDoc childName) {
37         this.childName = childName;
38         this.cacheKey = Arrays.asList(
39                 new Object JavaDoc[] {
40                     super.getCacheKey(),
41                     ChildByNameConstraint.class, childName});
42     }
43
44     public void addLevelConstraint(
45         SqlQuery query,
46         AggStar aggStar,
47         RolapLevel level,
48         Map JavaDoc<RolapLevel, RolapStar.Column> levelToColumnMap)
49     {
50         super.addLevelConstraint(query, aggStar, level, levelToColumnMap);
51         query.addWhere(
52             SqlConstraintUtils.constrainLevel(
53                 level,
54                 query,
55                 childName,
56                 true));
57     }
58
59     public String JavaDoc toString() {
60         return "ChildByNameConstraint(" + childName + ")";
61     }
62
63     public Object JavaDoc getCacheKey() {
64         return cacheKey;
65     }
66
67 }
68
69 // End ChildByNameConstraint.java
70
Popular Tags