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.

504 lines
18 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 2000
  5. //
  6. // File: ScrlSort.hxx
  7. //
  8. // Contents: Sorted, fully scrollable, distributed rowset.
  9. //
  10. // Classes: CScrollableSorted
  11. //
  12. // History: 05-Jun-95 KyleP Created
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. #include <impiunk.hxx>
  17. #include "seqsort.hxx"
  18. #include "poscache.hxx"
  19. //+---------------------------------------------------------------------------
  20. //
  21. // Class: CScrollableSorted
  22. //
  23. // Purpose: Sorted, fully scrollable, distributed rowset.
  24. //
  25. // History: 05-Jun-95 KyleP Created.
  26. //
  27. // Notes: Many of the methods in here are just forwarders to
  28. // implementation in CSequentialSorted. They are needed
  29. // because we have the following class structure:
  30. //
  31. // IRowset IRowset
  32. // \ /
  33. // CDistributedRowset IRowsetLocate
  34. // \ /
  35. // CSequentialSorted IRowsetScroll
  36. // \ /
  37. // \ /
  38. // CScrollableSorted
  39. //
  40. // What we really want is:
  41. //
  42. // IRowset
  43. // / \ .
  44. // CDistributedRowset IRowsetLocate
  45. // \ /
  46. // CSequentialSorted IRowsetScroll
  47. // \ /
  48. // \ /
  49. // CScrollableSorted
  50. //
  51. // But that involves virtual inheritance of IRowset, which
  52. // is not supported by OLE. Virtual inheritance is
  53. // simulated with the forwarder methods.
  54. //
  55. //----------------------------------------------------------------------------
  56. class CScrollableSorted : public IRowsetExactScroll,
  57. public IColumnsInfo, public IRowsetInfo,
  58. public IRowsetAsynch, public IAccessor,
  59. public IRowsetIdentity, public IRowsetQueryStatus,
  60. public IDBAsynchStatus, public IRowsetWatchRegion
  61. {
  62. public:
  63. CScrollableSorted( IUnknown * pUnkOuter,
  64. IUnknown ** ppMyUnk,
  65. IRowsetScroll ** aChild,
  66. unsigned cChild,
  67. CMRowsetProps const & Props,
  68. unsigned cColumns,
  69. CSort const & sort,
  70. CAccessorBag & aAccessors );
  71. //
  72. // IUnknown methods.
  73. //
  74. STDMETHOD(QueryInterface) ( THIS_ REFIID riid,
  75. LPVOID *ppiuk )
  76. {
  77. return _pControllingUnknown->QueryInterface(riid,ppiuk);
  78. }
  79. STDMETHOD_(ULONG, AddRef) (THIS) { return _pControllingUnknown->AddRef();}
  80. STDMETHOD_(ULONG, Release) (THIS) {return _pControllingUnknown->Release(); }
  81. //
  82. // IAccessor methods
  83. //
  84. STDMETHOD (AddRefAccessor) ( HACCESSOR hAccessor,
  85. ULONG * pcRefCount )
  86. {
  87. return _rowset.AddRefAccessor( hAccessor, pcRefCount );
  88. }
  89. STDMETHOD (CreateAccessor) ( DBACCESSORFLAGS dwAccessorFlags,
  90. DBCOUNTITEM cBindings,
  91. const DBBINDING rgBindings[],
  92. DBLENGTH cbRowWidth,
  93. HACCESSOR * phAccessor,
  94. DBBINDSTATUS rgStatus[] )
  95. {
  96. return _rowset.CreateAccessor( dwAccessorFlags,
  97. cBindings,
  98. rgBindings,
  99. cbRowWidth,
  100. phAccessor,
  101. rgStatus );
  102. }
  103. STDMETHOD (GetBindings) ( HACCESSOR hAccessor,
  104. DBACCESSORFLAGS * pdwAccessorFlags,
  105. DBCOUNTITEM * pcBindings,
  106. DBBINDING * * prgBindings)
  107. {
  108. return _rowset.GetBindings( hAccessor,
  109. pdwAccessorFlags,
  110. pcBindings,
  111. prgBindings );
  112. }
  113. STDMETHOD (ReleaseAccessor) ( HACCESSOR hAccessor,
  114. ULONG * pcRefCount )
  115. {
  116. return _rowset.ReleaseAccessor( hAccessor, pcRefCount );
  117. }
  118. //
  119. // IRowsetInfo methods
  120. //
  121. STDMETHOD(GetProperties) (const ULONG cPropertyIDSets,
  122. const DBPROPIDSET rgPropertyIDSets[],
  123. ULONG * pcProperties,
  124. DBPROPSET ** prgProperties)
  125. {
  126. return _rowset.GetProperties( cPropertyIDSets,
  127. rgPropertyIDSets,
  128. pcProperties,
  129. prgProperties );
  130. }
  131. STDMETHOD (GetReferencedRowset) ( DBORDINAL iOrdinal,
  132. REFIID riid,
  133. IUnknown ** ppReferencedRowset)
  134. {
  135. return _rowset.GetReferencedRowset( iOrdinal, riid, ppReferencedRowset );
  136. }
  137. //
  138. // IRowset methods
  139. //
  140. STDMETHOD (AddRefRows) ( DBCOUNTITEM cRows,
  141. const HROW rghRows [],
  142. DBREFCOUNT rgRefCounts[],
  143. DBROWSTATUS rgRowStatus[] )
  144. {
  145. return _rowset.AddRefRows( cRows, rghRows, rgRefCounts, rgRowStatus );
  146. }
  147. STDMETHOD (GetData) ( HROW hRow,
  148. HACCESSOR hAccessor,
  149. void * pData );
  150. STDMETHOD (GetNextRows) ( HCHAPTER hChapter,
  151. DBROWOFFSET cRowsToSkip,
  152. DBROWCOUNT cRows,
  153. DBCOUNTITEM * pcRowsObtained,
  154. HROW * * rrghRows )
  155. {
  156. return _rowset.GetNextRows( hChapter,
  157. cRowsToSkip,
  158. cRows,
  159. pcRowsObtained,
  160. rrghRows );
  161. }
  162. STDMETHOD (GetSpecification) ( REFIID riid,
  163. IUnknown ** ppSpecification )
  164. {
  165. return _rowset.GetSpecification( riid, ppSpecification );
  166. }
  167. STDMETHOD (ReleaseChapter) ( HCHAPTER hChapter )
  168. {
  169. return _rowset.ReleaseChapter( hChapter );
  170. }
  171. STDMETHOD (ReleaseRows) ( DBCOUNTITEM cRows,
  172. const HROW rghRows [],
  173. DBROWOPTIONS rgRowOptions[],
  174. DBREFCOUNT rgRefCounts[],
  175. DBROWSTATUS rgRowStatus[] )
  176. {
  177. return _rowset.ReleaseRows( cRows, rghRows, rgRowOptions, rgRefCounts, rgRowStatus );
  178. }
  179. STDMETHOD (RestartPosition) ( HCHAPTER hChapter )
  180. {
  181. return _rowset.RestartPosition( hChapter );
  182. }
  183. //
  184. // IRowsetLocate methods
  185. //
  186. STDMETHOD (Compare)( HCHAPTER hChapter,
  187. DBBKMARK cbBM1,
  188. BYTE const* pBM1,
  189. DBBKMARK cbBM2,
  190. BYTE const * pBM2,
  191. DBCOMPARE * pdwComparison );
  192. STDMETHOD (GetRowsAt) (HWATCHREGION hRegion,
  193. HCHAPTER hChapter,
  194. DBBKMARK cbBookmark,
  195. const BYTE * pBookmark,
  196. DBROWOFFSET lRowsOffset,
  197. DBROWCOUNT cRows,
  198. DBCOUNTITEM * pcRowsObtained,
  199. HROW * * rrghRows );
  200. STDMETHOD(GetRowsByBookmark) (HCHAPTER hChapter,
  201. DBCOUNTITEM cRows,
  202. const DBBKMARK rgcbBookmarks[],
  203. const BYTE * rgpBookmarks[],
  204. HROW rghRows[],
  205. DBROWSTATUS rgRowStatus[]);
  206. STDMETHOD(Hash) (HCHAPTER hChapter,
  207. DBBKMARK cBookmarks,
  208. const DBBKMARK rgcbBookmarks[],
  209. const BYTE * rgpBookmarks[],
  210. DBHASHVALUE rgHashedValues[],
  211. DBROWSTATUS rgRowStatus[]);
  212. //
  213. // IRowsetScroll methods
  214. //
  215. STDMETHOD (GetApproximatePosition) ( HCHAPTER hChapter,
  216. DBBKMARK cbBookmark,
  217. const BYTE * pBookmark,
  218. DBCOUNTITEM * pulPosition,
  219. DBCOUNTITEM * pulRows );
  220. STDMETHOD (GetRowsAtRatio)(HWATCHREGION hRegion,
  221. HCHAPTER hChapter,
  222. DBCOUNTITEM ulNumerator,
  223. DBCOUNTITEM ulDenominator,
  224. DBROWCOUNT cRows,
  225. DBCOUNTITEM * pcRowsObtained,
  226. HROW * * rrghRows );
  227. //
  228. // IColumnsInfo methods
  229. //
  230. STDMETHOD (GetColumnInfo) ( DBORDINAL * pcColumns,
  231. DBCOLUMNINFO * * rrgInfo,
  232. WCHAR * * ppwchInfo )
  233. {
  234. return _rowset.GetColumnInfo( pcColumns, rrgInfo, ppwchInfo );
  235. }
  236. STDMETHOD (MapColumnIDs) ( DBORDINAL cColumnIDs,
  237. const DBID rgColumnIDs[],
  238. DBORDINAL rgColumns[] )
  239. {
  240. return _rowset.MapColumnIDs( cColumnIDs, rgColumnIDs, rgColumns );
  241. }
  242. //
  243. // IRowsetIdentity methods
  244. //
  245. STDMETHOD (IsSameRow) ( HROW hThisRow, HROW hThatRow )
  246. {
  247. return _rowset.IsSameRow( hThisRow, hThatRow );
  248. }
  249. //
  250. // IRowsetAsynch methods
  251. //
  252. STDMETHOD(RatioFinished) (DBCOUNTITEM * pulDenominator,
  253. DBCOUNTITEM * pulNumerator,
  254. DBCOUNTITEM * pcRows,
  255. BOOL * pfNewRows);
  256. STDMETHOD(Stop) ( );
  257. //
  258. // IRowsetExactScroll methods
  259. // deprecated, but needed by ADO
  260. //
  261. STDMETHOD(GetExactPosition) (HCHAPTER hChapter,
  262. DBBKMARK cbBookmark,
  263. const BYTE * pBookmark,
  264. DBCOUNTITEM * pulPosition,
  265. DBCOUNTITEM * pcRows) /*const*/;
  266. //
  267. // IRowsetQueryStatus methods
  268. //
  269. STDMETHOD(GetStatus) (DWORD * pStatus)
  270. {
  271. return _rowset.GetStatus( pStatus );
  272. }
  273. STDMETHOD(GetStatusEx) (DWORD * pStatus,
  274. DWORD * pcFilteredDocuments,
  275. DWORD * pcDocumentsToFilter,
  276. DBCOUNTITEM * pdwRatioFinishedDenominator,
  277. DBCOUNTITEM * pdwRatioFinishedNumerator,
  278. DBBKMARK cbBmk,
  279. const BYTE * pBmk,
  280. DBCOUNTITEM * piRowCurrent,
  281. DBCOUNTITEM * pcRowsTotal )
  282. {
  283. SCODE sc = _rowset.GetStatusEx( pStatus,
  284. pcFilteredDocuments,
  285. pcDocumentsToFilter,
  286. pdwRatioFinishedDenominator,
  287. pdwRatioFinishedNumerator,
  288. cbBmk,
  289. pBmk,
  290. piRowCurrent,
  291. pcRowsTotal );
  292. if ( SUCCEEDED( sc ) && pBmk && cbBmk > 0 && piRowCurrent )
  293. {
  294. GetExactPosition( 0, cbBmk, pBmk, piRowCurrent, 0 );
  295. }
  296. return sc;
  297. }
  298. //
  299. // IDBAsynchStatus methods
  300. //
  301. STDMETHOD(Abort) (HCHAPTER hChapter,
  302. ULONG ulOpertation);
  303. STDMETHOD(GetStatus) (HCHAPTER hChapter,
  304. DBASYNCHOP ulOperation,
  305. DBCOUNTITEM * pulProgress,
  306. DBCOUNTITEM * pulProgressMax,
  307. DBASYNCHPHASE * pulAsynchPhase,
  308. LPOLESTR * ppwszStatusText) /*const*/;
  309. // IRowsetWatchAll methods
  310. //
  311. STDMETHOD(Acknowledge) ( )
  312. {
  313. return E_NOTIMPL;
  314. }
  315. STDMETHOD(Start) ( )
  316. {
  317. return E_NOTIMPL;
  318. }
  319. STDMETHOD(StopWatching) ( )
  320. {
  321. return E_NOTIMPL;
  322. }
  323. //
  324. // IRowsetWatchRegion methods
  325. //
  326. STDMETHOD(CreateWatchRegion) (
  327. DBWATCHMODE mode,
  328. HWATCHREGION* phRegion)
  329. {
  330. return E_NOTIMPL;
  331. }
  332. STDMETHOD(ChangeWatchMode) (
  333. HWATCHREGION hRegion,
  334. DBWATCHMODE mode)
  335. {
  336. return E_NOTIMPL;
  337. }
  338. STDMETHOD(DeleteWatchRegion) (
  339. HWATCHREGION hRegion)
  340. {
  341. return E_NOTIMPL;
  342. }
  343. STDMETHOD(GetWatchRegionInfo) (
  344. HWATCHREGION hRegion,
  345. DBWATCHMODE * pMode,
  346. HCHAPTER * phChapter,
  347. DBBKMARK * pcbBookmark,
  348. BYTE * * ppBookmark,
  349. DBROWCOUNT * pcRows)
  350. {
  351. return E_NOTIMPL;
  352. }
  353. STDMETHOD(Refresh) (
  354. DBCOUNTITEM* pChangesObtained,
  355. DBROWWATCHCHANGE** prgChanges );
  356. STDMETHOD(ShrinkWatchRegion) (
  357. HWATCHREGION hRegion,
  358. HCHAPTER hChapter,
  359. DBBKMARK cbBookmark,
  360. BYTE* pBookmark,
  361. DBROWCOUNT cRows )
  362. {
  363. return E_NOTIMPL;
  364. }
  365. protected:
  366. virtual ~CScrollableSorted();
  367. SCODE RealQueryInterface ( REFIID riid, LPVOID *ppiuk ); // used by _pControllingUnknown
  368. // in aggregation - does QI without delegating to outer unknown
  369. IUnknown * _pControllingUnknown; // outer unknown
  370. IRowsetScroll * Get(unsigned i) { return (IRowsetScroll *)_rowset._aChild[i]; }
  371. private:
  372. friend class CImpIUnknown<CScrollableSorted>;
  373. CImpIUnknown<CScrollableSorted> _impIUnknown;
  374. inline void SwapCursor( unsigned i1, unsigned i2 );
  375. SCODE Seek( DBBKMARK cbBookmark, BYTE const * pbBookmark, DBROWOFFSET lOffset );
  376. PMiniRowCache::ENext AdjustPosition( unsigned iChild, int iTarget );
  377. PMiniRowCache::ENext InitialSeek( unsigned iChild,
  378. int ITarget,
  379. int InitalDirection,
  380. int & iJump,
  381. int & iNextInc,
  382. int & iDirection );
  383. void Seek( DBCOUNTITEM ulNumerator, DBCOUNTITEM ulDenominator );
  384. BOOL SetupFetch( DBROWCOUNT cRows, HROW * rrghRows[] );
  385. SCODE CScrollableSorted::StandardFetch( DBROWCOUNT cRows,
  386. DBCOUNTITEM * pcRowsObtained,
  387. HROW rghRows[] );
  388. PMiniRowCache ** GetCacheArray()
  389. {
  390. Win4Assert( (ULONG_PTR)_apPosCursor[0] == (ULONG_PTR)(PMiniRowCache *)_apPosCursor[0] );
  391. return (PMiniRowCache **)_apPosCursor.GetPointer();
  392. }
  393. CMutexSem _mutex;
  394. unsigned _GetMaxPrevRowChild();
  395. CSequentialSorted _rowset; // Wish I could inherit this.
  396. XArray<CMiniPositionableCache *> _apPosCursor; // Fat cursors
  397. CRowHeap _heap; // Cursor heap
  398. // Ole-DB Error support
  399. CCIOleDBError _DBErrorObj; // error object
  400. };
  401. //+---------------------------------------------------------------------------
  402. //
  403. // Member: CScrollableSorted::SwapCursor, private
  404. //
  405. // Synopsis: Swaps two cursors
  406. //
  407. // Arguments: [i1] -- first of two cursors to swap
  408. // [i2] -- second cursor
  409. //
  410. // History: 07-Aug-95 KyleP Created.
  411. //
  412. //----------------------------------------------------------------------------
  413. inline void CScrollableSorted::SwapCursor( unsigned i1, unsigned i2 )
  414. {
  415. CMiniPositionableCache * pTemp = _apPosCursor[i1];
  416. _apPosCursor[i1] = _apPosCursor[i2];
  417. _apPosCursor[i2] = pTemp;
  418. }