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.

492 lines
13 KiB

  1. /******************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. Config.cpp
  5. Abstract:
  6. This file contains the implementation of the JetBlue::*Definition classes.
  7. Revision History:
  8. Davide Massarenti (Dmassare) 05/17/2000
  9. created
  10. ******************************************************************************/
  11. #include <stdafx.h>
  12. /////////////////////////////////////////////////////////////////////////////
  13. CFG_BEGIN_FIELDS_MAP(JetBlue::ColumnDefinition)
  14. CFG_ATTRIBUTE( L"TYPE" , DWORD , m_dwColTyp ),
  15. CFG_ATTRIBUTE( L"GRBITS" , DWORD , m_dwGRBits ),
  16. CFG_ATTRIBUTE( L"CODEPAGE", DWORD , m_dwCodePage ),
  17. CFG_ATTRIBUTE( L"MAX" , DWORD , m_dwMax ),
  18. CFG_VALUE ( string, m_strName ),
  19. CFG_END_FIELDS_MAP()
  20. CFG_BEGIN_CHILD_MAP(JetBlue::ColumnDefinition)
  21. CFG_END_CHILD_MAP()
  22. DEFINE_CFG_OBJECT(JetBlue::ColumnDefinition,L"COLUMN")
  23. DEFINE_CONFIG_METHODS__NOCHILD(JetBlue::ColumnDefinition)
  24. ////////////////////
  25. CFG_BEGIN_FIELDS_MAP(JetBlue::IndexDefinition)
  26. CFG_ATTRIBUTE( L"NAME" , string, m_strName ),
  27. CFG_ATTRIBUTE( L"GRBITS" , DWORD , m_dwGRBits ),
  28. CFG_ATTRIBUTE( L"DENSITY" , DWORD , m_dwDensity ),
  29. CFG_VALUE ( string, m_strCols ),
  30. CFG_END_FIELDS_MAP()
  31. CFG_BEGIN_CHILD_MAP(JetBlue::IndexDefinition)
  32. CFG_END_CHILD_MAP()
  33. DEFINE_CFG_OBJECT(JetBlue::IndexDefinition,L"INDEX")
  34. DEFINE_CONFIG_METHODS__NOCHILD(JetBlue::IndexDefinition)
  35. ////////////////////
  36. CFG_BEGIN_FIELDS_MAP(JetBlue::TableDefinition)
  37. CFG_ATTRIBUTE( L"NAME" , string, m_strName ),
  38. CFG_ATTRIBUTE( L"PAGES" , DWORD , m_dwPages ),
  39. CFG_ATTRIBUTE( L"DENSITY", DWORD , m_dwDensity ),
  40. CFG_END_FIELDS_MAP()
  41. CFG_BEGIN_CHILD_MAP(JetBlue::TableDefinition)
  42. CFG_CHILD(JetBlue::ColumnDefinition)
  43. CFG_CHILD(JetBlue::IndexDefinition)
  44. CFG_END_CHILD_MAP()
  45. DEFINE_CFG_OBJECT(JetBlue::TableDefinition,L"TABLE")
  46. DEFINE_CONFIG_METHODS_CREATEINSTANCE_SECTION(JetBlue::TableDefinition,tag,defSubType)
  47. if(tag == _cfg_table_tags[0])
  48. {
  49. defSubType = &(*(m_lstColumns.insert( m_lstColumns.end() )));
  50. return S_OK;
  51. }
  52. else if(tag == _cfg_table_tags[1])
  53. {
  54. defSubType = &(*(m_lstIndexes.insert( m_lstIndexes.end() )));
  55. return S_OK;
  56. }
  57. DEFINE_CONFIG_METHODS_SAVENODE_SECTION(JetBlue::TableDefinition,xdn)
  58. if(SUCCEEDED(hr = MPC::Config::SaveList( m_lstColumns, xdn )))
  59. {
  60. hr = MPC::Config::SaveList( m_lstIndexes, xdn );
  61. }
  62. DEFINE_CONFIG_METHODS_END(JetBlue::TableDefinition)
  63. /////////////////////////////////////////////////////////////////////////////
  64. /////////////////////////////////////////////////////////////////////////////
  65. /////////////////////////////////////////////////////////////////////////////
  66. JetBlue::ColumnDefinition::ColumnDefinition()
  67. {
  68. // MPC::string m_strName;
  69. m_dwColTyp = JET_coltypLongText; // DWORD m_dwColTyp;
  70. m_dwGRBits = 0; // DWORD m_dwGRBits;
  71. m_dwCodePage = 1200; // DWORD m_dwCodePage;
  72. m_dwMax = 0; // DWORD m_dwMax;
  73. // CComVariant m_vDefault;
  74. }
  75. HRESULT JetBlue::ColumnDefinition::Parse( /*[in] */ Column& col )
  76. {
  77. __HCP_FUNC_ENTRY( "JetBlue::ColumnDefinition::Parse" );
  78. HRESULT hr;
  79. m_strName = col.m_strName;
  80. m_dwColTyp = col.m_coldef.coltyp;
  81. m_dwCodePage = col.m_coldef.cp;
  82. m_dwMax = col.m_coldef.cbMax;
  83. m_dwGRBits = col.m_coldef.grbit;
  84. hr = S_OK;
  85. __HCP_FUNC_EXIT(hr);
  86. }
  87. HRESULT JetBlue::ColumnDefinition::Generate( /*[out]*/ JET_COLUMNCREATE& col )
  88. {
  89. __HCP_FUNC_ENTRY( "JetBlue::ColumnDefinition::Generate" );
  90. HRESULT hr;
  91. ::ZeroMemory( &col, sizeof(col) );
  92. col.cbStruct = sizeof(JET_COLUMNCREATE);
  93. col.szColumnName = _strdup( m_strName.c_str() );
  94. col.coltyp = m_dwColTyp;
  95. col.cbMax = m_dwMax;
  96. col.grbit = m_dwGRBits;
  97. col.pvDefault = NULL;
  98. col.cbDefault = 0;
  99. col.cp = m_dwCodePage;
  100. col.columnid = 0;
  101. col.err = JET_errSuccess;
  102. if(col.szColumnName == NULL)
  103. {
  104. __MPC_SET_ERROR_AND_EXIT(hr, E_OUTOFMEMORY);
  105. }
  106. hr = S_OK;
  107. __HCP_FUNC_CLEANUP;
  108. __HCP_FUNC_EXIT(hr);
  109. }
  110. HRESULT JetBlue::ColumnDefinition::Release( /*[in]*/ JET_COLUMNCREATE& col )
  111. {
  112. __HCP_FUNC_ENTRY( "JetBlue::ColumnDefinition::Release" );
  113. HRESULT hr;
  114. if(col.szColumnName)
  115. {
  116. free( col.szColumnName );
  117. col.szColumnName = NULL;
  118. }
  119. hr = S_OK;
  120. __HCP_FUNC_EXIT(hr);
  121. }
  122. /////////////////////////////////////////////////////////////////////////////
  123. /////////////////////////////////////////////////////////////////////////////
  124. /////////////////////////////////////////////////////////////////////////////
  125. JetBlue::IndexDefinition::IndexDefinition()
  126. {
  127. // MPC::string m_strName;
  128. // MPC::string m_strCols;
  129. m_dwGRBits = 0; // DWORD m_dwGRBits;
  130. m_dwDensity = 100; // DWORD m_dwDensity;
  131. }
  132. HRESULT JetBlue::IndexDefinition::Parse( /*[in] */ Index& idx )
  133. {
  134. __HCP_FUNC_ENTRY( "JetBlue::IndexDefinition::Parse" );
  135. HRESULT hr;
  136. int iElem;
  137. int i;
  138. m_strName = idx.m_strName;
  139. m_strCols.erase();
  140. m_dwGRBits = idx.m_grbitIndex;
  141. m_dwDensity = 100; // ??
  142. iElem = idx.NumOfColumns();
  143. for(i=0; i<iElem; i++)
  144. {
  145. Column& col = idx.GetCol( i );
  146. if(i) m_strCols += ' ';
  147. m_strCols += (col.m_coldef.grbit & JET_bitKeyDescending) ? "-" : "+";
  148. m_strCols += col.m_strName;
  149. }
  150. hr = S_OK;
  151. __HCP_FUNC_EXIT(hr);
  152. }
  153. HRESULT JetBlue::IndexDefinition::Generate( /*[out]*/ JET_INDEXCREATE& idx )
  154. {
  155. __HCP_FUNC_ENTRY( "JetBlue::IndexDefinition::Generate" );
  156. HRESULT hr;
  157. Index obj;
  158. std::vector<MPC::string> vec;
  159. int iElem;
  160. int i;
  161. ::ZeroMemory( &idx, sizeof(idx) );
  162. idx.cbStruct = sizeof(JET_INDEXCREATE);
  163. idx.szIndexName = _strdup( m_strName.c_str() );
  164. idx.szKey = NULL;
  165. idx.cbKey = 0;
  166. idx.grbit = m_dwGRBits;
  167. idx.ulDensity = m_dwDensity;
  168. idx.pidxunicode = NULL;
  169. idx.cbVarSegMac = 0;
  170. idx.rgconditionalcolumn = NULL;
  171. idx.cConditionalColumn = 0;
  172. idx.err = JET_errSuccess;
  173. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::SplitAtDelimiter( vec, m_strCols.c_str(), " ", true, true ));
  174. iElem = vec.size();
  175. obj.m_vecColumns.resize( iElem );
  176. for(i=0; i<iElem; i++)
  177. {
  178. Column& col = obj.m_vecColumns[i];
  179. LPCSTR szCol = vec[i].c_str();
  180. JET_GRBIT grbit = JET_bitKeyAscending;
  181. switch(szCol[0])
  182. {
  183. case '-': grbit = JET_bitKeyDescending;
  184. case '+': szCol++;
  185. }
  186. col.m_strName = szCol;
  187. col.m_coldef.grbit = grbit;
  188. }
  189. __MPC_EXIT_IF_METHOD_FAILS(hr, obj.GenerateKey( idx.szKey, idx.cbKey ));
  190. hr = S_OK;
  191. __HCP_FUNC_CLEANUP;
  192. __HCP_FUNC_EXIT(hr);
  193. }
  194. HRESULT JetBlue::IndexDefinition::Release( /*[in]*/ JET_INDEXCREATE& idx )
  195. {
  196. __HCP_FUNC_ENTRY( "JetBlue::IndexDefinition::Release" );
  197. HRESULT hr;
  198. if(idx.szIndexName)
  199. {
  200. free( idx.szIndexName );
  201. idx.szIndexName = NULL;
  202. }
  203. if(idx.szKey)
  204. {
  205. delete [] idx.szKey;
  206. idx.szKey = NULL;
  207. idx.cbKey = 0;
  208. }
  209. hr = S_OK;
  210. __HCP_FUNC_EXIT(hr);
  211. }
  212. /////////////////////////////////////////////////////////////////////////////
  213. /////////////////////////////////////////////////////////////////////////////
  214. /////////////////////////////////////////////////////////////////////////////
  215. JetBlue::TableDefinition::TableDefinition()
  216. {
  217. // MPC::string m_strName;
  218. m_dwPages = 10; // DWORD m_dwPages;
  219. m_dwDensity = 80; // DWORD m_dwDensity;
  220. // ColumnList m_lstColumns;
  221. // IndexList m_lstIndexes;
  222. }
  223. ////////////////////////////////////////
  224. HRESULT JetBlue::TableDefinition::Load( /*[in]*/ LPCWSTR szFile )
  225. {
  226. __HCP_FUNC_ENTRY( "JetBlue::TableDefinition::Load" );
  227. HRESULT hr;
  228. m_strName.erase();
  229. m_dwPages = 10;
  230. m_dwDensity = 80;
  231. m_lstColumns.clear();
  232. m_lstIndexes.clear();
  233. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::Config::LoadFile( this, szFile ));
  234. hr = S_OK;
  235. __MPC_FUNC_CLEANUP;
  236. __MPC_FUNC_EXIT(hr);
  237. }
  238. HRESULT JetBlue::TableDefinition::Save( /*[in]*/ LPCWSTR szFile )
  239. {
  240. __HCP_FUNC_ENTRY( "JetBlue::TableDefinition::Save" );
  241. HRESULT hr;
  242. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::Config::SaveFile( this, szFile ));
  243. hr = S_OK;
  244. __MPC_FUNC_CLEANUP;
  245. __MPC_FUNC_EXIT(hr);
  246. }
  247. ////////////////////////////////////////
  248. HRESULT JetBlue::TableDefinition::Parse( /*[in] */ Table& tbl )
  249. {
  250. __HCP_FUNC_ENTRY( "JetBlue::TableDefinition::Parse" );
  251. HRESULT hr;
  252. int i;
  253. int iNum;
  254. m_strName = tbl.m_strName;
  255. m_dwPages = 0; // ??
  256. m_dwDensity = 80; // ??
  257. m_lstColumns.clear();
  258. m_lstIndexes.clear();
  259. for(iNum=tbl.NumOfColumns(),i=0; i<iNum; i++)
  260. {
  261. ColDefIter it = m_lstColumns.insert( m_lstColumns.end() );
  262. __MPC_EXIT_IF_METHOD_FAILS(hr, it->Parse( tbl.GetCol( i ) ));
  263. }
  264. for(iNum=tbl.NumOfIndexes(),i=0; i<iNum; i++)
  265. {
  266. IdxDefIter it = m_lstIndexes.insert( m_lstIndexes.end() );
  267. __MPC_EXIT_IF_METHOD_FAILS(hr, it->Parse( tbl.GetIdx( i ) ));
  268. }
  269. hr = S_OK;
  270. __HCP_FUNC_CLEANUP;
  271. __HCP_FUNC_EXIT(hr);
  272. }
  273. HRESULT JetBlue::TableDefinition::Generate( /*[out]*/ JET_TABLECREATE& tbl )
  274. {
  275. __HCP_FUNC_ENTRY( "JetBlue::TableDefinition::Generate" );
  276. HRESULT hr;
  277. ColDefIter itCol;
  278. IdxDefIter itIdx;
  279. int i;
  280. ::ZeroMemory( &tbl, sizeof(tbl) );
  281. tbl.cbStruct = sizeof(JET_TABLECREATE);
  282. tbl.szTableName = _strdup( m_strName.c_str() );
  283. tbl.szTemplateTableName = NULL;
  284. tbl.ulPages = m_dwPages;
  285. tbl.ulDensity = m_dwDensity;
  286. tbl.cColumns = m_lstColumns.size();
  287. tbl.rgcolumncreate = new JET_COLUMNCREATE[tbl.cColumns];
  288. tbl.cIndexes = m_lstIndexes.size();
  289. tbl.rgindexcreate = new JET_INDEXCREATE[tbl.cIndexes];
  290. tbl.grbit = 0;
  291. tbl.tableid = JET_tableidNil;
  292. tbl.cCreated = 0;
  293. if(tbl.rgcolumncreate) ::ZeroMemory( tbl.rgcolumncreate, sizeof(JET_COLUMNCREATE) * tbl.cColumns );
  294. if(tbl.rgindexcreate ) ::ZeroMemory( tbl.rgindexcreate , sizeof(JET_INDEXCREATE ) * tbl.cIndexes );
  295. if(tbl.szTableName == NULL ||
  296. tbl.rgcolumncreate == NULL ||
  297. tbl.rgindexcreate == NULL )
  298. {
  299. __MPC_SET_ERROR_AND_EXIT(hr, E_OUTOFMEMORY);
  300. }
  301. for(i=0, itCol = m_lstColumns.begin(); itCol != m_lstColumns.end(); itCol++, i++)
  302. {
  303. __MPC_EXIT_IF_METHOD_FAILS(hr, itCol->Generate( tbl.rgcolumncreate[ i ] ));
  304. }
  305. for(i=0, itIdx = m_lstIndexes.begin(); itIdx != m_lstIndexes.end(); itIdx++, i++)
  306. {
  307. __MPC_EXIT_IF_METHOD_FAILS(hr, itIdx->Generate( tbl.rgindexcreate[ i ] ));
  308. }
  309. hr = S_OK;
  310. __HCP_FUNC_CLEANUP;
  311. __HCP_FUNC_EXIT(hr);
  312. }
  313. HRESULT JetBlue::TableDefinition::Release( /*[in]*/ JET_TABLECREATE& tbl )
  314. {
  315. __HCP_FUNC_ENTRY( "JetBlue::TableDefinition::Release" );
  316. HRESULT hr;
  317. ColDefIter itCol;
  318. IdxDefIter itIdx;
  319. int i;
  320. if(tbl.szTableName)
  321. {
  322. free( tbl.szTableName );
  323. tbl.szTableName = NULL;
  324. }
  325. if(tbl.rgcolumncreate)
  326. {
  327. for(i=0, itCol = m_lstColumns.begin(); itCol != m_lstColumns.end(); itCol++, i++)
  328. {
  329. __MPC_EXIT_IF_METHOD_FAILS(hr, itCol->Release( tbl.rgcolumncreate[ i ] ));
  330. }
  331. delete [] tbl.rgcolumncreate; tbl.rgcolumncreate = NULL;
  332. }
  333. if(tbl.rgindexcreate)
  334. {
  335. for(i=0, itIdx = m_lstIndexes.begin(); itIdx != m_lstIndexes.end(); itIdx++, i++)
  336. {
  337. __MPC_EXIT_IF_METHOD_FAILS(hr, itIdx->Release( tbl.rgindexcreate[ i ] ));
  338. }
  339. delete [] tbl.rgindexcreate; tbl.rgindexcreate = NULL;
  340. }
  341. hr = S_OK;
  342. __HCP_FUNC_CLEANUP;
  343. __HCP_FUNC_EXIT(hr);
  344. }