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.

242 lines
6.4 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995.
  5. //
  6. // File: PCache.hxx
  7. //
  8. // Contents: Protocol for HROW cache
  9. //
  10. // Classes: PMiniRowCache
  11. //
  12. // History: 05-Jun-95 KyleP Created
  13. // 14-JAN-97 KrishnaN Undefined CI_INETSRV and related changes
  14. //
  15. //----------------------------------------------------------------------------
  16. #include <pch.cxx>
  17. #pragma hdrstop
  18. #include "pcache.hxx"
  19. //+---------------------------------------------------------------------------
  20. //
  21. // Member: PMiniRowCache::PMiniRowCache, public
  22. //
  23. // Synopsis: Initialize, and setup default binding
  24. //
  25. // Arguments: [Index] -- Identifier. Not used internally.
  26. // [pRowset] -- Rowset used to fill cache.
  27. // [cBindings] -- Size of [pBindings].
  28. // [pBindings] -- Default binding.
  29. // [cbMaxLen] -- Max length of data fetched via [pBindings]
  30. //
  31. // History: 05-Jun-95 KyleP Created.
  32. //
  33. //----------------------------------------------------------------------------
  34. PMiniRowCache::PMiniRowCache( int Index,
  35. IRowset * pRowset,
  36. unsigned cBindings,
  37. DBBINDING * pBindings,
  38. unsigned cbMaxLen )
  39. : _Index( Index ),
  40. _pRowset( pRowset ),
  41. _ahrow( 2 ),
  42. _chrow( 0 ),
  43. _ihrow( 0 ),
  44. _cbRow( cbMaxLen )
  45. {
  46. //
  47. // Setup buffer for current row
  48. //
  49. _pbRow = new BYTE [_cbRow];
  50. //
  51. // Setup accessor
  52. //
  53. IAccessor * pia = 0;
  54. SCODE sc = _pRowset->QueryInterface( IID_IAccessor, (void **)&pia );
  55. if (SUCCEEDED( sc ))
  56. {
  57. sc = pia->CreateAccessor( DBACCESSOR_ROWDATA,
  58. cBindings,
  59. pBindings,
  60. 0,
  61. &_hacc,
  62. 0);
  63. pia->Release();
  64. }
  65. if ( FAILED(sc) )
  66. {
  67. delete [] _pbRow;
  68. vqDebugOut(( DEB_ERROR,
  69. "PMiniRowCache: CreateAccessor(child %d) returned 0x%x\n",
  70. _Index, sc ));
  71. THROW( CException(sc) );
  72. }
  73. END_CONSTRUCTION( PMiniRowCache );
  74. }
  75. //+---------------------------------------------------------------------------
  76. //
  77. // Member: PMiniRowCache::~PMiniRowCache, public
  78. //
  79. // Synopsis: Destructor.
  80. //
  81. // History: 05-Jun-95 KyleP Created.
  82. //
  83. //----------------------------------------------------------------------------
  84. PMiniRowCache::~PMiniRowCache()
  85. {
  86. //
  87. // Release any rows not transferred out.
  88. //
  89. FlushCache();
  90. delete [] _pbRow;
  91. IAccessor * pia = 0;
  92. _pRowset->QueryInterface( IID_IAccessor, (void **)&pia );
  93. Win4Assert(pia && "Invalid accessor!");
  94. pia->ReleaseAccessor( _hacc, 0 );
  95. pia->Release();
  96. }
  97. //+---------------------------------------------------------------------------
  98. //
  99. // Member: PMiniRowCache::SetCacheSize, public
  100. //
  101. // Synopsis: Adjust number of cached rows.
  102. //
  103. // Arguments: [cNewRows] -- Number of rows to cache.
  104. //
  105. // History: 05-Jun-95 KyleP Created.
  106. //
  107. // Notes: This call is advisory. There are situtations where the
  108. // cache cannot be shrunk.
  109. //
  110. //----------------------------------------------------------------------------
  111. void PMiniRowCache::SetCacheSize( DBCOUNTITEM cNewRows )
  112. {
  113. Win4Assert( cNewRows > 0 );
  114. //
  115. // Only realloc if the cache size is different.
  116. //
  117. if ( cNewRows != (DBCOUNTITEM) _ahrow.Count() )
  118. {
  119. //
  120. // We can't realloc to a smaller size than the number of rows
  121. // we're currently holding. Where would we put them?
  122. //
  123. if ( cNewRows < (DBCOUNTITEM) _chrow - (DBROWCOUNT) _ihrow &&
  124. _ihrow < _chrow )
  125. {
  126. cNewRows = _chrow - _ihrow;
  127. }
  128. //
  129. // Canonicalize the empty case.
  130. //
  131. if ( _ihrow >= _chrow )
  132. _ihrow = _chrow = 0;
  133. //
  134. // Realloc array of HROWs.
  135. //
  136. HROW * pnew = new HROW [(unsigned) cNewRows];
  137. RtlCopyMemory( pnew,
  138. _ahrow.GetPointer() + _ihrow,
  139. (_chrow - _ihrow) * sizeof(HROW) );
  140. delete [] _ahrow.Acquire();
  141. _ahrow.Set( (unsigned) cNewRows, pnew );
  142. //
  143. // Adjust index
  144. //
  145. _chrow -= _ihrow;
  146. _ihrow = 0;
  147. }
  148. }
  149. //+---------------------------------------------------------------------------
  150. //
  151. // Member: PMiniRowCache::LoadData, protected
  152. //
  153. // Synopsis: Called by derived classes to load default data for a new row.
  154. //
  155. // History: 05-Jun-95 KyleP Created.
  156. //
  157. //----------------------------------------------------------------------------
  158. void PMiniRowCache::LoadData()
  159. {
  160. //
  161. // Load up data for row.
  162. //
  163. SCODE sc = _pRowset->GetData( _ahrow[(unsigned) _ihrow], _hacc, _pbRow );
  164. if ( FAILED(sc) )
  165. {
  166. vqDebugOut(( DEB_ERROR, "PMiniRowCache: GetData returned 0x%x\n", sc ));
  167. THROW( CException( E_FAIL ) );
  168. }
  169. #if CIDBG == 1
  170. if ( vqInfoLevel & DEB_ITRACE )
  171. {
  172. vqDebugOut(( DEB_ITRACE, "Data for %d: ", Index() ));
  173. for ( int i = 0; i < 40; i++ )
  174. {
  175. if ( _pbRow[i] >= ' ' && _pbRow[i] <= '~' && 0 == _pbRow[i+1] )
  176. {
  177. vqDebugOut(( DEB_ITRACE | DEB_NOCOMPNAME, "%wc", *(WCHAR UNALIGNED *)&_pbRow[i] ));
  178. i++;
  179. }
  180. else
  181. vqDebugOut(( DEB_ITRACE | DEB_NOCOMPNAME, "%02x", _pbRow[i] ));
  182. }
  183. vqDebugOut(( DEB_ITRACE | DEB_NOCOMPNAME, "\n", _pbRow[i] ));
  184. }
  185. #endif
  186. }
  187. //+---------------------------------------------------------------------------
  188. //
  189. // Member: PMiniRowCache::FlushCache, public
  190. //
  191. // Synopsis: Clear the cache.
  192. //
  193. // History: 05-Jun-95 KyleP Created.
  194. //
  195. //----------------------------------------------------------------------------
  196. void PMiniRowCache::FlushCache()
  197. {
  198. if ( !IsAtEnd() )
  199. {
  200. _pRowset->ReleaseRows( _chrow - _ihrow, _ahrow.GetPointer() + _ihrow, 0, 0, 0 );
  201. }
  202. _ihrow = _chrow = 0;
  203. }