OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
ConnectionAPI.h
Go to the documentation of this file.
1#pragma once
2#include <iostream>
3#include <string>
4
5#include <mongocxx/client.hpp>
6#include <mongocxx/pool.hpp>
7#include <mongocxx/instance.hpp>
8
9using connection = mongocxx::pool::entry;
10
11namespace DataStorageAPI
12{
13 void callMe(void);
14
15 class __declspec(dllexport) ConnectionAPI
16 {
17 public:
18 static ConnectionAPI& getInstance();
19
20 static void establishConnection(const std::string &serverURL, const std::string &siteID, const std::string &userName, const std::string &userPassword);
21
22 // This method needs to be called initially only once when the application runs.
23 void setMongoInstance(int siteId, std::ostream* logger);
24 void configurePool(std::string connectionUri, bool useDefaultUri = false);
25
26 mongocxx::collection getCollection(std::string databaseName, std::string collectionName);
27 bool checkCollectionExists(std::string databaseName, std::string collectionName);
28 bool createCollection(std::string databaseName, std::string collectionName);
29 bool deleteCollection(std::string databaseName, std::string collectionName);
30
31 bool checkServerIsRunning(void);
32
33 mongocxx::database getDatabase(std::string databaseName);
34
35 int getSiteId() { return _siteId; };
36
37 static std::string getMongoURL(std::string databaseURL, std::string dbUsername, std::string dbPassword);
38 private:
39 connection getConnection();
40
41 bsoncxx::stdx::optional<connection> tryGetConnection();
42
43 ConnectionAPI() = default;
44 std::unique_ptr<mongocxx::instance> _mongoInstance = nullptr;
45 std::unique_ptr<mongocxx::pool> _pool = nullptr;
46 int _siteId;
47 };
48};
49
mongocxx::pool::entry connection
Definition ConnectionAPI.h:9
std::string getMongoURL(std::string databaseURL, std::string dbUsername, std::string dbPassword)
Definition MongoURL.cpp:4
Definition ArrayBinaryConverter.h:3
void callMe(void)
Definition ConnectionAPI.cpp:17