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.

628 lines
19 KiB

  1. //////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft WMIOLE DB Provider
  4. // (C) Copyright 1999 Microsoft Corporation. All Rights Reserved.
  5. //
  6. // CDBSession base object and contained interface definitions
  7. //
  8. //////////////////////////////////////////////////////////////////////////////////////////////////
  9. #ifndef _DBSESS_H_
  10. #define _DBSESS_H_
  11. //////////////////////////////////////////////////////////////////////////////////////////////////
  12. class CImpIGetDataSource;
  13. class CImpIOpenRowset;
  14. class CImpISessionProperties;
  15. class CImpITableDefinition;
  16. class CImplIBindRsrc;
  17. class CImpIDBSchemaRowset;
  18. class CImplIIndexDefinition;
  19. class CImplIAlterTable;
  20. class CBinder;
  21. class CImpITransactionLocal;
  22. class CBaseRowObj;
  23. //99/04/12
  24. typedef CImpIGetDataSource* PIMPIGETDATASOURCE;
  25. typedef CImpIOpenRowset* PIMPIOPENROWSET;
  26. typedef CImpISessionProperties* PIMPISESSIONPROPERTIES;
  27. typedef CImpITableDefinition* PIMPITABLEDEFINITION; //99/04/1288
  28. typedef CImplIBindRsrc* PIMPIBINDSRC;
  29. typedef CImplIIndexDefinition* PIMPINDEXDEF;
  30. typedef CImplIAlterTable* PIMPIALTERTABLE;
  31. typedef CImpITransactionLocal * PIMPITRANSACTIONLOCAL;
  32. //////////////////////////////////////////////////////////////////////////////////////////////////
  33. //
  34. // Containing class for all interfaces on the DBSession Object
  35. //
  36. //////////////////////////////////////////////////////////////////////////////////////////////////
  37. class CDBSession : public CBaseObj
  38. {
  39. //===============================================================
  40. // contained interfaces are friends
  41. //===============================================================
  42. friend class CImpIGetDataSource;
  43. friend class CImpIOpenRowset;
  44. friend class CImpIDataSource;
  45. friend class CImpISessionProperties;
  46. friend class CImpITableDefinition;
  47. friend class CImplIBindRsrc;
  48. friend class CImpIDBCreateCommand;
  49. friend class CImplIIndexDefinition;
  50. friend class CBinder;
  51. friend class CImpITransactionLocal;
  52. protected:
  53. ULONG m_nOpenedRowset; // number of rows & rowsets opened
  54. PCUTILPROP m_pUtilProp; // Utility object to manage properties
  55. PIMPIOPENROWSET m_pIOpenRowset; // contained IOpenRowset
  56. PIMPIGETDATASOURCE m_pIGetDataSource; // contained IGetDataSource
  57. PIMPISESSIONPROPERTIES m_pISessionProperties; // contained ISessionProperties
  58. PIMPITABLEDEFINITION m_pITableDefinition; // contained ITableDefinition
  59. PIMPIBINDSRC m_pIBindResource; // Pointer to bindresource
  60. CImpIDBSchemaRowset * m_pISchemaRowset;
  61. CImpIDBCreateCommand * m_pIDBCreateCommand; // Contained IDBCreateCommand
  62. PIMPINDEXDEF m_pIIndexDefinition; // Contained IIndexDefinition
  63. PIMPIALTERTABLE m_pIAlterTable; // Contained IAlterTable
  64. PIMPISUPPORTERRORINFO m_pISupportErrorInfo; // contained ISupportErrorInfo
  65. PIMPITRANSACTIONLOCAL m_pITransLocal; // contained ITransactionLocal interface
  66. BOOL m_bTxnStarted; // flag to indicate if Txn has started or not
  67. ISOLEVEL m_TxnIsoLevel;
  68. XACTUOW m_TxnGuid; // unit of work identifying the transaction
  69. CFlexArray m_OpenedRowsets;
  70. HRESULT CreateCommand(IUnknown *pUnkOuter, REFGUID guidTemp,IUnknown ** ppUnk);
  71. HRESULT CreateRow(IUnknown *pUnkOuter, WCHAR *pstrURL,REFGUID guidTemp,IUnknown ** ppUnk);
  72. HRESULT CreateRowset(IUnknown *pUnkOuter, WCHAR *pstrURL, REFGUID guidTemp,IUnknown ** ppUnk);
  73. BOOL CheckIfValidDataSrc();
  74. HRESULT AddInterfacesForISupportErrorInfo();
  75. BOOL IsTransactionActive() { return m_bTxnStarted; }
  76. void SetTransactionActive(BOOL bActive) { m_bTxnStarted = bActive; }
  77. void SetIsolationLevel(ISOLEVEL isoLevel) { m_TxnIsoLevel = isoLevel; }
  78. ISOLEVEL GetIsolationLevel() { return m_TxnIsoLevel; }
  79. HRESULT GenerateNewUOW(GUID &guidTrans);
  80. XACTUOW GetCurrentUOW() { return m_TxnGuid; }
  81. void SetAllOpenRowsetToZoombieState();
  82. public:
  83. CDBSession(LPUNKNOWN);
  84. ~CDBSession(void);
  85. LPUNKNOWN m_pISessionCache; //data cache session (synchronized with this session)
  86. PCDATASOURCE m_pCDataSource; // parent data source object
  87. HRESULT FInit( CDataSource *pCDataSource ); // Intitialization Routine
  88. inline void DecRowsetCount(void){if(this->m_nOpenedRowset) this->m_nOpenedRowset--;}; // inline to dec rowset count
  89. STDMETHODIMP QueryInterface(REFIID, LPVOID *);
  90. STDMETHODIMP_(ULONG) AddRef(void);
  91. STDMETHODIMP_(ULONG) Release(void);
  92. inline void RowsetDestroyed() { m_nOpenedRowset = 0; };
  93. HRESULT GetDataSrcProperty(DBPROPID propId , VARIANT & varValue);
  94. void AddRowset(CBaseRowObj * pRowset); // add rowset to list of open rowset
  95. void RemoveRowset(CBaseRowObj * pRowset); // deletes the rowset from list of open rowset
  96. // 07/12/2000
  97. // NTRaid : 142348
  98. HRESULT ExecuteQuery(CQuery *pQuery) { return m_pCDataSource->m_pWbemWrap->ExecuteQuery(pQuery);}
  99. };
  100. typedef CDBSession *PCDBSESSION;
  101. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  102. //
  103. // Contained IGetDataSource class
  104. //
  105. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  106. class CImpIGetDataSource : public IGetDataSource
  107. {
  108. private:
  109. DEBUGCODE(ULONG m_cRef);
  110. CDBSession *m_pObj;
  111. public:
  112. CImpIGetDataSource( CDBSession *pObj )
  113. {
  114. DEBUGCODE(m_cRef = 0L);
  115. m_pObj = pObj;
  116. }
  117. ~CImpIGetDataSource()
  118. {
  119. }
  120. STDMETHODIMP_(ULONG) AddRef(void)
  121. {
  122. DEBUGCODE(InterlockedIncrement((long*)&m_cRef));
  123. return m_pObj->GetOuterUnknown()->AddRef();
  124. }
  125. STDMETHODIMP_(ULONG) Release(void)
  126. {
  127. DEBUGCODE(long lRef = InterlockedDecrement((long*)&m_cRef);
  128. if( lRef < 0 ){
  129. ASSERT("Reference count on Object went below 0!")
  130. })
  131. return m_pObj->GetOuterUnknown()->Release();
  132. }
  133. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv)
  134. {
  135. return m_pObj->GetOuterUnknown()->QueryInterface(riid, ppv);
  136. }
  137. STDMETHODIMP GetDataSource( REFIID, IUnknown** );
  138. };
  139. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  140. //
  141. // contained IOpenRowset class
  142. //
  143. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  144. class CImpIOpenRowset : public IOpenRowset
  145. {
  146. private:
  147. DEBUGCODE(ULONG m_cRef);
  148. CDBSession *m_pObj;
  149. BOOL GetIRowProp(ULONG cPropSet, DBPROPSET[]);
  150. public:
  151. CImpIOpenRowset( CDBSession *pObj )
  152. {
  153. DEBUGCODE(m_cRef = 0L);
  154. m_pObj = pObj;
  155. }
  156. ~CImpIOpenRowset()
  157. {
  158. }
  159. STDMETHODIMP_(ULONG) AddRef(void)
  160. {
  161. DEBUGCODE(InterlockedIncrement((long*)&m_cRef));
  162. return m_pObj->GetOuterUnknown()->AddRef();
  163. }
  164. STDMETHODIMP_(ULONG) Release(void)
  165. {
  166. DEBUGCODE(long lRef = InterlockedDecrement((long*)&m_cRef);
  167. if( lRef < 0 ){
  168. ASSERT("Reference count on Object went below 0!")
  169. })
  170. return m_pObj->GetOuterUnknown()->Release();
  171. }
  172. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv)
  173. {
  174. return m_pObj->GetOuterUnknown()->QueryInterface(riid, ppv);
  175. }
  176. STDMETHODIMP OpenRowset( IUnknown*, DBID*, DBID*, REFIID, ULONG, DBPROPSET[], IUnknown** );
  177. };
  178. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  179. //
  180. // Contained ISessionProperties class
  181. //
  182. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  183. class CImpISessionProperties : public ISessionProperties
  184. {
  185. friend class CBinder;
  186. private:
  187. DEBUGCODE(ULONG m_cRef);
  188. CDBSession *m_pObj;
  189. CDBSession * GetSessionPtr() { return m_pObj; } // This function is to give the session object pointer
  190. // to the binder object
  191. public:
  192. CImpISessionProperties( CDBSession *pObj )
  193. {
  194. DEBUGCODE(m_cRef = 0L);
  195. m_pObj = pObj;
  196. }
  197. ~CImpISessionProperties()
  198. {
  199. }
  200. STDMETHODIMP_(ULONG) AddRef(void)
  201. {
  202. DEBUGCODE(InterlockedIncrement((long*)&m_cRef));
  203. return m_pObj->GetOuterUnknown()->AddRef();
  204. }
  205. STDMETHODIMP_(ULONG) Release(void)
  206. {
  207. DEBUGCODE(long lRef = InterlockedDecrement((long*)&m_cRef);
  208. if( lRef < 0 ){
  209. ASSERT("Reference count on Object went below 0!")
  210. })
  211. return m_pObj->GetOuterUnknown()->Release();
  212. }
  213. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv)
  214. {
  215. return m_pObj->GetOuterUnknown()->QueryInterface(riid, ppv);
  216. }
  217. STDMETHODIMP GetProperties
  218. (
  219. ULONG cPropertySets,
  220. const DBPROPIDSET rgPropertySets[],
  221. ULONG* pcProperties,
  222. DBPROPSET** prgProperties
  223. );
  224. STDMETHODIMP SetProperties
  225. (
  226. ULONG cProperties,
  227. DBPROPSET rgProperties[]
  228. );
  229. };
  230. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  231. //
  232. // Contained ITableDefinition class
  233. //
  234. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  235. class CImpITableDefinition : public ITableDefinition
  236. {
  237. private:
  238. DEBUGCODE(ULONG m_cRef);
  239. CDBSession *m_pObj;
  240. public:
  241. CImpITableDefinition( CDBSession *pObj )
  242. {
  243. DEBUGCODE(m_cRef = 0L);
  244. m_pObj = pObj;
  245. }
  246. ~CImpITableDefinition()
  247. {
  248. }
  249. STDMETHODIMP_(ULONG) AddRef(void)
  250. {
  251. DEBUGCODE(InterlockedIncrement((long*)&m_cRef));
  252. return m_pObj->GetOuterUnknown()->AddRef();
  253. }
  254. STDMETHODIMP_(ULONG) Release(void)
  255. {
  256. DEBUGCODE(long lRef = InterlockedDecrement((long*)&m_cRef);
  257. if( lRef < 0 ){
  258. ASSERT("Reference count on Object went below 0!")
  259. })
  260. return m_pObj->GetOuterUnknown()->Release();
  261. }
  262. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv)
  263. {
  264. return m_pObj->GetOuterUnknown()->QueryInterface(riid, ppv);
  265. }
  266. STDMETHODIMP CreateTable( IUnknown __RPC_FAR *pUnkOuter,
  267. DBID __RPC_FAR *pTableID,
  268. DBORDINAL cColumnDescs,
  269. const DBCOLUMNDESC __RPC_FAR rgColumnDescs[ ],
  270. REFIID riid, ULONG cPropertySets,
  271. DBPROPSET __RPC_FAR rgPropertySets[ ],
  272. DBID __RPC_FAR *__RPC_FAR *ppTableID,
  273. IUnknown __RPC_FAR *__RPC_FAR *ppRowset);
  274. STDMETHODIMP DropTable( DBID __RPC_FAR *pTableID);
  275. STDMETHODIMP AddColumn( DBID __RPC_FAR *pTableID,
  276. DBCOLUMNDESC __RPC_FAR *pColumnDesc,
  277. DBID __RPC_FAR *__RPC_FAR *ppColumnID);
  278. STDMETHODIMP DropColumn( DBID __RPC_FAR *pTableID, DBID __RPC_FAR *pColumnID);
  279. };
  280. class CImplIBindRsrc : public IBindResource
  281. {
  282. private:
  283. CDBSession *m_pObj;
  284. DEBUGCODE(ULONG m_cRef);
  285. BOOL CheckBindURLFlags(DBBINDURLFLAG dwBindURLFlags , REFGUID rguid); // Function to check if proper flags are
  286. // are set for the require object
  287. // To check if URL Matches the requested type of object
  288. BOOL CheckIfProperURL(BSTR & strUrl,REFGUID rguid,DBBINDURLSTATUS * pdwBindStatus);
  289. HRESULT BindURL(IUnknown * pUnkOuter,
  290. LPCOLESTR pwszURL,
  291. DBBINDURLFLAG dwBindURLFlags,
  292. REFGUID rguid,
  293. REFIID riid,
  294. DBIMPLICITSESSION * pImplSession,
  295. DBBINDURLSTATUS * pdwBindStatus,
  296. IUnknown ** ppUnk);
  297. public:
  298. CImplIBindRsrc( CDBSession *pObj )
  299. {
  300. DEBUGCODE(m_cRef = 0L);
  301. m_pObj = pObj;
  302. }
  303. ~CImplIBindRsrc()
  304. {
  305. }
  306. STDMETHODIMP_(ULONG) AddRef(void)
  307. {
  308. DEBUGCODE(InterlockedIncrement((long*)&m_cRef));
  309. return m_pObj->GetOuterUnknown()->AddRef();
  310. }
  311. STDMETHODIMP_(ULONG) Release(void)
  312. {
  313. DEBUGCODE(long lRef = InterlockedDecrement((long*)&m_cRef);
  314. if( lRef < 0 ){
  315. ASSERT("Reference count on Object went below 0!")
  316. })
  317. return m_pObj->GetOuterUnknown()->Release();
  318. }
  319. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv)
  320. {
  321. return m_pObj->GetOuterUnknown()->QueryInterface(riid, ppv);
  322. }
  323. STDMETHODIMP Bind(
  324. IUnknown * pUnkOuter,
  325. LPCOLESTR pwszURL,
  326. DBBINDURLFLAG dwBindURLFlags,
  327. REFGUID rguid,
  328. REFIID riid,
  329. IAuthenticate * pAuthenticate,
  330. DBIMPLICITSESSION * pImplSession,
  331. DBBINDURLSTATUS * pdwBindStatus,
  332. IUnknown ** ppUnk);
  333. };
  334. class CImplIIndexDefinition : public IIndexDefinition
  335. {
  336. private:
  337. DEBUGCODE(ULONG m_cRef);
  338. CDBSession *m_pObj;
  339. public:
  340. CImplIIndexDefinition( CDBSession *pObj )
  341. {
  342. DEBUGCODE(m_cRef = 0L);
  343. m_pObj = pObj;
  344. }
  345. ~CImplIIndexDefinition()
  346. {
  347. }
  348. STDMETHODIMP_(ULONG) AddRef(void)
  349. {
  350. DEBUGCODE(InterlockedIncrement((long*)&m_cRef));
  351. return m_pObj->GetOuterUnknown()->AddRef();
  352. }
  353. STDMETHODIMP_(ULONG) Release(void)
  354. {
  355. DEBUGCODE(long lRef = InterlockedDecrement((long*)&m_cRef);
  356. if( lRef < 0 ){
  357. ASSERT("Reference count on Object went below 0!")
  358. })
  359. return m_pObj->GetOuterUnknown()->Release();
  360. }
  361. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv)
  362. {
  363. return m_pObj->GetOuterUnknown()->QueryInterface(riid, ppv);
  364. }
  365. STDMETHODIMP CreateIndex( DBID * pTableID,
  366. DBID * pIndexID,
  367. DBORDINAL cIndexColumnDescs,
  368. const DBINDEXCOLUMNDESC rgIndexColumnDescs[],
  369. ULONG cPropertySets,
  370. DBPROPSET rgPropertySets[],
  371. DBID ** ppIndexID);
  372. STDMETHODIMP DropIndex( DBID * pTableID, DBID * pIndexID);
  373. };
  374. class CImplIAlterTable : public IAlterTable
  375. {
  376. private:
  377. DEBUGCODE(ULONG m_cRef);
  378. CDBSession *m_pObj;
  379. HRESULT CheckIfSupported(DBCOLUMNDESCFLAGS ColumnDescFlags);
  380. public:
  381. CImplIAlterTable( CDBSession *pObj )
  382. {
  383. DEBUGCODE(m_cRef = 0L);
  384. m_pObj = pObj;
  385. }
  386. ~CImplIAlterTable()
  387. {
  388. }
  389. STDMETHODIMP_(ULONG) AddRef(void)
  390. {
  391. DEBUGCODE(InterlockedIncrement((long*)&m_cRef));
  392. return m_pObj->GetOuterUnknown()->AddRef();
  393. }
  394. STDMETHODIMP_(ULONG) Release(void)
  395. {
  396. DEBUGCODE(long lRef = InterlockedDecrement((long*)&m_cRef);
  397. if( lRef < 0 ){
  398. ASSERT("Reference count on Object went below 0!")
  399. })
  400. return m_pObj->GetOuterUnknown()->Release();
  401. }
  402. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv)
  403. {
  404. return m_pObj->GetOuterUnknown()->QueryInterface(riid, ppv);
  405. }
  406. STDMETHODIMP AlterColumn(DBID * pTableID,
  407. DBID * pColumnID,
  408. DBCOLUMNDESCFLAGS ColumnDescFlags,
  409. DBCOLUMNDESC * pColumnDesc);
  410. STDMETHODIMP AlterTable(DBID * pTableID,
  411. DBID * pNewTableID,
  412. ULONG cPropertySets,
  413. DBPROPSET rgPropertySet[]);
  414. };
  415. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  416. //
  417. // Hashs a token and returns TRUE iff the token is a statement keywpord.
  418. //
  419. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  420. class CImpIDBCreateCommand : public IDBCreateCommand
  421. {
  422. public:
  423. CImpIDBCreateCommand(PCDBSESSION pCDBSession)
  424. {
  425. m_pCDBSession = pCDBSession;
  426. DEBUGCODE(m_cRef = 0);
  427. }
  428. ~CImpIDBCreateCommand() {}
  429. STDMETHODIMP_(ULONG) AddRef(void)
  430. {
  431. DEBUGCODE(InterlockedIncrement((long*)&m_cRef));
  432. return m_pCDBSession->GetOuterUnknown()->AddRef();
  433. }
  434. STDMETHODIMP_(ULONG) Release(void)
  435. {
  436. DEBUGCODE(long lRef = InterlockedDecrement((long*)&m_cRef);
  437. if( lRef < 0 ){
  438. ASSERT("Reference count on Object went below 0!")
  439. })
  440. return m_pCDBSession->GetOuterUnknown()->Release();
  441. }
  442. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv)
  443. {
  444. return m_pCDBSession->GetOuterUnknown()->QueryInterface(riid, ppv);
  445. }
  446. STDMETHODIMP CreateCommand( IUnknown* punkOuter, REFIID riid, IUnknown **ppCommand );
  447. private:
  448. CDBSession *m_pCDBSession;
  449. DEBUGCODE(ULONG m_cRef);
  450. };
  451. typedef CImpIDBCreateCommand *PIMPIDBCREATECOMMAND;
  452. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  453. //
  454. // Class declaration for implementing ITransactionLocal interface
  455. //
  456. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  457. class CImpITransactionLocal : public ITransactionLocal
  458. {
  459. public:
  460. CImpITransactionLocal(PCDBSESSION pCDBSession)
  461. {
  462. m_pCDBSession = pCDBSession;
  463. DEBUGCODE(m_cRef = 0);
  464. }
  465. ~CImpITransactionLocal() {}
  466. STDMETHODIMP_(ULONG) AddRef(void)
  467. {
  468. DEBUGCODE(InterlockedIncrement((long*)&m_cRef));
  469. return m_pCDBSession->GetOuterUnknown()->AddRef();
  470. }
  471. STDMETHODIMP_(ULONG) Release(void)
  472. {
  473. DEBUGCODE(long lRef = InterlockedDecrement((long*)&m_cRef);
  474. if( lRef < 0 ){
  475. ASSERT("Reference count on Object went below 0!")
  476. })
  477. return m_pCDBSession->GetOuterUnknown()->Release();
  478. }
  479. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv)
  480. {
  481. return m_pCDBSession->GetOuterUnknown()->QueryInterface(riid, ppv);
  482. }
  483. STDMETHODIMP Commit (BOOL fRetaining,
  484. DWORD grfTC,
  485. DWORD grfRM);
  486. STDMETHODIMP Abort (BOID *pboidReason,
  487. BOOL fRetaining,
  488. BOOL fAsync);
  489. STDMETHODIMP GetTransactionInfo (XACTTRANSINFO *pinfo);
  490. STDMETHODIMP GetOptionsObject (ITransactionOptions ** ppOptions);
  491. STDMETHODIMP StartTransaction( ISOLEVEL isoLevel,
  492. ULONG isoFlags,
  493. ITransactionOptions *pOtherOptions,
  494. ULONG *pulTransactionLevel);
  495. private:
  496. CDBSession *m_pCDBSession;
  497. DEBUGCODE(ULONG m_cRef);
  498. HRESULT GetFlagsForIsolation(ISOLEVEL isoLevel,LONG &lFlag);
  499. };
  500. typedef CImpITransactionLocal *PIMPITRANSACTIONLOCAL;
  501. #endif