Source code of Windows XP (NT5)
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.

400 lines
12 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1995-1995, Microsoft Corporation.
  4. //
  5. // File: rowseek.hxx
  6. //
  7. // Contents: Declarations of classes for row seek descriptions,
  8. // used with the IRowset implementations.
  9. //
  10. // Classes: CRowSeekDescription - base class
  11. // CRowSeekNext - for GetNextRows
  12. // CRowSeekAt - for GetRowsAt
  13. // CRowSeekAtRatio - for GetRowsAtRatio
  14. // CRowSeekByBookmark - for GetRowsByBookmark
  15. // CRowSeekByValues - for GetRowsByValues (maybe someday)
  16. //
  17. // History: 03 Apr 1995 AlanW Created
  18. //
  19. //----------------------------------------------------------------------------
  20. #pragma once
  21. #include <bigtable.hxx>
  22. //+-------------------------------------------------------------------------
  23. //
  24. // Class: CRowSeekDescription
  25. //
  26. // Purpose: Describes row positioning operation for a GetRows call
  27. //
  28. // Notes: This is a base class for one of several derived classes
  29. // that give row positioning parameters for various types of
  30. // GetRows operations.
  31. //
  32. //--------------------------------------------------------------------------
  33. enum RowSeekMethod
  34. {
  35. eRowSeekNull = 0,
  36. eRowSeekCurrent = 1,
  37. eRowSeekAt = 2,
  38. eRowSeekAtRatio = 3,
  39. eRowSeekByBookmark = 4,
  40. };
  41. class CRowSeekDescription
  42. {
  43. public:
  44. CRowSeekDescription( DWORD eType, CI_TBL_CHAPT chapt )
  45. : _chapt( chapt )
  46. { }
  47. virtual ~CRowSeekDescription( ) { }
  48. virtual void Marshall( PSerStream & stm ) const = 0;
  49. virtual unsigned MarshalledSize( void ) const;
  50. virtual BOOL IsCurrentRowSeek(void) const { return FALSE; }
  51. virtual BOOL IsByBmkRowSeek(void) const { return FALSE; }
  52. virtual SCODE GetRows(
  53. CTableCursor & rCursor,
  54. CTableSource & rTable,
  55. CGetRowsParams& rFetchParams,
  56. XPtr<CRowSeekDescription>& pSeekDescOut) const = 0;
  57. virtual void MergeResults( CRowSeekDescription * pRowSeek );
  58. virtual BOOL IsDone(void) const
  59. {
  60. return FALSE;
  61. }
  62. CI_TBL_CHAPT GetChapter() const { return _chapt; }
  63. protected:
  64. void MarshallBase( PSerStream & stm, DWORD eType ) const;
  65. void SetChapter(CI_TBL_CHAPT Chapter)
  66. {
  67. _chapt = Chapter;
  68. }
  69. private:
  70. CI_TBL_CHAPT _chapt;
  71. };
  72. //+-------------------------------------------------------------------------
  73. //
  74. // Class: CRowSeekNext
  75. //
  76. // Purpose: Describes row positioning operation for a GetNextRows call.
  77. // The only parameter is the number of rows to be skipped prior
  78. // to the transfer operation.
  79. //
  80. //--------------------------------------------------------------------------
  81. class CRowSeekNext: public CRowSeekDescription
  82. {
  83. public:
  84. CRowSeekNext( CI_TBL_CHAPT chapt,
  85. LONG cRowsToSkip )
  86. : CRowSeekDescription( eRowSeekCurrent, chapt )
  87. {
  88. SetSkip( cRowsToSkip );
  89. }
  90. CRowSeekNext( PDeSerStream & stm, int iVersion );
  91. BOOL IsCurrentRowSeek(void) const
  92. {
  93. return TRUE;
  94. }
  95. void Marshall( PSerStream & stm ) const;
  96. SCODE GetRows( CTableCursor & rCursor,
  97. CTableSource & rTable,
  98. CGetRowsParams& rFetchParams,
  99. XPtr<CRowSeekDescription>& pSeekDescOut) const;
  100. LONG GetSkip() const
  101. {
  102. return _cSkip;
  103. }
  104. void SetSkip(LONG cRowsToSkip)
  105. {
  106. _cSkip = cRowsToSkip;
  107. }
  108. private:
  109. LONG _cSkip; // rows to skip
  110. };
  111. //+-------------------------------------------------------------------------
  112. //
  113. // Class: CRowSeekAt
  114. //
  115. // Purpose: Describes row positioning operation for a GetRowsAt call.
  116. // The parameters are the bookmark for the desired position,
  117. // and the offset from that position.
  118. //
  119. //--------------------------------------------------------------------------
  120. class CRowSeekAt: public CRowSeekDescription
  121. {
  122. public:
  123. CRowSeekAt( HWATCHREGION hRegion,
  124. CI_TBL_CHAPT chapt,
  125. LONG lRowOffset,
  126. CI_TBL_BMK bmk )
  127. : CRowSeekDescription( eRowSeekAt, chapt ),
  128. _hRegion (hRegion),
  129. _cRowsOffset ( lRowOffset ),
  130. _bmkOffset ( bmk )
  131. { }
  132. CRowSeekAt( PDeSerStream & stm, int iVersion );
  133. void Marshall( PSerStream & stm ) const;
  134. SCODE GetRows( CTableCursor & rCursor,
  135. CTableSource & rTable,
  136. CGetRowsParams& rFetchParams,
  137. XPtr<CRowSeekDescription>& pSeekDescOut) const;
  138. WORKID Bmk() const {
  139. return (WORKID)_bmkOffset;
  140. }
  141. LONG Offset() const {
  142. return _cRowsOffset;
  143. }
  144. private:
  145. HWATCHREGION _hRegion;
  146. LONG _cRowsOffset;
  147. CI_TBL_BMK _bmkOffset;
  148. };
  149. //+-------------------------------------------------------------------------
  150. //
  151. // Class: CRowSeekAtRatio
  152. //
  153. // Purpose: Describes row positioning operation for a GetRowsAtRatio
  154. // call. The parameters are the numerator and denominator
  155. // of the ratio. If this operation is restarted, the class
  156. // is transformed into a CRowSeekAt for the restart wid
  157. // and a skip of one.
  158. //
  159. //--------------------------------------------------------------------------
  160. class CRowSeekAtRatio: public CRowSeekDescription
  161. {
  162. public:
  163. CRowSeekAtRatio( HWATCHREGION hRegion,
  164. CI_TBL_CHAPT chapt,
  165. ULONG ulNum,
  166. ULONG ulDen )
  167. : CRowSeekDescription( eRowSeekAtRatio, chapt ),
  168. _hRegion (hRegion),
  169. _ulNumerator( ulNum ),
  170. _ulDenominator( ulDen )
  171. { }
  172. CRowSeekAtRatio( PDeSerStream & stm, int iVersion );
  173. void Marshall( PSerStream & stm ) const;
  174. SCODE GetRows( CTableCursor & rCursor,
  175. CTableSource & rTable,
  176. CGetRowsParams& rFetchParams,
  177. XPtr<CRowSeekDescription>& pSeekDescOut) const;
  178. ULONG RatioNumerator() const
  179. {
  180. return _ulNumerator;
  181. }
  182. ULONG RatioDenominator() const
  183. {
  184. return _ulDenominator;
  185. }
  186. private:
  187. HWATCHREGION _hRegion;
  188. ULONG _ulNumerator;
  189. ULONG _ulDenominator;
  190. };
  191. //+-------------------------------------------------------------------------
  192. //
  193. // Class: CRowSeekByBookmark
  194. //
  195. // Purpose: Describes row positioning operation for a GetRowsByBookmark
  196. // call. The parameter is an array of bookmarks.
  197. // This class also contains an array of SCODEs to record
  198. // the status of bookmark lookups.
  199. //
  200. //--------------------------------------------------------------------------
  201. class CRowSeekByBookmark: public CRowSeekDescription
  202. {
  203. public:
  204. //
  205. // NOTE: For this constructor, the CRowSeekDescription will now
  206. // own the memory pointed to by pBookmarks.
  207. CRowSeekByBookmark( CI_TBL_CHAPT chapt,
  208. ULONG cBookmarks,
  209. CI_TBL_BMK * pBookmarks = 0 )
  210. : CRowSeekDescription( eRowSeekByBookmark, chapt ),
  211. _cBookmarks ( cBookmarks ),
  212. _maxRet ( cBookmarks ),
  213. _aBookmarks ( pBookmarks ),
  214. _cValidRet ( 0 ),
  215. _ascRet ( 0 )
  216. {
  217. if (0 == pBookmarks)
  218. _cBookmarks = 0;
  219. }
  220. CRowSeekByBookmark( PDeSerStream & stm, int iVersion );
  221. virtual ~CRowSeekByBookmark( );
  222. virtual BOOL IsByBmkRowSeek(void) const { return TRUE; }
  223. void Marshall( PSerStream & stm ) const;
  224. SCODE GetRows( CTableCursor & rCursor,
  225. CTableSource & rTable,
  226. CGetRowsParams& rFetchParams,
  227. XPtr<CRowSeekDescription>& pSeekDescOut) const;
  228. void MergeResults( CRowSeekDescription * pRowSeek );
  229. BOOL IsDone(void) const
  230. {
  231. return _cBookmarks == 0;
  232. }
  233. ULONG GetValidStatuses(void) { return _cValidRet; }
  234. SCODE GetStatus(unsigned i) { return _ascRet[i]; }
  235. private:
  236. void _SetStatus( unsigned i, SCODE sc);
  237. ULONG _cBookmarks; // size of _aBookmarks
  238. ULONG _maxRet; // size of _ascRet
  239. ULONG _cValidRet; // number of valid entries in _ascRet
  240. CI_TBL_BMK* _aBookmarks; // array of bookmarks
  241. SCODE* _ascRet; // array of returned statuses
  242. };
  243. //+-------------------------------------------------------------------------
  244. //
  245. // Function: MarshallRowSeekDescription, public inline
  246. //
  247. // Synopsis: Marshall a row seek description and assign to a smart
  248. // pointer.
  249. //
  250. // Arguments: [stmSer] - Deserialization stream
  251. // [iVersion] - output stream version
  252. // [pRowSeek] - pointer to row seek description
  253. //
  254. // Returns: Nothing. Throws if error.
  255. //
  256. // History: 02 May 1995 AlanW Created
  257. //
  258. //+-------------------------------------------------------------------------
  259. inline void MarshallRowSeekDescription(
  260. PSerStream &stmSer,
  261. int iVersion,
  262. CRowSeekDescription* pRowSeek)
  263. {
  264. if (0 == pRowSeek)
  265. {
  266. stmSer.PutULong(eRowSeekNull);
  267. }
  268. else
  269. {
  270. pRowSeek->Marshall(stmSer);
  271. }
  272. }
  273. //+-------------------------------------------------------------------------
  274. //
  275. // Function: UnmarshallRowSeekDescription, public inline
  276. //
  277. // Synopsis: Unmarshall a row seek description and assign to a smart
  278. // pointer.
  279. //
  280. // Arguments: [stmDeser] - Deserialization stream
  281. // [iVersion] - input stream version
  282. // [xpRowSeek] - smart pointer to row seek description
  283. //
  284. // Returns: Nothing. Throws if error.
  285. //
  286. // History: 02 May 1995 AlanW Created
  287. //
  288. //+-------------------------------------------------------------------------
  289. inline void UnmarshallRowSeekDescription(
  290. PDeSerStream & stmDeser,
  291. int iVersion,
  292. XPtr<CRowSeekDescription> & xpRowSeek,
  293. BOOL fAllowNull )
  294. {
  295. //
  296. // Deserialize the row seek description
  297. //
  298. ULONG eMethod = stmDeser.GetULong();
  299. switch (eMethod)
  300. {
  301. case eRowSeekNull:
  302. if ( !fAllowNull )
  303. THROW( CException( STATUS_INVALID_PARAMETER ) );
  304. break;
  305. case eRowSeekCurrent:
  306. xpRowSeek.Set( new CRowSeekNext( stmDeser, iVersion ) );
  307. break;
  308. case eRowSeekAt:
  309. xpRowSeek.Set( new CRowSeekAt( stmDeser, iVersion ) );
  310. break;
  311. case eRowSeekAtRatio:
  312. xpRowSeek.Set( new CRowSeekAtRatio( stmDeser, iVersion ) );
  313. break;
  314. case eRowSeekByBookmark:
  315. xpRowSeek.Set( new CRowSeekByBookmark( stmDeser, iVersion ) );
  316. break;
  317. default:
  318. // Don't assert or the pipe hacking test will stop
  319. // Win4Assert( eMethod <= eRowSeekByBookmark );
  320. ciDebugOut(( DEB_ERROR,
  321. "UnmarshallRowSeekDescription, invalid eMethod: %d\n",
  322. eMethod ));
  323. THROW( CException( STATUS_INVALID_PARAMETER ) );
  324. }
  325. }