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.

219 lines
5.1 KiB

  1. /******************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. Database.cpp
  5. Abstract:
  6. This file contains the implementation of the JetBlueCOM::Database class.
  7. Revision History:
  8. Davide Massarenti (Dmassare) 05/20/2000
  9. created
  10. ******************************************************************************/
  11. #include <stdafx.h>
  12. #ifndef NOJETBLUECOM
  13. ////////////////////////////////////////////////////////////////////////////////
  14. JetBlueCOM::Database::Database()
  15. {
  16. m_db = NULL; // JetBlue::Database* m_db;
  17. // BaseObjectWithChildren<Database,Table> m_Tables;
  18. }
  19. JetBlueCOM::Database::~Database()
  20. {
  21. Passivate();
  22. }
  23. HRESULT JetBlueCOM::Database::Refresh()
  24. {
  25. __HCP_FUNC_ENTRY( "JetBlueCOM::Database::Refresh" );
  26. HRESULT hr;
  27. int iTbl = m_db->NumOfTables();
  28. int i;
  29. m_Tables.Passivate();
  30. for(i=0; i<iTbl; i++)
  31. {
  32. CComPtr<Table> child;
  33. JetBlue::Table* tbl = m_db->GetTbl( i );
  34. __MPC_EXIT_IF_METHOD_FAILS(hr, tbl->Open());
  35. __MPC_EXIT_IF_METHOD_FAILS(hr, m_Tables.CreateChild( this, &child ));
  36. __MPC_EXIT_IF_METHOD_FAILS(hr, child->Initialize( *tbl ));
  37. }
  38. hr = S_OK;
  39. __HCP_FUNC_CLEANUP;
  40. __HCP_FUNC_EXIT(hr);
  41. }
  42. ////////////////////////////////////////
  43. HRESULT JetBlueCOM::Database::Initialize( /*[in]*/ JetBlue::Database& db )
  44. {
  45. __HCP_FUNC_ENTRY( "JetBlueCOM::Database::Initialize" );
  46. HRESULT hr;
  47. m_db = &db;
  48. hr = Refresh();
  49. __HCP_FUNC_EXIT(hr);
  50. }
  51. void JetBlueCOM::Database::Passivate()
  52. {
  53. MPC::SmartLock<_ThreadModel> lock( this );
  54. m_db = NULL;
  55. m_Tables.Passivate();
  56. }
  57. ////////////////////////////////////////
  58. STDMETHODIMP JetBlueCOM::Database::get_Name( /*[out, retval]*/ BSTR *pVal )
  59. {
  60. __HCP_FUNC_ENTRY( "JetBlueCOM::Database::get_Name" );
  61. USES_CONVERSION;
  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. __MPC_JET_CHECKHANDLE(hr,m_db,NULL);
  68. {
  69. const MPC::string& str = *m_db;
  70. hr = MPC::GetBSTR( A2W(str.c_str()), pVal );
  71. }
  72. __HCP_FUNC_CLEANUP;
  73. __HCP_FUNC_EXIT(hr);
  74. }
  75. STDMETHODIMP JetBlueCOM::Database::get_Tables( /*[out, retval]*/ IPCHDBCollection* *pVal )
  76. {
  77. __HCP_FUNC_ENTRY( "JetBlueCOM::Database::get_Tables" );
  78. HRESULT hr;
  79. MPC::SmartLock<_ThreadModel> lock( this );
  80. __MPC_PARAMCHECK_BEGIN(hr)
  81. __MPC_PARAMCHECK_POINTER_AND_SET(pVal,NULL);
  82. __MPC_PARAMCHECK_END();
  83. __MPC_JET_CHECKHANDLE(hr,m_db,NULL);
  84. hr = m_Tables.GetEnumerator( pVal );
  85. __HCP_FUNC_CLEANUP;
  86. __HCP_FUNC_EXIT(hr);
  87. }
  88. ////////////////////////////////////////
  89. STDMETHODIMP JetBlueCOM::Database::AttachTable( /*[in]*/ BSTR bstrName ,
  90. /*[in, optional]*/ VARIANT vXMLDef ,
  91. /*[out,retval] */ IPCHDBTable* *pVal )
  92. {
  93. __HCP_FUNC_ENTRY( "JetBlueCOM::Database::DeleteRecord" );
  94. USES_CONVERSION;
  95. HRESULT hr;
  96. MPC::SmartLock<_ThreadModel> lock( this );
  97. JET_TABLECREATE tblcrt; ::ZeroMemory( &tblcrt, sizeof(tblcrt) );
  98. JetBlue::TableDefinition tbldef;
  99. JetBlue::Table* table;
  100. LPSTR szName;
  101. __MPC_PARAMCHECK_BEGIN(hr)
  102. __MPC_PARAMCHECK_STRING_NOT_EMPTY(bstrName);
  103. __MPC_PARAMCHECK_POINTER_AND_SET(pVal,NULL);
  104. __MPC_PARAMCHECK_END();
  105. __MPC_JET_CHECKHANDLE(hr,m_db,NULL);
  106. szName = W2A( bstrName );
  107. if(vXMLDef.vt == VT_BSTR && vXMLDef.bstrVal)
  108. {
  109. __MPC_EXIT_IF_METHOD_FAILS(hr, tbldef.Load( vXMLDef.bstrVal ));
  110. __MPC_EXIT_IF_METHOD_FAILS(hr, tbldef.Generate( tblcrt ));
  111. tblcrt.szTableName = szName;
  112. __MPC_EXIT_IF_METHOD_FAILS(hr, m_db->GetTable( NULL, table, &tblcrt ));
  113. __MPC_EXIT_IF_METHOD_FAILS(hr, Refresh());
  114. }
  115. else
  116. {
  117. __MPC_EXIT_IF_METHOD_FAILS(hr, m_db->GetTable( szName, table ));
  118. }
  119. {
  120. BaseObjectWithChildren<Database,Table>::ChildIterConst itBegin;
  121. BaseObjectWithChildren<Database,Table>::ChildIterConst itEnd;
  122. m_Tables.GetChildren( itBegin, itEnd );
  123. for(;itBegin != itEnd; itBegin++)
  124. {
  125. CComBSTR bstr;
  126. __MPC_EXIT_IF_METHOD_FAILS(hr, (*itBegin)->get_Name( &bstr ));
  127. if(bstr == bstrName) break;
  128. }
  129. if(itBegin == itEnd)
  130. {
  131. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_FILE_NOT_FOUND);
  132. }
  133. else
  134. {
  135. __MPC_SET_ERROR_AND_EXIT(hr, (*itBegin)->QueryInterface( IID_IPCHDBTable, (void**)pVal ));
  136. }
  137. }
  138. hr = S_OK;
  139. __HCP_FUNC_CLEANUP;
  140. (void)tbldef.Release( tblcrt );
  141. __HCP_FUNC_EXIT(hr);
  142. }
  143. #endif