Fennel: /home/pub/open/dev/fennel/btree/BTreeReader.h Source File (original) (raw)

00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 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