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.

213 lines
5.1 KiB

  1. /******************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. Session.cpp
  5. Abstract:
  6. This file contains the implementation of the JetBlueCOM::Session class.
  7. Revision History:
  8. Davide Massarenti (Dmassare) 05/20/2000
  9. created
  10. ******************************************************************************/
  11. #include <stdafx.h>
  12. #ifndef NOJETBLUECOM
  13. ////////////////////////////////////////////////////////////////////////////////
  14. JetBlueCOM::Session::Session()
  15. {
  16. // JetBlue::SessionHandle m_sess;
  17. // BaseObjectWithChildren<Session,Database> m_DBs;
  18. }
  19. JetBlueCOM::Session::~Session()
  20. {
  21. Passivate();
  22. }
  23. HRESULT JetBlueCOM::Session::Refresh()
  24. {
  25. __HCP_FUNC_ENTRY( "JetBlueCOM::Session::Refresh" );
  26. HRESULT hr;
  27. int iDb = m_sess->NumOfDatabases();
  28. int i;
  29. m_DBs.Passivate();
  30. for(i=0; i<iDb; i++)
  31. {
  32. CComPtr<Database> child;
  33. JetBlue::Database* db = m_sess->GetDB( i );
  34. __MPC_EXIT_IF_METHOD_FAILS(hr, db->Open( /*fReadOnly*/false, /*fCreate*/false, /*fRepair*/false ));
  35. __MPC_EXIT_IF_METHOD_FAILS(hr, m_DBs.CreateChild( this, &child ));
  36. __MPC_EXIT_IF_METHOD_FAILS(hr, child->Initialize( *db ));
  37. }
  38. hr = S_OK;
  39. __HCP_FUNC_CLEANUP;
  40. __HCP_FUNC_EXIT(hr);
  41. }
  42. ////////////////////////////////////////
  43. HRESULT JetBlueCOM::Session::FinalConstruct()
  44. {
  45. __HCP_FUNC_ENTRY( "JetBlueCOM::Session::FinalConstruct" );
  46. HRESULT hr;
  47. __MPC_EXIT_IF_METHOD_FAILS(hr, JetBlue::SessionPool::s_GLOBAL->GetSession( m_sess ));
  48. hr = Refresh();
  49. __HCP_FUNC_CLEANUP;
  50. __HCP_FUNC_EXIT(hr);
  51. }
  52. void JetBlueCOM::Session::Passivate()
  53. {
  54. MPC::SmartLock<_ThreadModel> lock( this );
  55. m_DBs .Passivate();
  56. m_sess.Release ();
  57. }
  58. ////////////////////////////////////////
  59. STDMETHODIMP JetBlueCOM::Session::get_Databases( /*[out, retval]*/ IPCHDBCollection* *pVal )
  60. {
  61. __HCP_FUNC_ENTRY( "JetBlueCOM::Session::get_Databases" );
  62. HRESULT hr;
  63. MPC::SmartLock<_ThreadModel> lock( this );
  64. __MPC_PARAMCHECK_BEGIN(hr)
  65. __MPC_PARAMCHECK_POINTER_AND_SET(pVal,NULL);
  66. __MPC_PARAMCHECK_END();
  67. hr = m_DBs.GetEnumerator( pVal );
  68. __HCP_FUNC_CLEANUP;
  69. __HCP_FUNC_EXIT(hr);
  70. }
  71. ////////////////////////////////////////
  72. STDMETHODIMP JetBlueCOM::Session::AttachDatabase( /*[in]*/ BSTR bstrName ,
  73. /*[in, optional]*/ VARIANT vCreate ,
  74. /*[out,retval]*/ IPCHDBDatabase* *pVal )
  75. {
  76. __HCP_FUNC_ENTRY( "JetBlueCOM::Session::AttachDatabase" );
  77. USES_CONVERSION;
  78. HRESULT hr;
  79. MPC::SmartLock<_ThreadModel> lock( this );
  80. JetBlue::Database* db;
  81. LPSTR szName;
  82. bool fCreate;
  83. __MPC_PARAMCHECK_BEGIN(hr)
  84. __MPC_PARAMCHECK_STRING_NOT_EMPTY(bstrName);
  85. __MPC_PARAMCHECK_POINTER_AND_SET(pVal,NULL);
  86. __MPC_PARAMCHECK_END();
  87. szName = W2A( bstrName );
  88. fCreate = (vCreate.vt == VT_BOOL && vCreate.boolVal == VARIANT_TRUE);
  89. __MPC_EXIT_IF_METHOD_FAILS(hr, m_sess->GetDatabase( szName, db, /*fReadOnly*/false, /*fCreate*/fCreate, /*fRepair*/false ));
  90. __MPC_EXIT_IF_METHOD_FAILS(hr, Refresh());
  91. {
  92. BaseObjectWithChildren<Session,Database>::ChildIterConst itBegin;
  93. BaseObjectWithChildren<Session,Database>::ChildIterConst itEnd;
  94. m_DBs.GetChildren( itBegin, itEnd );
  95. for(;itBegin != itEnd; itBegin++)
  96. {
  97. CComBSTR bstr;
  98. __MPC_EXIT_IF_METHOD_FAILS(hr, (*itBegin)->get_Name( &bstr ));
  99. if(bstr == bstrName) break;
  100. }
  101. if(itBegin == itEnd)
  102. {
  103. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_FILE_NOT_FOUND);
  104. }
  105. else
  106. {
  107. __MPC_SET_ERROR_AND_EXIT(hr, (*itBegin)->QueryInterface( IID_IPCHDBDatabase, (void**)pVal ));
  108. }
  109. }
  110. hr = S_OK;
  111. __HCP_FUNC_CLEANUP;
  112. __HCP_FUNC_EXIT(hr);
  113. }
  114. ////////////////////////////////////////
  115. STDMETHODIMP JetBlueCOM::Session::BeginTransaction()
  116. {
  117. __HCP_FUNC_ENTRY( "JetBlueCOM::Session::BeginTransaction" );
  118. HRESULT hr;
  119. MPC::SmartLock<_ThreadModel> lock( this );
  120. hr = m_sess->BeginTransaction();
  121. __HCP_FUNC_EXIT(hr);
  122. }
  123. STDMETHODIMP JetBlueCOM::Session::CommitTransaction()
  124. {
  125. __HCP_FUNC_ENTRY( "JetBlueCOM::Session::CommitTransaction" );
  126. HRESULT hr;
  127. MPC::SmartLock<_ThreadModel> lock( this );
  128. hr = m_sess->CommitTransaction();
  129. __HCP_FUNC_EXIT(hr);
  130. }
  131. STDMETHODIMP JetBlueCOM::Session::RollbackTransaction()
  132. {
  133. __HCP_FUNC_ENTRY( "JetBlueCOM::Session::RollbackTransaction" );
  134. HRESULT hr;
  135. MPC::SmartLock<_ThreadModel> lock( this );
  136. hr = m_sess->RollbackTransaction();
  137. __HCP_FUNC_EXIT(hr);
  138. }
  139. #endif