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.

217 lines
7.3 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. Wsbdb.h
  5. Abstract:
  6. These classes provide support for data bases.
  7. Author:
  8. Ron White [ronw] 19-Nov-1996
  9. Revision History:
  10. --*/
  11. #ifndef _WSBDB_
  12. #define _WSBDB_
  13. // Are we defining imports or exports?
  14. #if defined(IDB_IMPL)
  15. #define IDB_EXPORT __declspec(dllexport)
  16. #else
  17. #define IDB_EXPORT __declspec(dllimport)
  18. #endif
  19. #include "wsbdef.h"
  20. #include "wsbdbent.h"
  21. #define IDB_MAX_REC_TYPES 16
  22. #define IDB_MAX_KEYS_PER_REC 10
  23. // Maximum key size in bytes; Jet limit is currently 255 so we limit
  24. // all implementations
  25. #define IDB_MAX_KEY_SIZE 255
  26. // IDB_SYS_INIT_FLAG_* flags for use with IWsbDbSys::Init
  27. #define IDB_SYS_INIT_FLAG_FULL_LOGGING 0x00000000 // I.e. the default
  28. #define IDB_SYS_INIT_FLAG_LIMITED_LOGGING 0x00000001
  29. #define IDB_SYS_INIT_FLAG_SPECIAL_ERROR_MSG 0x00000002
  30. #define IDB_SYS_INIT_FLAG_NO_BACKUP 0x00000004
  31. #define IDB_SYS_INIT_FLAG_NO_LOGGING 0x00000008
  32. // IDB_CREATE_FLAG_* flags for use with IWsbDb::Create
  33. #define IDB_CREATE_FLAG_NO_TRANSACTION 0x00000001
  34. #define IDB_CREATE_FLAG_FIXED_SCHEMA 0x00000002
  35. // IDB_DELETE_FLAG_* flags for use with IWsbDb::Delete
  36. #define IDB_DELETE_FLAG_NO_ERROR 0x00000001
  37. // IDB_DUMP_FLAG_* flags for use with IWsbDB::Dump
  38. #define IDB_DUMP_FLAG_DB_INFO 0x00000001
  39. #define IDB_DUMP_FLAG_REC_INFO 0x00000002
  40. #define IDB_DUMP_FLAG_KEY_INFO 0x00000004
  41. #define IDB_DUMP_FLAG_RECORDS 0x00000008
  42. #define IDB_DUMP_FLAG_EVERYTHING 0x0000000F
  43. #define IDB_DUMP_FLAG_RECORD_TYPE 0x00000010
  44. #define IDB_DUMP_FLAG_APPEND_TO_FILE 0x00000100
  45. // IDB_KEY_FLAG_* flags for use in IDB_KEY_INFO structure:
  46. #define IDB_KEY_FLAG_DUP_ALLOWED 0x00000001 // Duplicate keys allowed
  47. #define IDB_KEY_FLAG_PRIMARY 0x00000002 // Primary key
  48. // IDB_KEY_INFO - data about record keys
  49. // Note: Only one key per record type can be a primary key. The primary
  50. // key can not be modified in a record. In general, the primary key is
  51. // used for the physical clustering of the records in the DB.
  52. typedef struct : _COM_IDB_KEY_INFO {
  53. // ULONG Type; // Key type ID; must be > 0
  54. // ULONG Size; // Key size in bytes
  55. // ULONG Flags; // IDB_KEY_FLAG_* values
  56. } IDB_KEY_INFO;
  57. // IDB_REC_FLAG_* flags for use in IDB_REC_INFO structur
  58. #define IDB_REC_FLAG_VARIABLE 0x00000001 // Record size is not fixed
  59. // IDB_REC_INFO - data about IDB records
  60. // Note: It there are multiple keys, the first key is taken as the
  61. // default key to use for a new entity created by GetEntity.
  62. typedef struct : _COM_IDB_REC_INFO {
  63. IDB_KEY_INFO *Key; // Key info (must be allocated by derived DB object)
  64. } IDB_REC_INFO;
  65. // IDB_BACKUP_FLAG_* flags for use with IWsbDbSys::Backup
  66. #define IDB_BACKUP_FLAG_AUTO 0x00000001 // Start auto backup thread
  67. #define IDB_BACKUP_FLAG_FORCE_FULL 0x00000002 // Force a full backup
  68. /*++
  69. Class Name:
  70. CWsbDb
  71. Class Description:
  72. The base class for a data base object.
  73. --*/
  74. class IDB_EXPORT CWsbDb :
  75. public CWsbPersistable,
  76. public IWsbDbPriv
  77. {
  78. public:
  79. // CComObjectRoot
  80. public:
  81. STDMETHOD(FinalConstruct)(void);
  82. void FinalRelease(void);
  83. // IPersist
  84. public:
  85. STDMETHOD(GetClassID)(LPCLSID pclsid);
  86. // IPersistStream
  87. public:
  88. STDMETHOD(GetSizeMax)(ULARGE_INTEGER* /*pSize*/) {
  89. return(E_NOTIMPL); }
  90. STDMETHOD(Load)(IStream* pStream);
  91. STDMETHOD(Save)(IStream* pStream, BOOL clearDirty);
  92. // IWsbDb
  93. public:
  94. STDMETHOD(Close)(IWsbDbSession* pSession);
  95. STDMETHOD(Create)(OLECHAR* path, ULONG flags = 0);
  96. STDMETHOD(Delete)(OLECHAR* path, ULONG flags = 0);
  97. STDMETHOD(Dump)(OLECHAR* Filename, ULONG Flags, ULONG Data);
  98. STDMETHOD(GetEntity)(IWsbDbSession* pSession, ULONG RecId, REFIID riid, void** ppEntity);
  99. STDMETHOD(GetName)(OLECHAR** /*pName*/) { return(E_NOTIMPL); }
  100. STDMETHOD(GetPath)(OLECHAR** /*pPath*/) { return(E_NOTIMPL); }
  101. STDMETHOD(GetVersion)(ULONG* /*pVer*/) { return(E_NOTIMPL); }
  102. STDMETHOD(Locate)(OLECHAR* path);
  103. STDMETHOD(Open)(IWsbDbSession** ppSession);
  104. // IWsbDbPriv - For internal use only!
  105. STDMETHOD(GetKeyInfo)(ULONG RecType, USHORT nKeys, COM_IDB_KEY_INFO* pKeyInfo);
  106. STDMETHOD(GetRecInfo)(ULONG RecType, COM_IDB_REC_INFO* pRecInfo);
  107. STDMETHOD(Lock)(void) { CWsbPersistable::Lock(); return(S_OK); }
  108. STDMETHOD(Unlock)(void) { CWsbPersistable::Unlock(); return(S_OK); }
  109. STDMETHOD(GetJetIds)(JET_SESID SessionId, ULONG RecType,
  110. JET_TABLEID* pTableId, ULONG* pDataColId);
  111. STDMETHOD(GetJetIndexInfo)(JET_SESID SessionId, ULONG RecType, ULONG KeyType,
  112. ULONG* pColId, OLECHAR** pName, ULONG bufferSize);
  113. STDMETHOD(GetNewSQN)(ULONG /*RecType*/, ULONG* /*pSeqNum*/)
  114. { return(E_NOTIMPL); }
  115. private:
  116. HRESULT db_info_from_file_block(void* block);
  117. HRESULT db_info_to_file_block(void* block);
  118. HRESULT rec_info_from_file_block(int index, void* block);
  119. HRESULT rec_info_to_file_block(int index, void* block);
  120. HRESULT session_current_index(IWsbDbSession* pSession);
  121. HRESULT jet_init(void);
  122. HRESULT jet_make_index_name(ULONG key_type, char* pName, ULONG bufsize);
  123. HRESULT jet_make_table_name(ULONG rec_type, char* pName, ULONG bufsize);
  124. HRESULT jet_load_info(void);
  125. HRESULT jet_save_info(void);
  126. protected:
  127. // Values to be supplied by derived class:
  128. CComPtr<IWsbDbSys> m_pWsbDbSys; // Strong reference to DbSys object - ensures that
  129. // this object dies after the DBs
  130. // Note: CWsbDbSys must NOT have strong reference to
  131. // objects of this class (WsbDb)
  132. ULONG m_version; // DB version
  133. USHORT m_nRecTypes; // Number of record (object) types
  134. IDB_REC_INFO* m_RecInfo; // Record/key info (must be allocated
  135. // by derived DB object)
  136. // Not to be changed by derived class:
  137. CWsbStringPtr m_path;
  138. void * m_pImp; // Secret stuff
  139. ULONG m_SessionIndex;
  140. };
  141. #define WSB_FROM_CWSBDB \
  142. STDMETHOD(Close)(IWsbDbSession* pSession) \
  143. {return(CWsbDb::Close(pSession));} \
  144. STDMETHOD(Create)(OLECHAR* path, ULONG flags = 0) \
  145. {return(CWsbDb::Create(path, flags));} \
  146. STDMETHOD(Delete)(OLECHAR* path, ULONG flags = 0) \
  147. {return(CWsbDb::Delete(path, flags));} \
  148. STDMETHOD(Dump)(OLECHAR* Filename, ULONG Flags, ULONG Data) \
  149. {return(CWsbDb::Dump(Filename, Flags, Data));} \
  150. STDMETHOD(GetEntity)(IWsbDbSession* pSession, ULONG RecId, REFIID riid, void** ppEntity) \
  151. {return(CWsbDb::GetEntity(pSession, RecId, riid, ppEntity));} \
  152. STDMETHOD(GetName)(OLECHAR** pName) \
  153. {return(CWsbDb::GetName(pName)); } \
  154. STDMETHOD(GetPath)(OLECHAR** pPath) \
  155. {return(CWsbDb::GetPath(pPath)); } \
  156. STDMETHOD(GetVersion)(ULONG* pVer) \
  157. {return(CWsbDb::GetVersion(pVer)); } \
  158. STDMETHOD(Locate)(OLECHAR* path) \
  159. {return(CWsbDb::Locate(path));} \
  160. STDMETHOD(Open)(IWsbDbSession** ppSession) \
  161. {return(CWsbDb::Open(ppSession));} \
  162. #endif // _WSBDB_