Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

317 lines
8.7 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994.
  5. //
  6. // File: tputget.hxx
  7. //
  8. // Contents: Classes to add, retrieve and locate rows in the large table.
  9. //
  10. // Classes: CTableRowPutter, CTableRowGetter, CTableRowLocator
  11. //
  12. // Functions:
  13. //
  14. // History: 4-17-95 srikants Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #pragma once
  18. #include <bigtable.hxx>
  19. class CTableWindow;
  20. class CTableBucket;
  21. //+---------------------------------------------------------------------------
  22. //
  23. // Class: CTableRowPutter
  24. //
  25. // Purpose: A class to add a row to the large table.
  26. //
  27. // History: 4-17-95 srikants Created
  28. //
  29. //----------------------------------------------------------------------------
  30. class CTableRowPutter
  31. {
  32. public:
  33. CTableRowPutter( CLargeTable & largeTable, CRetriever & obj ) :
  34. _largeTable(largeTable),
  35. _segListMgr(largeTable._GetSegListMgr()),
  36. _segList(_segListMgr.GetList()),
  37. _comparator(largeTable._keyCompare.GetReference()),
  38. _currRow(largeTable._currRow.GetReference()),
  39. _obj(obj),
  40. _fNewWindowCreated(FALSE)
  41. {
  42. _currRow.PreSet( & _obj, & _largeTable._vtInfoSortKey );
  43. }
  44. CTableSegment * LokFindSegToInsert( CTableSegment * pSegHint = 0 );
  45. CTableSegment * LokSplitOrAddSegment( CTableSegment * pSegment );
  46. BOOL LokIsNewWindowCreated() const { return _fNewWindowCreated; }
  47. private:
  48. //
  49. // LargeTable and the segment list manager references.
  50. //
  51. CLargeTable & _largeTable;
  52. CSegListMgr & _segListMgr;
  53. CTableSegList & _segList;
  54. CTableKeyCompare & _comparator;
  55. CTableRowKey & _currRow;
  56. CRetriever & _obj;
  57. //
  58. // Flag set to TRUE if a new window was created and added to the
  59. // table before adding the row.
  60. //
  61. BOOL _fNewWindowCreated;
  62. //
  63. // Result of comparison with the current segment. Used to locate
  64. // the segment into which the row must be inserted.
  65. //
  66. CCompareResult _cmpCurr;
  67. CTableSegment * _IsHintGood( CTableSegment * pSegHint );
  68. BOOL _LokShouldUseNext( int icmp, CTableSegment * pSeg );
  69. };
  70. class CRegionTransformer;
  71. //+---------------------------------------------------------------------------
  72. //
  73. // Class: CTableRowLocator
  74. //
  75. // Purpose: A class to locate a requested row in the large table.
  76. //
  77. // History: 4-19-95 srikants Created
  78. //
  79. //----------------------------------------------------------------------------
  80. class CTableRowLocator
  81. {
  82. public:
  83. CTableRowLocator( CLargeTable & largeTable, WORKID widStart,
  84. LONG iRowOffset, CI_TBL_CHAPT chapt )
  85. : _largeTable(largeTable),
  86. _segListMgr(largeTable._GetSegListMgr()),
  87. _segList(_segListMgr.GetList()),
  88. _widStart(widStart),
  89. _iRowOffset( iRowOffset ),
  90. _widFound(widInvalid),
  91. _cRowsBeyond(0),
  92. _chapt(chapt)
  93. {
  94. }
  95. SCODE LokLocate( HWATCHREGION hRegion,
  96. BOOL fAsync,
  97. CDoubleTableSegIter & iter,
  98. CRegionTransformer & transformer );
  99. void LokRelocate( BOOL fAsync, CDoubleTableSegIter & iter,
  100. CRegionTransformer & transformer,
  101. XPtr<CTableBucket> & xBktToExplode,
  102. CDynStack<CTableBucket> & xBktToConvert );
  103. void LokSimulateFetch( CDoubleTableSegIter & iter,
  104. CRegionTransformer & transformer,
  105. CDynStack<CTableBucket> & xBktToConvert );
  106. void SetLocateInfo( WORKID widStart, LONG iRowOffset )
  107. {
  108. _widStart = widStart;
  109. _iRowOffset = iRowOffset;
  110. }
  111. WORKID GetWorkIdFound() const { return _widFound; }
  112. void SeekAndSetFetchBmk( WORKID wid, CDoubleTableSegIter & iter );
  113. DBROWCOUNT GetBeyondTableCount() const { return _cRowsBeyond; }
  114. BOOL IsOffsetFound( CDoubleTableSegIter & iter, DBROWCOUNT offset );
  115. private:
  116. //
  117. // LargeTable and the segment list manager references.
  118. //
  119. CLargeTable & _largeTable;
  120. CSegListMgr & _segListMgr;
  121. CTableSegList & _segList;
  122. //
  123. // The parameters for the search.
  124. //
  125. WORKID _widStart;
  126. LONG _iRowOffset;
  127. CI_TBL_CHAPT _chapt;
  128. //
  129. // Results of a locate.
  130. //
  131. WORKID _widFound;
  132. DBROWCOUNT _cRowsBeyond;
  133. void _RelocateThruBuckets( BOOL fAsync, CDoubleTableSegIter & iter ,
  134. CRegionTransformer & transformer,
  135. XPtr<CTableBucket> & xBktToExplode );
  136. };
  137. //+---------------------------------------------------------------------------
  138. //
  139. // Member: CTableRowLocator::IsOffsetFound
  140. //
  141. // Synopsis: Determines whether the current segment in the iterator has
  142. // the row indicated by the _cRowsResidual or not, ie, does the
  143. // current segment in the iterator has the requested row or
  144. // not.
  145. //
  146. // Arguments: [iter] - The iterator on the segment list.
  147. //
  148. // Returns: TRUE if the requested row is located.
  149. // FALSE o/w.
  150. //
  151. // History: 7-26-95 srikants Created
  152. //
  153. // Notes:
  154. //
  155. //----------------------------------------------------------------------------
  156. inline BOOL CTableRowLocator::IsOffsetFound(
  157. CDoubleTableSegIter& iter,
  158. DBROWCOUNT offset )
  159. {
  160. Win4Assert( offset >= 0 );
  161. return !_segList.AtEnd(iter) &&
  162. offset < (DBROWCOUNT) iter.GetSegment()->RowCount();
  163. }
  164. //+---------------------------------------------------------------------------
  165. //
  166. // Class: CTableRowGetter
  167. //
  168. // Purpose: A class to fetch rows from the table.
  169. //
  170. // History: 4-19-95 srikants Created
  171. //
  172. // Notes:
  173. //
  174. //----------------------------------------------------------------------------
  175. class CTableRowGetter
  176. {
  177. public:
  178. CTableRowGetter( CLargeTable & largeTable,
  179. CTableColumnSet const & outColumns,
  180. CGetRowsParams & getParams,
  181. CI_TBL_CHAPT chapt,
  182. HWATCHREGION hRegion);
  183. SCODE LokGetRowsAtSegment( CTableSegment * pStartSeg,
  184. WORKID widStart,
  185. BOOL fAsync,
  186. XPtr<CTableBucket> & xBktToExplode );
  187. CTableBucket * LokGetBucketToExpand() { return _pBucketToExpand; }
  188. void ClearBucketToExpand() { _pBucketToExpand = 0; }
  189. WORKID GetLastWorkId() const { return _widLastTransferred; }
  190. BOOL IsDone() const { return 0 == _pBucketToExpand; }
  191. void SetRowsToTransfer( ULONG cRowsToTransfer );
  192. long GetRowsToTransfer() const { return (long) _cRowsToTransfer; }
  193. void DecrementRowsToTransfer( ULONG cDiff )
  194. {
  195. if ( cDiff < _cRowsToTransfer )
  196. {
  197. _cRowsToTransfer -= cDiff;
  198. }
  199. else
  200. {
  201. _cRowsToTransfer = 0;
  202. }
  203. }
  204. private:
  205. //
  206. // Large table and the segment list management members.
  207. //
  208. CLargeTable & _largeTable;
  209. CSegListMgr & _segListMgr;
  210. CTableSegList & _segList;
  211. //
  212. // Input and output parameters to the GetRows call.
  213. //
  214. CTableColumnSet const & _outColumns;
  215. CGetRowsParams & _getParams;
  216. CI_TBL_CHAPT _chapt;
  217. HWATCHREGION _hRegion;
  218. //
  219. // MAX Number of rows to be transferred
  220. //
  221. ULONG _cRowsToTransfer;
  222. //
  223. // The bucket that must be converted into a window before any more
  224. // rows can be retrieved.
  225. //
  226. CTableBucket * _pBucketToExpand;
  227. //
  228. // The workid that was transferred last.
  229. //
  230. WORKID _widLastTransferred;
  231. //
  232. // State information used during retrieval of rows.
  233. //
  234. WORKID _widStart;
  235. ULONG _cBktRowsToExpand;
  236. SCODE _status;
  237. BOOL _fAsync;
  238. void _Reset()
  239. {
  240. _pBucketToExpand = 0;
  241. }
  242. void _InitForGetRows( WORKID widStart, BOOL fAsync )
  243. {
  244. _widStart = widStart;
  245. _cBktRowsToExpand = _cRowsToTransfer;
  246. _status = S_OK;
  247. _fAsync = fAsync;
  248. _pBucketToExpand = 0;
  249. }
  250. BOOL _GetRowsFromWindow( CDoubleTableSegIter & iter );
  251. BOOL _ProcessBucket( CDoubleTableSegIter & iter,
  252. XPtr<CTableBucket> & xBktToExplode );
  253. };