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.

249 lines
4.4 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. Wsbdbses.cpp
  5. Abstract:
  6. The CWsbDbSession class
  7. Author:
  8. Ron White [ronw] 20-Jun-1997
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "wsbdbsys.h"
  13. #include "wsbdbses.h"
  14. static USHORT iCountSes = 0; // Count of existing objects
  15. HRESULT
  16. CWsbDbSession::FinalConstruct(
  17. void
  18. )
  19. /*++
  20. Implements:
  21. CComObjectRoot::FinalConstruct
  22. --*/
  23. {
  24. HRESULT hr = S_OK;
  25. WsbTraceIn(OLESTR("CWsbDbSession::FinalConstruct"), OLESTR("") );
  26. m_SessionId = JET_sesidNil;
  27. iCountSes++;
  28. WsbTraceOut(OLESTR("CWsbDbSession::FinalConstruct"), OLESTR("hr =<%ls>, Count is <%d>"),
  29. WsbHrAsString(hr), iCountSes);
  30. return(hr);
  31. }
  32. void
  33. CWsbDbSession::FinalRelease(
  34. void
  35. )
  36. /*++
  37. Implements:
  38. CComObjectRoot::FinalRelease
  39. --*/
  40. {
  41. HRESULT hr = S_OK;
  42. WsbTraceIn(OLESTR("CWsbDbSession::FinalRelease"), OLESTR(""));
  43. try {
  44. JET_ERR jstat;
  45. WsbTrace(OLESTR("CWsbDbSession::FinalRelease, SessionId = %p\n"), (LONG_PTR)m_SessionId);
  46. if (JET_sesidNil != m_SessionId) {
  47. jstat = JetEndSession(m_SessionId, 0);
  48. WsbAffirmHr(jet_error(jstat));
  49. m_SessionId = JET_sesidNil;
  50. }
  51. } WsbCatch(hr);
  52. iCountSes--;
  53. WsbTraceOut(OLESTR("CWsbDbSession::FinalRelease"), OLESTR("hr =<%ls>, Count is <%d>"),
  54. WsbHrAsString(hr), iCountSes);
  55. }
  56. HRESULT
  57. CWsbDbSession::Init(
  58. JET_INSTANCE *pInstance
  59. )
  60. /*++
  61. Implements:
  62. IWsbDbSessionPriv::Init
  63. --*/
  64. {
  65. HRESULT hr = S_OK;
  66. WsbTraceIn(OLESTR("CWsbDbSession::Init"), OLESTR("") );
  67. try {
  68. JET_ERR jstat;
  69. // Create the Jet session here instead of in FinalConstract
  70. // because we need the Jet instance
  71. WsbAffirm(NULL != pInstance, E_POINTER);
  72. WsbTrace(OLESTR("CWsbDbSession::Init, calling JetBeginSession, JetInstance = %p\n"),
  73. (LONG_PTR)*pInstance );
  74. jstat = JetBeginSession(*pInstance, &m_SessionId, NULL, NULL);
  75. WsbTrace(OLESTR("CWsbDbSession::FinalConstruct, SessionId = %p\n"), (LONG_PTR)m_SessionId);
  76. WsbAffirmHr(jet_error(jstat));
  77. } WsbCatch(hr);
  78. WsbTraceOut(OLESTR("CWsbDbSession::Init"), OLESTR("hr =<%ls>"), WsbHrAsString(hr));
  79. return(hr);
  80. }
  81. HRESULT
  82. CWsbDbSession::GetJetId(
  83. JET_SESID* pSessionId
  84. )
  85. /*++
  86. Implements:
  87. IWsbDbSessionPriv::GetJetId
  88. --*/
  89. {
  90. HRESULT hr = S_OK;
  91. WsbTraceIn(OLESTR("CWsbDbSession::GetJetId"), OLESTR("") );
  92. *pSessionId = m_SessionId;
  93. WsbTraceOut(OLESTR("CWsbDbSession::GetJetId"), OLESTR("hr =<%ls>, Id = %lx"),
  94. WsbHrAsString(hr), *pSessionId);
  95. return(hr);
  96. }
  97. HRESULT
  98. CWsbDbSession::TransactionBegin(
  99. void
  100. )
  101. /*++
  102. Implements:
  103. IWsbDbSession::TransactionBegin
  104. --*/
  105. {
  106. HRESULT hr = S_OK;
  107. WsbTraceIn(OLESTR("CWsbDbSession::TransactionBegin"), OLESTR(""));
  108. try {
  109. JET_ERR jstat;
  110. jstat = JetBeginTransaction(m_SessionId);
  111. WsbAffirmHr(jet_error(jstat));
  112. } WsbCatch(hr);
  113. WsbTraceOut(OLESTR("CWsbDbSession::TransactionBegin"), OLESTR("hr =<%ls>"), WsbHrAsString(hr));
  114. return(hr);
  115. }
  116. HRESULT
  117. CWsbDbSession::TransactionCancel(
  118. void
  119. )
  120. /*++
  121. Implements:
  122. IWsbDbSession::TransactionCancel
  123. --*/
  124. {
  125. HRESULT hr = S_OK;
  126. WsbTraceIn(OLESTR("CWsbDbSession::TransactionCancel"), OLESTR(""));
  127. try {
  128. JET_ERR jstat;
  129. jstat = JetRollback(m_SessionId, 0);
  130. WsbAffirmHr(jet_error(jstat));
  131. } WsbCatch(hr);
  132. WsbTraceOut(OLESTR("CWsbDbSession::TransactionCancel"), OLESTR("hr =<%ls>"), WsbHrAsString(hr));
  133. return(hr);
  134. }
  135. HRESULT
  136. CWsbDbSession::TransactionEnd(
  137. void
  138. )
  139. /*++
  140. Implements:
  141. IWsbDbSession::TransactionEnd
  142. --*/
  143. {
  144. HRESULT hr = S_OK;
  145. WsbTraceIn(OLESTR("CWsbDbSession::TransactionEnd"), OLESTR(""));
  146. try {
  147. JET_ERR jstat;
  148. jstat = JetCommitTransaction(m_SessionId, 0);
  149. WsbAffirmHr(jet_error(jstat));
  150. } WsbCatch(hr);
  151. WsbTraceOut(OLESTR("CWsbDbSession::TransactionEnd"), OLESTR("hr =<%ls>"), WsbHrAsString(hr));
  152. return(hr);
  153. }