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.

191 lines
6.0 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright(C) 2000 Microsoft Corporation all rights reserved.
  4. //
  5. // Module: GlobalTransaction.cpp
  6. //
  7. // Project: Windows 2000 IAS
  8. //
  9. // Description: Implementation of CGlobalTransaction
  10. //
  11. // Author: tperraut
  12. //
  13. // Revision 02/24/2000 created
  14. //
  15. /////////////////////////////////////////////////////////////////////////////
  16. #include "stdafx.h"
  17. #include "GlobalTransaction.h"
  18. CGlobalTransaction CGlobalTransaction::_instance;
  19. CGlobalTransaction& CGlobalTransaction::Instance()
  20. {
  21. return _instance;
  22. }
  23. CGlobalTransaction::~CGlobalTransaction()
  24. {
  25. // an error-free upgrade will have commit called, then MyCloseDataSources
  26. // before the objects are destroyed.
  27. // that'll insure that the mdb files can be manipulated (no lock on them)
  28. // if it was not comited before, then abort.
  29. Abort();
  30. // close the datasources if needed
  31. MyCloseDataSources();
  32. };
  33. /////////////////////////////////////////////////////////////////////////////
  34. // MyCloseDataSources
  35. /////////////////////////////////////////////////////////////////////////////
  36. void CGlobalTransaction::MyCloseDataSources()
  37. {
  38. // then close the data sources
  39. if ( m_StdInitialized )
  40. {
  41. m_StdSession.Close();
  42. m_StdDataSource.Close();
  43. m_StdInitialized = FALSE;
  44. }
  45. if ( m_RefInitialized )
  46. {
  47. m_RefSession.Close();
  48. m_RefDataSource.Close();
  49. m_RefInitialized = FALSE;
  50. }
  51. if ( m_DnaryInitialized )
  52. {
  53. m_DnarySession.Close();
  54. m_DnaryDataSource.Close();
  55. m_DnaryInitialized = FALSE;
  56. }
  57. if ( m_NT4Initialized )
  58. {
  59. m_NT4Session.Close();
  60. m_NT4DataSource.Close();
  61. m_NT4Initialized = FALSE;
  62. }
  63. }
  64. /////////////////////////////////////////////////////////////////////////////
  65. // Commit
  66. /////////////////////////////////////////////////////////////////////////////
  67. void CGlobalTransaction::Commit()
  68. {
  69. if ( m_StdInitialized )
  70. {
  71. _com_util::CheckError(m_StdSession.Commit(FALSE, XACTTC_SYNC, 0));
  72. }
  73. }
  74. /////////////////////////////////////////////////////////////////////////////
  75. // Abort
  76. /////////////////////////////////////////////////////////////////////////////
  77. void CGlobalTransaction::Abort()
  78. {
  79. if ( m_StdInitialized )
  80. {
  81. m_StdSession.Abort(NULL, FALSE, FALSE ); // no check
  82. }
  83. }
  84. //////////////////////////////////////////////////////////////////////////
  85. // OpenStdDataSource
  86. //////////////////////////////////////////////////////////////////////////
  87. void CGlobalTransaction::OpenStdDataSource(LPCWSTR DataSourceName)
  88. {
  89. CDBPropSet dbinit(DBPROPSET_DBINIT);
  90. dbinit.AddProperty(DBPROP_INIT_DATASOURCE, DataSourceName);
  91. dbinit.AddProperty(DBPROP_INIT_MODE, static_cast<long>
  92. (DB_MODE_READWRITE));
  93. dbinit.AddProperty(DBPROP_INIT_PROMPT, static_cast<short>
  94. (DBPROMPT_NOPROMPT));
  95. _com_util::CheckError(m_StdDataSource.Open(
  96. L"Microsoft.Jet.OLEDB.4.0", &dbinit
  97. ));
  98. _com_util::CheckError(m_StdSession.Open(m_StdDataSource));
  99. ULONG TransactionLevel;
  100. _com_util::CheckError(m_StdSession.StartTransaction(
  101. ISOLATIONLEVEL_READCOMMITTED,
  102. 0,
  103. NULL,
  104. &TransactionLevel
  105. ));
  106. m_StdInitialized = TRUE;
  107. }
  108. //////////////////////////////////////////////////////////////////////////
  109. // OpenRefDataSource
  110. // No transaction (read only)
  111. //////////////////////////////////////////////////////////////////////////
  112. void CGlobalTransaction::OpenRefDataSource(LPCWSTR DataSourceName)
  113. {
  114. CDBPropSet dbinit(DBPROPSET_DBINIT);
  115. dbinit.AddProperty(DBPROP_INIT_DATASOURCE, DataSourceName);
  116. dbinit.AddProperty(DBPROP_INIT_MODE, static_cast<long>(DB_MODE_READ));
  117. dbinit.AddProperty(DBPROP_INIT_PROMPT, static_cast<short>(DBPROMPT_NOPROMPT));
  118. _com_util::CheckError(m_RefDataSource.Open(
  119. L"Microsoft.Jet.OLEDB.4.0", &dbinit
  120. ));
  121. _com_util::CheckError(m_RefSession.Open(m_RefDataSource));
  122. m_RefInitialized = TRUE;
  123. }
  124. //////////////////////////////////////////////////////////////////////////
  125. // OpenDnaryDataSource
  126. // No transaction (read only)
  127. //////////////////////////////////////////////////////////////////////////
  128. void CGlobalTransaction::OpenDnaryDataSource(LPCWSTR DataSourceName)
  129. {
  130. CDBPropSet dbinit(DBPROPSET_DBINIT);
  131. dbinit.AddProperty(DBPROP_INIT_DATASOURCE, DataSourceName);
  132. dbinit.AddProperty(DBPROP_INIT_MODE, static_cast<long>(DB_MODE_READ));
  133. dbinit.AddProperty(DBPROP_INIT_PROMPT, static_cast<short>(DBPROMPT_NOPROMPT));
  134. _com_util::CheckError(m_DnaryDataSource.Open(
  135. L"Microsoft.Jet.OLEDB.4.0", &dbinit
  136. ));
  137. _com_util::CheckError(m_DnarySession.Open(m_DnaryDataSource));
  138. m_DnaryInitialized = TRUE;
  139. }
  140. //////////////////////////////////////////////////////////////////////////
  141. // OpenNT4DataSource
  142. // No transaction (read only)
  143. //////////////////////////////////////////////////////////////////////////
  144. void CGlobalTransaction::OpenNT4DataSource(LPCWSTR DataSourceName)
  145. {
  146. CDBPropSet dbinit(DBPROPSET_DBINIT);
  147. dbinit.AddProperty(DBPROP_INIT_DATASOURCE, DataSourceName);
  148. dbinit.AddProperty(DBPROP_INIT_MODE, static_cast<long>(DB_MODE_READ));
  149. dbinit.AddProperty(DBPROP_INIT_PROMPT, static_cast<short>(DBPROMPT_NOPROMPT));
  150. _com_util::CheckError(m_NT4DataSource.Open(
  151. L"Microsoft.Jet.OLEDB.4.0", &dbinit
  152. ));
  153. _com_util::CheckError(m_NT4Session.Open(m_NT4DataSource));
  154. m_NT4Initialized = TRUE;
  155. }