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 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 
549  Db SetCatalogFromFile (const RDM_CHAR_T *const file) const;
550 #if defined(RDM_UNICODE)
551  Db SetCatalogFromFile (const wchar_t *const file) const;
552 #endif
553 
558  Db AlterCatalog (const RDM_CHAR_T *const catalog) const;
559 #if defined(RDM_UNICODE)
560  Db AlterCatalog (const wchar_t *const catalog) const;
561 #endif
562 
571  RDM_LOCK_STATUS GetLockStatus (RDM_TABLE_ID tableId) const;
572 
586  void SetEncrypt (RDM_ENCRYPT enc) const;
587 
596  RDM_ENCRYPT GetEncrypt (void) const;
597 
621  void Encrypt (RDM_ENCRYPT enc, const RDM_CHAR_T *optString) const;
622 #if defined(RDM_UNICODE)
623  void Encrypt (RDM_ENCRYPT enc, const wchar_t *optString) const;
624 #endif
625 
641  void Vacuum (const RDM_CHAR_T *optString) const;
642 #if defined(RDM_UNICODE)
643  void Vacuum (const wchar_t *optString) const;
644 #endif
645 
656  void FlushIdIndex () const;
657 
668  void RebuildIdIndex () const;
669 
680  void CreateNewPackFile () const;
681 
684  void Drop ();
685 
688  Db Open (
689  const RDM_CHAR_T *name,
690  RDM_OPEN_MODE mode,
691  const RDM_CHAR_T *const catalog) const;
694  Db Open (const RDM_CHAR_T *name, RDM_OPEN_MODE mode = RDM_OPEN_SHARED) const;
695 
696 #if defined(RDM_UNICODE)
697  Db Open (const wchar_t *name, RDM_OPEN_MODE mode = RDM_OPEN_SHARED) const;
698  Db Open (const wchar_t *name, RDM_OPEN_MODE mode, const char *const catalog) const;
699  Db Open (const char *name, RDM_OPEN_MODE mode, const wchar_t *const catalog) const;
700  Db Open (const wchar_t *name, RDM_OPEN_MODE mode, const wchar_t *const catalog)
701  const;
702 #endif
703 
706  Db Close () const;
707 
710  void ClearCache (void) const;
711 
714  void TriggersOn (void) const;
715 
718  void TriggersOff (void) const;
719 
722  RDM_TRIGGERS_STATUS TriggersStatus (void) const;
723 
726  void RebuildKey (
727  RDM_KEY_ID keyId,
728  uint32_t reportFrequency = 0,
729  RDM_REBUILD_INDEX_REPORT_FCN *fcn = NULL) const;
730 
733  void RebuildKeys (
734  uint32_t numKeys,
735  const RDM_KEY_ID *keyIds,
736  uint32_t reportFrequency = 0,
737  RDM_REBUILD_INDEX_REPORT_FCN *fcn = NULL) const;
738 
741  void Persist (void) const;
742 
751 #if !defined(RDM_NO_CPP_STD_STRING)
752  std::string GetOption (std::string option) const;
753 #endif
754 
756  void GetOption (
757  const char *option,
758  char *value,
759  size_t bytesIn,
760  size_t *bytesOut = NULL) const;
761 
762 #if defined(RDM_UNICODE)
763 
765 #if !defined(RDM_NO_CPP_STD_STRING)
766  std::wstring GetOption (std::wstring option) const;
767 #endif
768 
770  void GetOption (
771  const wchar_t *option,
772  wchar_t *value,
773  size_t bytesIn,
774  size_t *bytesOut = NULL) const;
775 #endif
776 
783 #if !defined(RDM_NO_CPP_STD_STRING)
784  std::string GetInfo (std::string key) const;
785 #endif
786 
788  void GetInfo (
789  const char *key,
790  char *value,
791  size_t bytesIn,
792  size_t *bytesOut = NULL) const;
793 
794 #if defined(RDM_UNICODE)
795 
797 #if !defined(RDM_NO_CPP_STD_STRING)
798  std::wstring GetInfo (std::wstring key) const;
799 #endif
800 
802  void GetInfo (
803  const wchar_t *key,
804  wchar_t *value,
805  size_t bytesIn,
806  size_t *bytesOut = NULL) const;
807 #endif
808 
823  void GetMemoryUsage (
824  uint64_t &systemCurr,
826  uint64_t &systemMax,
828  uint64_t &userCurr,
829  uint64_t &userMax
830  ) const;
831 
832 #ifndef RDM_DOXYGEN
833  protected:
834  IDb *m_idb;
835  Db (IDb *idb);
836  Db (const Db &, dbType);
837  Cursor _InsertRow (
838  RDM_TABLE_ID,
839  const void *,
840  size_t = 0,
841  RDM_ROWID_T rowid = NULL_ROWID) const;
842  Cursor _InsertRows (RDM_TABLE_ID, const void *, uint32_t, size_t, Cursor &) const;
843  Cursor _InsertRows (RDM_TABLE_ID, const void *, uint32_t, Cursor &) const;
844  Cursor _InsertRows (RDM_TABLE_ID, const void *, uint32_t) const;
845  Cursor _InsertRows (RDM_TABLE_ID, const void *, uint32_t, size_t) const;
846 
847  Cursor _GetRows (RDM_TABLE_ID, RDM_ROWID_T = NULL_ROWID) const;
848  Cursor _GetRowsByKey (RDM_KEY_ID id) const;
849  Cursor _GetRowsByRtreeKey (RDM_KEY_ID id) const;
850  Cursor _GetRowsByKey (RDM_KEY_ID, const void *, size_t = 0) const;
851  Cursor _GetRowsByKey (RDM_KEY_ID, const RDM_SEARCH_KEY *) const;
852  Cursor _GetRowsByKey (RDM_KEY_ID, const void *, size_t, RDM_RTREE_TYPE, uint32_t)
853  const;
854  Cursor _GetRowsByKeyInRange (
855  RDM_KEY_ID,
856  const RDM_SEARCH_KEY *,
857  const RDM_SEARCH_KEY * = NULL) const;
858  Cursor _GetRowsByKeyInRange (
859  RDM_KEY_ID,
860  const RDM_RANGE_KEY *,
861  const RDM_RANGE_KEY * = NULL) const;
862  Cursor _GetRowsByKeyInRange (
863  RDM_KEY_ID,
864  const void *,
865  size_t = 0,
866  const void * = NULL,
867  size_t = 0) const;
868  dbType _GetType (void) const;
869 
870  void _VerifyType (dbType) const;
871  void _ValidateIDb () const;
872  Db &_AssignAndVerifyType (dbType, const Db &);
873 
874  private:
875  int16_t __countLocks (const RDM_TABLE_ID[], int16_t) const;
876 
878  const Db *operator& (void) const;
879 #endif
880 
881  friend class Cursor;
882  friend class TFS;
883 };
884 #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:139
The Cursor base class.
Definition: cpp-cursor.h:43
RDM_LOCK_STATUS
Enumeration for RDM table lock status.
Definition: rdmtypes.h:115
Header for the native RDM Runtime types.
The RDM Partial Key data structure.
Definition: rdmtypes.h:33
The RDM Range Key data structure.
Definition: rdmtypes.h:78
#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:94
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:208
RDM_RTREE_TYPE
Query types for an R-tree index.
Definition: rdmtypes.h:52
RDM_TRIGGERS_STATUS
Triggers status values.
Definition: rdmtypes.h:277
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:265
uint64_t RDM_ROWID_T
Definition: rdmrowidtypes.h:21
Header for row ID types.
struct RDM_ENCRYPT_S * RDM_ENCRYPT
Definition: psptypes.h:73