001    /*
002    // This software is subject to the terms of the Common Public License
003    // Agreement, available at the following URL:
004    // http://www.opensource.org/licenses/cpl.html.
005    // Copyright (C) 2004-2005 TONBELLER AG
006    // Copyright (C) 2006-2007 Julian Hyde
007    // All Rights Reserved.
008    // You must accept the terms of that agreement to use this software.
009    */
010    package mondrian.rolap;
011    
012    import java.util.Arrays;
013    
014    import mondrian.olap.Id;
015    import mondrian.rolap.sql.SqlQuery;
016    import mondrian.rolap.aggmatcher.AggStar;
017    
018    /**
019     * Constraint which optimizes the search for a child by name. This is used
020     * whenever the string representation of a member is parsed, e.g.
021     * [Customers].[All Customers].[USA].[CA]. Restricts the result to
022     * the member we are searching for.
023     *
024     * @author avix
025     * @version $Id: //open/mondrian/src/main/mondrian/rolap/ChildByNameConstraint.java#17 $
026     */
027    class ChildByNameConstraint extends DefaultMemberChildrenConstraint {
028        String childName;
029        Object cacheKey;
030    
031        /**
032         * Creates a <code>ChildByNameConstraint</code>.
033         *
034         * @param childName Name of child
035         */
036        public ChildByNameConstraint(Id.Segment childName) {
037            this.childName = childName.name;
038            this.cacheKey = Arrays.asList(
039                    new Object[] {
040                        super.getCacheKey(),
041                        ChildByNameConstraint.class, childName});
042        }
043    
044        public void addLevelConstraint(
045            SqlQuery query,
046            RolapCube baseCube,
047            AggStar aggStar,
048            RolapLevel level)
049        {
050            super.addLevelConstraint(query, baseCube, aggStar, level);
051            query.addWhere(
052                SqlConstraintUtils.constrainLevel(level, query, baseCube, childName, true));
053        }
054    
055        public String toString() {
056            return "ChildByNameConstraint(" + childName + ")";
057        }
058    
059        public Object getCacheKey() {
060            return cacheKey;
061        }
062    
063    }
064    
065    // End ChildByNameConstraint.java