Products Support Documentation Download
cpp-db.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2  * Raima Database Manager
3  *
4  * Copyright (c) 2011 Raima Inc., All rights reserved.
5  *
6  * Use of this software, whether in source code format, or in executable,
7  * binary object code form, is governed by the Birdstep LICENSE which
8  * is fully described in the LICENSE.TXT file, included within this
9  * distribution of files.
10  * ----------------------------------------------------------------------------
11  */
12 
17 #if !defined(CPP_DB_H_INCLUDED_)
18 #define CPP_DB_H_INCLUDED_
19 
20 #if !defined(__cplusplus)
21 #error cpp-db.h is only for C++ applications. Do not include it in C applications
22 #endif
23 
24 #include "rdmtypes.h"
25 #include "rdmrowidtypes.h"
26 #if !defined(RDM_NO_CPP_STD_STRING)
27 #include <string>
28 #endif
29 
32 namespace RDM_CPP {
33 
34  class TFS;
35  class Transaction;
36  class IDb;
37  class Cursor;
38  typedef const void *dbType;
39  class Db;
40 } // namespace RDM_CPP
41 
52 class RDM_PUBLIC_CLASS RDM_CPP::Db
53 {
54  public:
55  /* Handle more than one reference to the underlying database */
56 
68  Db (void) throw ();
69 
81  Db (const Db &db) throw ();
82 
94  Db &operator= (const Db &db) throw ();
95 
110  TFS GetTFS (void);
111 
127  void DeleteAllRows (void) const;
128 
144  void DeleteAllRows (RDM_TABLE_ID tableId) const;
145 
159  void SetOptions (const char *optString) const;
160 #if !defined(RDM_NO_CPP_STD_STRING)
161  void SetOptions (const std::string &optString) const;
162 #endif
163  void SetOption (const char *option, const char *value) const;
164 #if !defined(RDM_NO_CPP_STD_STRING)
165  void SetOption (const std::string &option, const std::string &value) const;
166 #endif
167 
168 #if defined(RDM_UNICODE)
169 
171  void SetOptions (const wchar_t *optString) const;
172 #if !defined(RDM_NO_CPP_STD_STRING)
173  void SetOptions (const std::wstring &optString) const;
174 #endif
175  void SetOption (const wchar_t *option, const wchar_t *value) const;
176 #if !defined(RDM_NO_CPP_STD_STRING)
177  void SetOption (const std::wstring &option, const std::wstring &value) const;
178 #endif
179 #endif
180 
199  Transaction StartRead (
200  const RDM_TABLE_ID tableIds[] =
201  NULL,
202  uint32_t num = 0
203  ) const;
204 
227  Transaction StartUpdate (
228  const RDM_TABLE_ID writeTableIds[],
230  uint32_t numWriteTableIds,
231  const RDM_TABLE_ID readTableIds[] =
232  NULL,
233  uint32_t numReadTableIds =
234  0
235  ) const;
236 
239  Transaction StartUpdate (
240  const RDM_TABLE_ID writeTableIds[] =
241  NULL,
242  const RDM_TABLE_ID readTableIds[] =
243  NULL,
244  uint32_t numReadTableIds =
245  0
246  ) const;
247 
261  Transaction StartSnapshot (
262  const RDM_TABLE_ID tableIds[] =
263  NULL,
264  uint32_t num = 0
265  ) const;
266 
290  void Precommit (void) const;
291 
309  void End (void) const;
310 
324  void EndRollback (void) const;
325 
336  RDM_TRANS_STATUS GetTransactionStatus (void) const;
337 
350  bool IsOpenedExclusive (void) const;
351 
364  bool IsOpenedShared (void) const;
365 
378  bool IsOpenedReadOnly (void) const;
379 
397  void BuildKeys (
398  const RDM_CHAR_T *optString
399  );
400 
401 #if defined(RDM_UNICODE)
402  void BuildKeys (const wchar_t *optString);
403 #endif
404 
432  void Export (const char *optString
433  ) const;
434 #if !defined(RDM_NO_CPP_STD_STRING)
435  void Export (const std::string &optString
436  ) const;
437 #endif
438 
439 #if defined(RDM_UNICODE)
440  void Export (const wchar_t *optString) const;
441 #if !defined(RDM_NO_CPP_STD_STRING)
442  void Export (const std::wstring &optString) const;
443 #endif
444 #endif
445 
468  void Import (const char *optString
469  ) const;
470 #if !defined(RDM_NO_CPP_STD_STRING)
471  void Import (const std::string &optString
472  ) const;
473 #endif
474 #if defined(RDM_UNICODE)
475  void Import (const wchar_t *optString) const;
476 #if !defined(RDM_NO_CPP_STD_STRING)
477  void Import (const std::wstring &optString
478  ) const;
479 #endif
480 #endif
481 
483 
486  RDM_DB GetDb ();
487 
489 
500  RDM_RETCODE GetReturnCode () const;
501 
515  Db &Release (void);
516 
528  ~Db ();
529 
537  Db SetCatalog (const RDM_CHAR_T *const catalog = NULL) const;
538 #if defined(RDM_UNICODE)
539  Db SetCatalog (const wchar_t *const catalog) const;
540 #endif
541 
550  Db CompileCatalog (const RDM_CHAR_T *const catalog = NULL) const;
551 #if defined(RDM_UNICODE)
552  Db CompileCatalog (const wchar_t *const catalog) const;
553 #endif
554 
563  Db LoadCatalog (const RDM_CHAR_T *const catalog = NULL) const;
564 #if defined(RDM_UNICODE)
565  Db LoadCatalog (const wchar_t *const catalog) const;
566 #endif
567 
575  Db SetCatalogFromFile (const RDM_CHAR_T *const file) const;
576 #if defined(RDM_UNICODE)
577  Db SetCatalogFromFile (const wchar_t *const file) const;
578 #endif
579 
589  Db CompileCatalogFromFile (const RDM_CHAR_T *const file) const;
590 #if defined(RDM_UNICODE)
591  Db CompileCatalogFromFile (const wchar_t *const file) const;
592 #endif
593 
603  Db LoadCatalogFromFile (const RDM_CHAR_T *const file) const;
604 #if defined(RDM_UNICODE)
605  Db LoadCatalogFromFile (const wchar_t *const file) const;
606 #endif
607 
612  Db AlterCatalog (const RDM_CHAR_T *const catalog) const;
613 #if defined(RDM_UNICODE)
614  Db AlterCatalog (const wchar_t *const catalog) const;
615 #endif
616 
625  RDM_LOCK_STATUS GetLockStatus (RDM_TABLE_ID tableId) const;
626 
640  void SetEncrypt (RDM_ENCRYPT enc) const;
641 
650  RDM_ENCRYPT GetEncrypt (void) const;
651 
675  void Encrypt (RDM_ENCRYPT enc, const RDM_CHAR_T *optString) const;
676 #if defined(RDM_UNICODE)
677  void Encrypt (RDM_ENCRYPT enc, const wchar_t *optString) const;
678 #endif
679 
695  void Vacuum (const RDM_CHAR_T *optString) const;
696 #if defined(RDM_UNICODE)
697  void Vacuum (const wchar_t *optString) const;
698 #endif
699 
710  void FlushIdIndex () const;
711 
722  void RebuildIdIndex () const;
723 
735  void ReplicationSend (
736  void *replicationBuffer,
737  size_t bufferSize,
738  size_t &bytesWritten) const;
739 
751  void ReplicationReceive (const void *replicationBuffer, size_t bufferSize) const;
752 
753 
764  void CreateNewPackFile () const;
765 
768  void Drop ();
769 
772  Db Open (
773  const RDM_CHAR_T *name,
774  RDM_OPEN_MODE mode,
775  const RDM_CHAR_T *const catalog) const;
778  Db Open (const RDM_CHAR_T *name, RDM_OPEN_MODE mode = RDM_OPEN_SHARED) const;
779 
780 #if defined(RDM_UNICODE)
781  Db Open (const wchar_t *name, RDM_OPEN_MODE mode = RDM_OPEN_SHARED) const;
782  Db Open (const wchar_t *name, RDM_OPEN_MODE mode, const char *const catalog) const;
783  Db Open (const char *name, RDM_OPEN_MODE mode, const wchar_t *const catalog) const;
784  Db Open (const wchar_t *name, RDM_OPEN_MODE mode, const wchar_t *const catalog)
785  const;
786 #endif
787 
790  Db Close () const;
791 
794  void ClearCache (void) const;
795 
798  void TriggersOn (void) const;
799 
802  void TriggersOff (void) const;
803 
806  RDM_TRIGGERS_STATUS TriggersStatus (void) const;
807 
810  void RebuildKey (
811  RDM_KEY_ID keyId,
812  uint32_t reportFrequency = 0,
813  RDM_REBUILD_INDEX_REPORT_FCN *fcn = NULL) const;
814 
817  void RebuildKeys (
818  uint32_t numKeys,
819  const RDM_KEY_ID *keyIds,
820  uint32_t reportFrequency = 0,
821  RDM_REBUILD_INDEX_REPORT_FCN *fcn = NULL) const;
822 
825  void Persist (void) const;
826 
835 #if !defined(RDM_NO_CPP_STD_STRING)
836  std::string GetOption (std::string option) const;
837 #endif
838 
840  void GetOption (
841  const char *option,
842  char *value,
843  size_t bytesIn,
844  size_t *bytesOut = NULL) const;
845 
846 #if defined(RDM_UNICODE)
847 
849 #if !defined(RDM_NO_CPP_STD_STRING)
850  std::wstring GetOption (std::wstring option) const;
851 #endif
852 
854  void GetOption (
855  const wchar_t *option,
856  wchar_t *value,
857  size_t bytesIn,
858  size_t *bytesOut = NULL) const;
859 #endif
860 
867 #if !defined(RDM_NO_CPP_STD_STRING)
868  std::string GetInfo (std::string key) const;
869 #endif
870 
872  void GetInfo (
873  const char *key,
874  char *value,
875  size_t bytesIn,
876  size_t *bytesOut = NULL) const;
877 
878 #if defined(RDM_UNICODE)
879 
881 #if !defined(RDM_NO_CPP_STD_STRING)
882  std::wstring GetInfo (std::wstring key) const;
883 #endif
884 
886  void GetInfo (
887  const wchar_t *key,
888  wchar_t *value,
889  size_t bytesIn,
890  size_t *bytesOut = NULL) const;
891 #endif
892 
907  void GetMemoryUsage (
908  uint64_t &systemCurr,
910  uint64_t &systemMax,
912  uint64_t &userCurr,
913  uint64_t &userMax
914  ) const;
915 
916 #ifndef RDM_DOXYGEN
917  protected:
918  IDb *m_idb;
919  Db (IDb *idb);
920  Db (const Db &, dbType);
921  Cursor _InsertRow (
922  RDM_TABLE_ID,
923  const void *,
924  size_t = 0,
925  RDM_ROWID_T rowid = NULL_ROWID) const;
926  Cursor _InsertRows (RDM_TABLE_ID, const void *, uint32_t, size_t, Cursor &) const;
927  Cursor _InsertRows (RDM_TABLE_ID, const void *, uint32_t, Cursor &) const;
928  Cursor _InsertRows (RDM_TABLE_ID, const void *, uint32_t) const;
929  Cursor _InsertRows (RDM_TABLE_ID, const void *, uint32_t, size_t) const;
930 
931  Cursor _GetRows (RDM_TABLE_ID, RDM_ROWID_T = NULL_ROWID) const;
932  Cursor _GetRowsByKey (RDM_KEY_ID id) const;
933  Cursor _GetRowsByRtreeKey (RDM_KEY_ID id) const;
934  Cursor _GetRowsByKey (RDM_KEY_ID, const void *, size_t = 0) const;
935  Cursor _GetRowsByKey (RDM_KEY_ID, const RDM_SEARCH_KEY *) const;
936  Cursor _GetRowsByKey (RDM_KEY_ID, const void *, size_t, RDM_RTREE_TYPE, uint32_t)
937  const;
938  Cursor _GetRowsByKeyInRange (
939  RDM_KEY_ID,
940  const RDM_SEARCH_KEY *,
941  const RDM_SEARCH_KEY * = NULL) const;
942  Cursor _GetRowsByKeyInRange (
943  RDM_KEY_ID,
944  const RDM_RANGE_KEY *,
945  const RDM_RANGE_KEY * = NULL) const;
946  Cursor _GetRowsByKeyInRange (
947  RDM_KEY_ID,
948  const void *,
949  size_t = 0,
950  const void * = NULL,
951  size_t = 0) const;
952  dbType _GetType (void) const;
953 
954  void _VerifyType (dbType) const;
955  void _ValidateIDb () const;
956  Db &_AssignAndVerifyType (dbType, const Db &);
957 
958  private:
959  int16_t __countLocks (const RDM_TABLE_ID[], int16_t) const;
960 
962  const Db *operator& (void) const;
963 #endif
964 
965  friend class Cursor;
966  friend class TFS;
967 };
968 #endif /* CPP_DB_H_INCLUDED_ */
RDM_RETCODE() RDM_REBUILD_INDEX_REPORT_FCN(const char *table, const char *indexes, uint64_t current, uint64_t total)
Callback function signature to report status on an ID-index rebuild.
Definition: rdmtypes.h:164
The Cursor base class.
Definition: cpp-cursor.h:43
RDM_LOCK_STATUS
Enumeration for RDM table lock status.
Definition: rdmtypes.h:140
Header for the native RDM Runtime types.
The RDM Partial Key data structure.
Definition: rdmtypes.h:58
The RDM Range Key data structure.
Definition: rdmtypes.h:103
#define NULL_ROWID
Definition: rdmrowidtypes.h:25
uint32_t RDM_TABLE_ID
Definition: rdmtypes.h:27
#define RDM_CHAR_T
Definition: psptypes.h:115
The Db base class.
Definition: cpp-db.h:52
RDM_TRANS_STATUS
The RDM transaction status identifiers.
Definition: rdmtypes.h:119
The TFS class This class provides the TFS implementation.
Definition: cpp-tfs.h:62
The Transaction class This class provides the Transaction implementation.
RDM_RETCODE
RDM status and error return codes.
RDM_OPEN_MODE
Enumeration for open modes.
Definition: rdmtypes.h:233
RDM_RTREE_TYPE
Query types for an R-tree index.
Definition: rdmtypes.h:77
RDM_TRIGGERS_STATUS
Triggers status values.
Definition: rdmtypes.h:302
uint32_t RDM_KEY_ID
Definition: rdmtypes.h:29
The RDM C++ Namespace.
Definition: cpp-cursor.h:27
const void * dbType
Definition: cpp-db.h:37
struct RDM_DB_S * RDM_DB
Definition: rdmtypes.h:290
uint64_t RDM_ROWID_T
Definition: rdmrowidtypes.h:21
Header for row ID types.
struct RDM_ENCRYPT_S * RDM_ENCRYPT
Definition: psptypes.h:73