00001 /* 00002 // $Id: //open/dev/fennel/ftrs/BTreeExecStream.cpp#14 $ 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) 2004-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/ftrs/BTreeExecStream.h" 00026 #include "fennel/btree/BTreeWriter.h" 00027 00028 FENNEL_BEGIN_CPPFILE("$Id: //open/dev/fennel/ftrs/BTreeExecStream.cpp#14 $"); 00029 00030 void BTreeExecStream::prepare(BTreeExecStreamParams const ¶ms) 00031 { 00032 SingleOutputExecStream::prepare(params); 00033 00034 copyParamsToDescriptor(treeDescriptor,params,params.pCacheAccessor); 00035 scratchAccessor = params.scratchAccessor; 00036 pRootMap = params.pRootMap; 00037 rootPageIdParamId = params.rootPageIdParamId; 00038 } 00039 00040 void BTreeExecStream::open(bool restart) 00041 { 00042 SingleOutputExecStream::open(restart); 00043 if (restart) { 00044 endSearch(); 00045 } 00046 if (!restart) { 00047 if (pRootMap) { 00048 treeDescriptor.rootPageId = pRootMap->getRoot( 00049 treeDescriptor.pageOwnerId); 00050 if (pBTreeAccessBase) { 00051 pBTreeAccessBase->setRootPageId(treeDescriptor.rootPageId); 00052 } 00053 } 00054 } 00055 } 00056 00057 void BTreeExecStream::closeImpl() 00058 { 00059 endSearch(); 00060 if (pRootMap && pBTreeAccessBase) { 00061 treeDescriptor.rootPageId = NULL_PAGE_ID; 00062 pBTreeAccessBase->setRootPageId(NULL_PAGE_ID); 00063 } 00064 SingleOutputExecStream::closeImpl(); 00065 } 00066 00067 SharedBTreeReader BTreeExecStream::newReader() 00068 { 00069 SharedBTreeReader pReader = SharedBTreeReader( 00070 new BTreeReader(treeDescriptor)); 00071 pBTreeAccessBase = pBTreeReader = pReader; 00072 return pReader; 00073 } 00074 00075 SharedBTreeWriter BTreeExecStream::newWriter(bool monotonic) 00076 { 00077 SharedBTreeWriter pWriter = SharedBTreeWriter( 00078 new BTreeWriter(treeDescriptor,scratchAccessor,monotonic)); 00079 pBTreeAccessBase = pBTreeReader = pWriter; 00080 return pWriter; 00081 } 00082 00083 SharedBTreeWriter BTreeExecStream::newWriter( 00084 BTreeExecStreamParams const ¶ms) 00085 { 00086 BTreeDescriptor treeDescriptor; 00087 copyParamsToDescriptor(treeDescriptor,params,params.pCacheAccessor); 00088 return SharedBTreeWriter( 00089 new BTreeWriter( 00090 treeDescriptor,params.scratchAccessor)); 00091 } 00092 00093 void BTreeExecStream::copyParamsToDescriptor( 00094 BTreeDescriptor &treeDescriptor, 00095 BTreeParams const ¶ms, 00096 SharedCacheAccessor const &pCacheAccessor) 00097 { 00098 treeDescriptor.segmentAccessor.pSegment = params.pSegment; 00099 treeDescriptor.segmentAccessor.pCacheAccessor = pCacheAccessor; 00100 treeDescriptor.tupleDescriptor = params.tupleDesc; 00101 treeDescriptor.keyProjection = params.keyProj; 00102 treeDescriptor.rootPageId = params.rootPageId; 00103 treeDescriptor.segmentId = params.segmentId; 00104 treeDescriptor.pageOwnerId = params.pageOwnerId; 00105 } 00106 00107 void BTreeExecStream::endSearch() 00108 { 00109 if (pBTreeReader && pBTreeReader->isSingular() == false) { 00110 pBTreeReader->endSearch(); 00111 } 00112 } 00113 00114 BTreeExecStreamParams::BTreeExecStreamParams() 00115 { 00116 pRootMap = NULL; 00117 } 00118 00119 BTreeOwnerRootMap::~BTreeOwnerRootMap() 00120 { 00121 } 00122 00123 FENNEL_END_CPPFILE("$Id: //open/dev/fennel/ftrs/BTreeExecStream.cpp#14 $"); 00124 00125 // End BTreeExecStream.cpp