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 }
41 
52  class PUBLIC_CLASS RDM_CPP::Db {
53 public:
54  /* Handle more than one reference to the underlying database */
55 
67  Db (void) throw ();
68 
80  Db (const Db& db) throw ();
81 
93  Db& operator = (const Db& db) throw ();
94 
109  TFS GetTFS (void);
110 
126  void DeleteAllRows (void) const;
127 
143  void DeleteAllRows (RDM_TABLE_ID tableId) const;
144 
158  void SetOptions (const char *optString) const;
159 #if !defined(RDM_NO_CPP_STD_STRING)
160  void SetOptions (const std::string &optString) const;
161 #endif
162  void SetOption (const char *option, const char *value) const;
163 #if !defined(RDM_NO_CPP_STD_STRING)
164  void SetOption (const std::string &option, const std::string &value) const;
165 #endif
166 
167 #if !defined(RDM_NO_UNICODE)
168 
170  void SetOptions (
171  const wchar_t *optString
172  ) const;
173 #if !defined(RDM_NO_CPP_STD_STRING)
174  void SetOptions (
175  const std::wstring &optString
176  ) const;
177 #endif
178  void SetOption (const wchar_t *option, const wchar_t *value) const;
179 #if !defined(RDM_NO_CPP_STD_STRING)
180  void SetOption (const std::wstring &option, const std::wstring &value) const;
181 #endif
182 #endif
183 
202  Transaction StartRead (
203  const RDM_TABLE_ID tableIds[]= NULL,
204  uint32_t num = 0
205  ) const;
206 
229  Transaction StartUpdate (
230  const RDM_TABLE_ID writeTableIds[],
231  uint32_t numWriteTableIds,
232  const RDM_TABLE_ID readTableIds[]= NULL,
233  uint32_t numReadTableIds = 0
234  ) const;
235 
238  Transaction StartUpdate (
239  const RDM_TABLE_ID writeTableIds[] = NULL,
240  const RDM_TABLE_ID readTableIds[] = NULL,
241  uint32_t numReadTableIds = 0
242  ) const;
243 
257  Transaction StartSnapshot (
258  const RDM_TABLE_ID tableIds[]= NULL,
259  uint32_t num = 0
260  ) const;
261 
285  void Precommit (void) const;
286 
304  void End (void) const;
305 
319  void EndRollback (void) const;
320 
331  RDM_TRANS_STATUS GetTransactionStatus (void) const;
332 
345  bool IsOpenedExclusive (void) const;
346 
359  bool IsOpenedShared (void) const;
360 
373  bool IsOpenedReadOnly (void) const;
374 
392  void BuildKeys (
393  const RDM_CHAR_T *optString
394  );
395 
396 #if !defined(RDM_NO_UNICODE)
397  void BuildKeys (
398  const wchar_t *optString
399  );
400 #endif
401 
429  void Export (
430  const char *optString
431  ) const;
432 #if !defined(RDM_NO_CPP_STD_STRING)
433  void Export (
434  const std::string &optString
435  ) const;
436 #endif
437 
438 #if !defined(RDM_NO_UNICODE)
439  void Export (
440  const wchar_t *optString
441  ) const;
442 #if !defined(RDM_NO_CPP_STD_STRING)
443  void Export (
444  const std::wstring &optString
445  ) const;
446 #endif
447 #endif
448 
471  void Import (
472  const char *optString
473  ) const;
474 #if !defined(RDM_NO_CPP_STD_STRING)
475  void Import (
476  const std::string &optString
477  ) const;
478 #endif
479 #if !defined(RDM_NO_UNICODE)
480  void Import (
481  const wchar_t *optString
482  ) const;
483 #if !defined(RDM_NO_CPP_STD_STRING)
484  void Import (
485  const std::wstring &optString
486  ) const;
487 #endif
488 #endif
489 
491 
494  RDM_DB GetDb();
495 
497 
508  RDM_RETCODE GetReturnCode() const;
509 
523  Db& Release (void);
524 
536  ~Db ();
537 
545  Db SetCatalog (
546  const RDM_CHAR_T *const catalog = NULL
547  ) const;
548 #if !defined(RDM_NO_UNICODE)
549  Db SetCatalog (
550  const wchar_t *const catalog
551  ) const;
552 #endif
553 
561  Db SetCatalogFromFile (
562  const RDM_CHAR_T *const file
563  ) const;
564 #if !defined(RDM_NO_UNICODE)
565  Db SetCatalogFromFile (
566  const wchar_t *const file
567  ) const;
568 #endif
569 
574  Db AlterCatalog (
575  const RDM_CHAR_T *const catalog
576  ) const;
577 #if !defined(RDM_NO_UNICODE)
578  Db AlterCatalog (
579  const wchar_t *const catalog
580  ) const;
581 #endif
582 
591  RDM_LOCK_STATUS GetLockStatus (
592  RDM_TABLE_ID tableId
593  ) const;
594 
608  void SetEncrypt (
609  RDM_ENCRYPT enc
610  ) const;
611 
620  RDM_ENCRYPT GetEncrypt (
621  void
622  ) const;
623 
647  void Encrypt (
648  RDM_ENCRYPT enc,
649  const RDM_CHAR_T *optString
650  ) const;
651 #if !defined(RDM_NO_UNICODE)
652  void Encrypt (
653  RDM_ENCRYPT enc,
654  const wchar_t *optString
655  ) const;
656 #endif
657 
673  void Vacuum (
674  const RDM_CHAR_T *optString
675  ) const;
676 #if !defined(RDM_NO_UNICODE)
677  void Vacuum (
678  const wchar_t *optString
679  ) const;
680 #endif
681 
692  void FlushIdIndex (
693  ) const;
694 
705  void RebuildIdIndex (
706  ) const;
707 
718  void CreateNewPackFile (
719  ) const;
720 
723  Db Open (
724  const RDM_CHAR_T *name,
725  RDM_OPEN_MODE mode,
726  const RDM_CHAR_T *const catalog
727  ) const;
730  Db Open (
731  const RDM_CHAR_T *name,
733  ) const;
734 
735 #if !defined(RDM_NO_UNICODE)
736  Db Open (
737  const wchar_t *name,
739  ) const;
740  Db Open (
741  const wchar_t *name,
742  RDM_OPEN_MODE mode,
743  const char *const catalog
744  ) const;
745  Db Open (
746  const char *name,
747  RDM_OPEN_MODE mode,
748  const wchar_t *const catalog
749  ) const;
750  Db Open (
751  const wchar_t *name,
752  RDM_OPEN_MODE mode,
753  const wchar_t *const catalog
754  ) const;
755 #endif
756 
759  Db Close (
760  ) const;
761 
764  void ClearCache (void) const;
765 
768  void TriggersOn (void) const;
769 
772  void TriggersOff (void) const;
773 
776  RDM_TRIGGERS_STATUS TriggersStatus (void) const;
777 
780  void RebuildKey (
781  RDM_KEY_ID keyId,
782  uint32_t reportFrequency = 0,
783  RDM_REBUILD_INDEX_REPORT_FCN *fcn = NULL
784  ) const;
785 
788  void RebuildKeys (
789  uint32_t numKeys,
790  const RDM_KEY_ID *keyIds,
791  uint32_t reportFrequency = 0,
792  RDM_REBUILD_INDEX_REPORT_FCN *fcn = NULL
793  ) const;
794 
797  void Persist (void) const;
798 
807 #if !defined(RDM_NO_CPP_STD_STRING)
808  std::string GetOption (
809  std::string option
810  ) const;
811 #endif
812 
814  void GetOption (
815  const char *option,
816  char *value,
817  size_t bytesIn,
818  size_t *bytesOut = NULL
819  ) const;
820 
821 #if !defined(RDM_NO_UNICODE)
822 
824 #if !defined(RDM_NO_CPP_STD_STRING)
825  std::wstring GetOption (
826  std::wstring option
827  ) const;
828 #endif
829 
831  void GetOption (
832  const wchar_t *option,
833  wchar_t *value,
834  size_t bytesIn,
835  size_t *bytesOut = NULL
836  ) const;
837 #endif
838 
845 #if !defined(RDM_NO_CPP_STD_STRING)
846  std::string GetInfo (
847  std::string key
848  ) const;
849 #endif
850 
852  void GetInfo (
853  const char *key,
854  char *value,
855  size_t bytesIn,
856  size_t *bytesOut = NULL
857  ) const;
858 
859 #if !defined(RDM_NO_UNICODE)
860 
862 #if !defined(RDM_NO_CPP_STD_STRING)
863  std::wstring GetInfo (
864  std::wstring key
865  ) const;
866 #endif
867 
869  void GetInfo (
870  const wchar_t *key,
871  wchar_t *value,
872  size_t bytesIn,
873  size_t *bytesOut = NULL
874  ) const;
875 #endif
876 
877 #ifndef RDM_DOXYGEN
878 protected:
879  IDb *m_idb;
880  Db (IDb *idb);
881  Db (const Db&, dbType);
882  Cursor _InsertRow (RDM_TABLE_ID, const void *, size_t = 0, RDM_ROWID_T rowid = NULL_ROWID) const;
883  Cursor _InsertRows (RDM_TABLE_ID, const void *, uint32_t, size_t, Cursor&) const;
884  Cursor _InsertRows (RDM_TABLE_ID, const void *, uint32_t, Cursor&) const;
885  Cursor _InsertRows (RDM_TABLE_ID, const void *, uint32_t) const;
886  Cursor _InsertRows (RDM_TABLE_ID, const void *, uint32_t, size_t) const;
887 
888  Cursor _GetRows (RDM_TABLE_ID, RDM_ROWID_T = NULL_ROWID) const;
889  Cursor _GetRowsByKey (RDM_KEY_ID id) const;
890  Cursor _GetRowsByRtreeKey (RDM_KEY_ID id) const;
891  Cursor _GetRowsByKey (RDM_KEY_ID, const void *, size_t = 0) const;
892  Cursor _GetRowsByKey (RDM_KEY_ID, const RDM_SEARCH_KEY *) const;
893  Cursor _GetRowsByKey (RDM_KEY_ID, const void *, size_t, RDM_RTREE_TYPE, uint32_t) const;
894  Cursor _GetRowsByKeyInRange (RDM_KEY_ID, const RDM_SEARCH_KEY *, const RDM_SEARCH_KEY * = NULL) const;
895  Cursor _GetRowsByKeyInRange (RDM_KEY_ID, const RDM_RANGE_KEY *, const RDM_RANGE_KEY * =NULL) const;
896  Cursor _GetRowsByKeyInRange (RDM_KEY_ID, const void *, size_t = 0, const void * = NULL, size_t = 0) const;
897  dbType _GetType (void) const;
898 
899  void _VerifyType (dbType) const;
900  void _ValidateIDb () const;
901  Db& _AssignAndVerifyType (dbType, const Db&);
902 private:
903  int16_t __countLocks (const RDM_TABLE_ID [], int16_t) const;
904 
906  const Db* operator & (void) const;
907 #endif
908 
909  friend class Cursor;
910  friend class TFS;
911 };
912 #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:134
The Cursor base class.
Definition: cpp-cursor.h:43
RDM_LOCK_STATUS
Enumeration for RDM table lock status.
Definition: rdmtypes.h:114
Header for the native RDM Runtime types.
The RDM Partial Key data structure.
Definition: rdmtypes.h:32
The RDM Range Key data structure.
Definition: rdmtypes.h:77
#define NULL_ROWID
Definition: rdmrowidtypes.h:25
uint32_t RDM_TABLE_ID
Definition: rdmtypes.h:26
#define RDM_CHAR_T
Definition: psptypes.h:119
The Db base class.
Definition: cpp-db.h:52
RDM_TRANS_STATUS
The RDM transaction status identifiers.
Definition: rdmtypes.h:93
The TFS class This class provides the TFS implementation.
Definition: cpp-tfs.h:67
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:194
RDM_RTREE_TYPE
Query types for an R-tree index.
Definition: rdmtypes.h:51
RDM_TRIGGERS_STATUS
Triggers status values.
Definition: rdmtypes.h:249
uint32_t RDM_KEY_ID
Definition: rdmtypes.h:28
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:240
uint64_t RDM_ROWID_T
Definition: rdmrowidtypes.h:21
Header for row ID types.
struct RDM_ENCRYPT_S * RDM_ENCRYPT
Definition: psptypes.h:77