00001 /* 00002 // $Id: //open/dev/fennel/btree/BTreeLeafReader.cpp#3 $ 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 #include "fennel/common/CommonPreamble.h" 00025 #include "fennel/btree/BTreeLeafReader.h" 00026 #include "fennel/btree/BTreeAccessBaseImpl.h" 00027 #include "fennel/btree/BTreeReaderImpl.h" 00028 00029 FENNEL_BEGIN_CPPFILE("$Id: //open/dev/fennel/btree/BTreeLeafReader.cpp#3 $"); 00030 00031 BTreeLeafReader::BTreeLeafReader(BTreeDescriptor const &descriptor) 00032 : BTreeReader(descriptor) 00033 { 00034 currLeafPageId = NULL_PAGE_ID; 00035 } 00036 00037 bool BTreeLeafReader::adjustRootLockMode(LockMode &lockMode) 00038 { 00039 assert(lockMode == leafLockMode); 00040 return true; 00041 } 00042 00043 bool BTreeLeafReader::searchExtreme(bool first) 00044 { 00045 assert(currLeafPageId != NULL_PAGE_ID); 00046 pageLock.lockPage(currLeafPageId, leafLockMode); 00047 BTreeNode const &node = pageLock.getNodeForRead(); 00048 if (node.nEntries == 0) { 00049 singular = true; 00050 return false; 00051 } 00052 singular = false; 00053 if (first) { 00054 iTupleOnLowestLevel = 0; 00055 } else { 00056 iTupleOnLowestLevel = node.nEntries - 1; 00057 } 00058 accessLeafTuple(); 00059 return true; 00060 } 00061 00062 bool BTreeLeafReader::searchForKey( 00063 TupleData const &key, 00064 DuplicateSeek dupSeek, 00065 bool leastUpper) 00066 { 00067 assert(currLeafPageId != NULL_PAGE_ID); 00068 return 00069 searchForKeyInternal( 00070 key, dupSeek, leastUpper, currLeafPageId, leafLockMode, 00071 READ_LEAF_ONLY); 00072 } 00073 00074 bool BTreeLeafReader::searchNext() 00075 { 00076 assert(currLeafPageId != NULL_PAGE_ID); 00077 assert(!singular); 00078 assert(pageLock.isLocked()); 00079 assert(!pageLock.getNodeForRead().height); 00080 ++iTupleOnLowestLevel; 00081 BTreeNode const &node = pageLock.getNodeForRead(); 00082 if (iTupleOnLowestLevel < node.nEntries) { 00083 accessLeafTuple(); 00084 return true; 00085 } else { 00086 // might as well preserve position 00087 --iTupleOnLowestLevel; 00088 singular = true; 00089 return false; 00090 } 00091 } 00092 00093 void BTreeLeafReader::endSearch() 00094 { 00095 BTreeReader::endSearch(); 00096 currLeafPageId = NULL_PAGE_ID; 00097 } 00098 00099 void BTreeLeafReader::setCurrentPageId(PageId pageId) 00100 { 00101 currLeafPageId = pageId; 00102 } 00103 00104 FENNEL_END_CPPFILE("$Id: //open/dev/fennel/btree/BTreeLeafReader.cpp#3 $"); 00105 00106 // End BTreeLeafReader.cpp