OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
DataBase.h
Go to the documentation of this file.
1#pragma once
2#pragma warning(disable : 4251)
3
4#include <string>
5#include <vector>
6#include <map>
7#include <list>
8
9#include <bsoncxx/builder/stream/document.hpp>
10#include <bsoncxx/json.hpp>
11#include <bsoncxx/builder/basic/document.hpp>
12#include <bsoncxx/types/value.hpp>
13#include <bsoncxx/document/value.hpp>
14
15#include <mongocxx/pool.hpp>
16
18#include "EntityBase.h"
19
20#include "Geometry.h"
21
22class ClassFactory;
23
24using connection = mongocxx::pool::entry;
25
26class __declspec(dllexport) DataBase
27{
28public:
29 DataBase();
30 virtual ~DataBase();
31
32 static DataBase* GetDataBase();
33
34 bool InitializeConnection(const std::string &serverURL, const std::string &siteID);
35 void setProjectName(const std::string &name) { projectName = name; };
36 std::string getProjectName(void) { return projectName; };
37 int getSiteID(void) { return serviceSiteID; };
38
39 // Create a compound collection index for entityID and version in case the index has not yet been created
40 void createIndexIfNecessary(void);
41
42 std::string StoreDataItem(bsoncxx::builder::basic::document &storage);
43 std::string StorePlainDataItem(bsoncxx::builder::basic::document &storage);
44
46 bool GetDocumentFromObjectID(const std::string &storageID, bsoncxx::builder::basic::document &doc);
47
49 bool GetDocumentFromEntityIDandVersion(unsigned long long entityID, unsigned long long version, bsoncxx::builder::basic::document &doc);
50 EntityBase* GetEntityFromEntityIDandVersion(ot::UID _entityID, ot::UID _version, ClassFactory* classFactory);
51
52
53 bool GetAllDocumentsFromFilter(std::map<std::string, bsoncxx::types::value> &filterPairs, std::vector<std::string> &columnNames, bsoncxx::builder::basic::document &doc);
54
55 void PrefetchDocumentsFromStorage(std::list<std::pair<unsigned long long, unsigned long long>> &prefetchIdandVersion);
56 void RemovePrefetchedDocument(unsigned long long entityID);
57
58 static long long GetIntFromView(bsoncxx::document::view &doc_view, const char *elementName);
59 static long long GetIntFromArrayViewIterator(bsoncxx::array::view::const_iterator &it)
60 {
61 if (it->type() == bsoncxx::type::k_int32) return it->get_int32();
62 if (it->type() == bsoncxx::type::k_int64) return it->get_int64();
63 assert(0);
64 return 0;
65 }
66 static long long GetIntFromView(bsoncxx::document::view &doc_view, const char *elementName, long long defaultValue);
67
68 std::string getDataBaseServerURL(void) { return databaseServerURL; };
69
70 void setDataBaseServerURL(const std::string &url) { databaseServerURL = url; };
71 void setSiteIDString(const std::string &id) { serviceSiteIDString = id; };
72 std::string getSiteIDString(void) { return serviceSiteIDString; }
73
74 std::string getTmpFileName(void);
75
76 void queueWriting(bool enableQueuedWriting);
77 void flushWritingQueue(void);
78 bool isWritingQueue(void) { return queueWritingFlag; };
79
80 void DeleteDocuments(std::list<std::pair<unsigned long long, unsigned long long>> &deleteDocuments);
81
82 void setUserCredentials(const std::string &_userName, const std::string &_password) { userName = _userName; userPassword = _password; }
83 std::string getUserName(void) { return userName; }
84 std::string getUserPassword(void) { return userPassword; }
85
86 /* ******************************************** Legacy API from Viewer (Needs to be removed with next refactoring) ******************************** */
87 static void readBSON(bsoncxx::document::view &nodesObj, std::vector<Geometry::Node> &nodes);
88 static void readBSON(bsoncxx::document::view &trianglesObj, std::list<Geometry::Triangle> &triangles);
89 static void readBSON(bsoncxx::document::view &edgesObj, std::list<Geometry::Edge> &edges);
91private:
92 bool isConnected;
93 std::string projectName;
94 std::string databaseServerURL;
95 int serviceSiteID;
96 std::string serviceSiteIDString;
97 bool queueWritingFlag;
98 std::map<unsigned long long, bsoncxx::builder::basic::document *> prefetchedDocuments;
99 std::string userName;
100 std::string userPassword;
101};
102
mongocxx::pool::entry connection
Definition ConnectionAPI.h:9
@ nodes
Definition MonitorSettings.h:17
@ edges
Definition MonitorSettings.h:17
unsigned long UID
Unique identifier (32 bit unsigned integer)
Definition CoreTypes.h:27