BTreeReader.h

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/btree/BTreeReader.h#19 $
00003 // Fennel is a library of data storage and processing components.
00004 // Copyright (C) 2005-2009 The Eigenbase Project
00005 // Copyright (C) 2005-2009 SQLstream, Inc.
00006 // Copyright (C) 2005-2009 LucidEra, Inc.
00007 // Portions Copyright (C) 1999-2009 John V. Sichi
00008 //
00009 // This program is free software; you can redistribute it and/or modify it
00010 // under the terms of the GNU General Public License as published by the Free
00011 // Software Foundation; either version 2 of the License, or (at your option)
00012 // any later version approved by The Eigenbase Project.
00013 //
00014 // This program is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with this program; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 */
00023 
00024 #ifndef Fennel_BTreeReader_Included
00025 #define Fennel_BTreeReader_Included
00026 
00027 #include "fennel/btree/BTreeAccessBase.h"
00028 #include "fennel/btree/BTreeNode.h"
00029 #include "fennel/tuple/TupleData.h"
00030 
00031 FENNEL_BEGIN_NAMESPACE
00032 
00036 class FENNEL_BTREE_EXPORT BTreeReader
00037     : public BTreeAccessBase
00038 {
00039 protected:
00043     enum ReadMode {
00047         READ_ALL,
00051         READ_NONLEAF_ONLY,
00055         READ_LEAF_ONLY
00056     };
00057 
00062     class NullPageStack
00063     {
00064     public:
00065         void push_back(PageId)
00066         {
00067         }
00068     };
00069 
00070     inline void accessLeafTuple();
00071 
00075     BTreePageLock pageLock;
00076 
00080     PageId pageId;
00081 
00085     uint iTupleOnLowestLevel;
00086 
00090     bool singular;
00091 
00095     LockMode rootLockMode;
00096 
00101     LockMode nonLeafLockMode;
00102 
00106     LockMode leafLockMode;
00107 
00111     TupleData comparisonKeyData;
00112 
00116     TupleData const *pSearchKey;
00117 
00121     TupleData searchKeyData;
00122 
00138     inline uint binarySearch(
00139         BTreeNode const &node, DuplicateSeek dupSeek, bool leastUpper,
00140         bool &found);
00141 
00145     inline TupleData const &getSearchKey();
00146 
00158     inline bool adjustRootLockMode(LockMode &lockMode);
00159 
00167     inline int compareFirstKey(BTreeNode const &node);
00168 
00176     inline void accessTupleInline(BTreeNode const &node, uint iEntry);
00177 
00203     template <bool leafLockCoupling,class PageStack>
00204     inline bool searchForKeyTemplate(
00205         TupleData const &key, DuplicateSeek dupSeek, bool leastUpper,
00206         PageStack &pageStack, PageId startPageId, LockMode initialLockMode,
00207         ReadMode readMode);
00208 
00212     bool searchForKeyInternal(
00213         TupleData const &key, DuplicateSeek dupSeek, bool leastUpper,
00214         PageId startPageId, LockMode initialLockMode,
00215         ReadMode readMode);
00216 
00224     virtual bool searchExtreme(bool first);
00225 
00235     bool searchExtremeInternal(bool first, ReadMode readMode);
00236 
00242     bool searchNextInternal();
00243 
00244 public:
00245     explicit BTreeReader(BTreeDescriptor const &descriptor);
00246     virtual ~BTreeReader();
00247 
00254     TupleAccessor const &getTupleAccessorForRead() const;
00255 
00263     inline TupleData &getSearchKeyForWrite();
00264 
00270     inline bool searchFirst();
00271 
00287     inline bool searchLast();
00288 
00311     virtual bool searchForKey(
00312         TupleData const &key,
00313         DuplicateSeek dupSeek,
00314         bool leastUpper = true);
00315 
00322     virtual bool searchNext();
00323 
00327     virtual void endSearch();
00328 
00333     inline bool isPositioned() const;
00334 
00339     inline bool isSingular() const;
00340 };
00341 
00342 inline TupleData &BTreeReader::getSearchKeyForWrite()
00343 {
00344     return searchKeyData;
00345 }
00346 
00347 inline bool BTreeReader::isSingular() const
00348 {
00349     return singular;
00350 }
00351 
00352 inline bool BTreeReader::isPositioned() const
00353 {
00354     return pageLock.isLocked();
00355 }
00356 
00357 inline bool BTreeReader::searchFirst()
00358 {
00359     return searchExtreme(true);
00360 }
00361 
00362 inline bool BTreeReader::searchLast()
00363 {
00364     return searchExtreme(false);
00365 }
00366 
00367 FENNEL_END_NAMESPACE
00368 
00369 #endif
00370 
00371 // End BTreeReader.h

Generated on Mon Jun 22 04:00:13 2009 for Fennel by  doxygen 1.5.1