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.

228 lines
5.0 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // objcmd.h
  8. //
  9. // SYNOPSIS
  10. //
  11. // This file defines commands for manipulating the Objects table.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 02/20/1998 Original version.
  16. // 04/03/1998 Bind integers as DBTYPE_I4.
  17. // Add PARAMETERS clause to all commands.
  18. // 02/15/1999 Make commands MT safe.
  19. //
  20. ///////////////////////////////////////////////////////////////////////////////
  21. #ifndef _OBJCMD_H_
  22. #define _OBJCMD_H_
  23. #include <cmdbase.h>
  24. #include <rowset.h>
  25. //////////
  26. // The width of the Name column including null-terminator (i.e., the Jet
  27. // column size + 1).
  28. //////////
  29. const size_t OBJECT_NAME_LENGTH = 256;
  30. //////////
  31. // Command to find all the members of a container.
  32. //////////
  33. class FindMembers : public CommandBase
  34. {
  35. public:
  36. void execute(ULONG parentKey, IRowset** members)
  37. {
  38. _serialize
  39. parent = parentKey;
  40. CommandBase::execute(__uuidof(IRowset), (IUnknown**)members);
  41. }
  42. PCWSTR getCommandText() const throw ()
  43. {
  44. return L"PARAMETERS X LONG;"
  45. L"SELECT Identity, Name FROM Objects WHERE Parent = X;";
  46. }
  47. protected:
  48. ULONG parent;
  49. BEGIN_BIND_MAP(FindMembers, ParamIO, DBACCESSOR_PARAMETERDATA)
  50. BIND_COLUMN(parent, 1, DBTYPE_I4),
  51. END_BIND_MAP()
  52. };
  53. //////////
  54. // Base class for commands that key off the parent and the name. This is
  55. // similar to the "one level" scope in LDAP.
  56. //////////
  57. class OneLevel : public CommandBase
  58. {
  59. public:
  60. void execute(ULONG parentKey, PCWSTR nameKey)
  61. {
  62. _serialize
  63. parent = parentKey;
  64. wcsncpy(name, nameKey, sizeof(name)/sizeof(WCHAR));
  65. CommandBase::execute();
  66. }
  67. protected:
  68. ULONG parent;
  69. WCHAR name[OBJECT_NAME_LENGTH];
  70. BEGIN_BIND_MAP(OneLevel, ParamIO, DBACCESSOR_PARAMETERDATA)
  71. BIND_COLUMN(parent, 1, DBTYPE_I4),
  72. BIND_COLUMN(name, 2, DBTYPE_WSTR)
  73. END_BIND_MAP()
  74. };
  75. //////////
  76. // Creates a new object in a container.
  77. //////////
  78. class CreateObject : public OneLevel
  79. {
  80. public:
  81. PCWSTR getCommandText() const throw ()
  82. {
  83. return L"PARAMETERS X LONG, Y TEXT;"
  84. L"INSERT INTO Objects (Parent, Name) VALUES (X, Y);";
  85. }
  86. };
  87. //////////
  88. // Destroys an object in a container.
  89. //////////
  90. class DestroyObject : public OneLevel
  91. {
  92. public:
  93. PCWSTR getCommandText() const throw ()
  94. {
  95. return L"PARAMETERS X LONG, Y TEXT;"
  96. L"DELETE FROM Objects WHERE Parent = X AND Name = Y;";
  97. }
  98. };
  99. //////////
  100. // Finds an object in a container and returns its identity.
  101. //////////
  102. class FindObject : public OneLevel
  103. {
  104. public:
  105. ~FindObject()
  106. {
  107. finalize();
  108. }
  109. ULONG execute(ULONG parentKey, PCWSTR nameKey)
  110. {
  111. _serialize
  112. // Load the parameters.
  113. parent = parentKey;
  114. wcsncpy(name, nameKey, sizeof(name)/sizeof(WCHAR));
  115. // Execute the command and get the answer set.
  116. Rowset rowset;
  117. CommandBase::execute(__uuidof(IRowset), (IUnknown**)&rowset);
  118. // Did we get anything?
  119. if (rowset.moveNext())
  120. {
  121. // Yes, so load the identity.
  122. rowset.getData(readAccess, this);
  123. // We should retrieved at most one record.
  124. _ASSERT(!rowset.moveNext());
  125. return identity;
  126. }
  127. // Zero represents 'not found'. I didn't want to throw an exception,
  128. // since this isn't very exceptional.
  129. return 0;
  130. }
  131. PCWSTR getCommandText() const throw ()
  132. {
  133. return L"PARAMETERS X LONG, Y TEXT;"
  134. L"SELECT Identity FROM Objects WHERE Parent = X AND Name = Y;";
  135. }
  136. void initialize(IUnknown* session)
  137. {
  138. OneLevel::initialize(session);
  139. readAccess = createReadAccessor(command);
  140. }
  141. void finalize() throw ()
  142. {
  143. releaseAccessor(readAccess);
  144. OneLevel::finalize();
  145. }
  146. protected:
  147. HACCESSOR readAccess;
  148. ULONG identity;
  149. BEGIN_BIND_MAP(FindObject, ReadAccessor, DBACCESSOR_ROWDATA)
  150. BIND_COLUMN(identity, 1, DBTYPE_I4),
  151. END_BIND_MAP()
  152. };
  153. //////////
  154. // Updates the Name and Parent of an object.
  155. //////////
  156. class UpdateObject : public CommandBase
  157. {
  158. public:
  159. void execute(ULONG identityKey, PCWSTR nameValue, ULONG parentValue)
  160. {
  161. _serialize
  162. parent = parentValue;
  163. wcsncpy(name, nameValue, sizeof(name)/sizeof(WCHAR));
  164. identity = identityKey;
  165. CommandBase::execute();
  166. }
  167. PCWSTR getCommandText() const throw ()
  168. {
  169. return L"PARAMETERS X LONG, Y TEXT, Z LONG;"
  170. L"UPDATE Objects SET Parent = X, Name = Y WHERE Identity = Z;";
  171. }
  172. protected:
  173. ULONG parent;
  174. WCHAR name[OBJECT_NAME_LENGTH];
  175. ULONG identity;
  176. BEGIN_BIND_MAP(UpdateObject, ParamIO, DBACCESSOR_PARAMETERDATA)
  177. BIND_COLUMN(parent, 1, DBTYPE_I4),
  178. BIND_COLUMN(name, 2, DBTYPE_WSTR),
  179. BIND_COLUMN(identity, 3, DBTYPE_I4)
  180. END_BIND_MAP()
  181. };
  182. #endif // _OBJCMD_H_