001    /*
002    // $Id: //open/mondrian/src/main/mondrian/rolap/MemberCache.java#14 $
003    // This software is subject to the terms of the Common Public License
004    // Agreement, available at the following URL:
005    // http://www.opensource.org/licenses/cpl.html.
006    // Copyright (C) 2001-2002 Kana Software, Inc.
007    // Copyright (C) 2001-2007 Julian Hyde and others
008    // All Rights Reserved.
009    // You must accept the terms of that agreement to use this software.
010    //
011    // jhyde, 22 December, 2001
012    */
013    
014    package mondrian.rolap;
015    
016    import java.util.List;
017    
018    import mondrian.rolap.sql.TupleConstraint;
019    import mondrian.rolap.sql.MemberChildrenConstraint;
020    
021    /**
022     * A <code>MemberCache</code> can retrieve members based upon their parent and
023     * name.
024     *
025     * @author jhyde
026     * @since 22 December, 2001
027     * @version $Id: //open/mondrian/src/main/mondrian/rolap/MemberCache.java#14 $
028     */
029    interface MemberCache {
030        /**
031         * Creates a key with which to {@link #getMember(Object)} or
032         * {@link #putMember(Object, RolapMember)} the
033         * {@link RolapMember} with a given parent and key.
034         *
035         * @param parent Parent member
036         * @param key Key of member within parent
037         * @return key with which to address this member in the cache
038         */
039        Object makeKey(RolapMember parent, Object key);
040    
041        /**
042         * Retrieves the {@link RolapMember} with a given key.
043         *
044         * @param key cache key, created by {@link #makeKey}
045         * @return member with a given cache key
046         */
047        RolapMember getMember(Object key);
048    
049        /**
050         * Retrieves the {@link RolapMember} with a given key.
051         *
052         * @param key cache key, created by {@link #makeKey}
053         * @param mustCheckCacheStatus If {@code true}, do not check cache status
054         * @return member with a given cache key
055         */
056        RolapMember getMember(Object key, boolean mustCheckCacheStatus);
057    
058        /**
059         * Replaces the {@link RolapMember} with a given key and returns the
060         * previous member if any.
061         *
062         * @param key cache key, created by {@link #makeKey}
063         * @param member new member
064         * @return Previous member with that key, or null.
065         */
066        Object putMember(Object key, RolapMember member);
067    
068        /**
069         * Returns whether the cache supports removing selected items. If it does,
070         * it is valid to call the {@link #removeMember(Object)} and
071         * {@link #removeMemberAndDescendants(Object)} methods.
072         *
073         * <p>REVIEW: remove isMutable and move removeMember and
074         * removeMemberAndDescendants to new interface MutableMemberCache
075         *
076         * @return true if the cache supports removing selected items.
077         */
078        boolean isMutable();
079    
080        /**
081         * Removes the {@link RolapMember} with a given key from the cache.
082         * Returns the previous member with that key, or null.
083         * Optional operation: see {@link #isMutable}.
084         *
085         * @param key cache key, created by {@link #makeKey}
086         * @return previous member with that key, or null
087         */
088        RolapMember removeMember(Object key);
089    
090        /**
091         * Removes the designated {@link RolapMember} and all its descendants.
092         * Returns the previous member with that key, or null.
093         * Optional operation: see {@link #isMutable}.
094         *
095         * @param key cache key, created by {@link #makeKey}
096         * @return previous member with that key, or null
097         */
098        RolapMember removeMemberAndDescendants(Object key);
099    
100        /**
101         * Returns the children of <code>member</code> if they are currently in the
102         * cache, otherwise returns null.
103         *
104         * <p>The children may be garbage collected as
105         * soon as the returned list may be garbage collected.</p>
106         *
107         * @param parent the parent member
108         * @param constraint the condition that was used when the members were
109         *    fetched. May be null for all members (no constraint)
110         * @return list of children, or null if not in cache
111         */
112        List<RolapMember> getChildrenFromCache(
113            RolapMember parent,
114            MemberChildrenConstraint constraint);
115    
116        /**
117         * Returns the members of <code>level</code> if they are currently in the
118         * cache, otherwise returns null.
119         *
120         * <p>The members may be garbage collected as soon as the
121         * returned list may be garbage collected.</p>
122         *
123         * @param level the level whose members should be fetched
124         * @param constraint the condition that was used when the members were
125         *   fetched. May be null for all members (no constraint)
126         * @return members of level, or null if not in cache
127         */
128        List<RolapMember> getLevelMembersFromCache(
129            RolapLevel level,
130            TupleConstraint constraint);
131    
132        /**
133         * Registers that the children of <code>member</code> are
134         * <code>children</code> (a list of {@link RolapMember}s).
135         *
136         * @param member the parent member
137         * @param constraint the condition that was used when the members were
138         *   fetched. May be null for all members (no constraint)
139         * @param children list of children
140         */
141        void putChildren(
142            RolapMember member,
143            MemberChildrenConstraint constraint,
144            List<RolapMember> children);
145    }
146    
147    
148    // End MemberCache.java