9 #include "knowrob/storage/mongo/MongoInterface.h"
13 MongoInterface::MongoInterface() {
17 MongoInterface::~MongoInterface() =
default;
24 std::shared_ptr<Connection> MongoInterface::getOrCreateConnection(
const char *uri_string_c) {
26 auto it = connections_.find(uri_string);
27 if (it == connections_.end()) {
29 auto newConnection = std::make_shared<Connection>(uri_string);
30 connections_[uri_string] = newConnection;
38 auto dbConnection = getOrCreateConnection((
char *) dbTerm[1]);
39 return std::make_shared<Database>(dbConnection->pool_, (
char *) dbTerm[2]);
43 return connect((
char *) dbTerm[1], (
char *) dbTerm[2], collectionName);
46 std::shared_ptr<Collection>
48 auto dbConnection = getOrCreateConnection(db_uri);
49 return std::make_shared<Collection>(dbConnection, db_name, collectionName);
54 auto coll =
connect(db_term, coll_name);
55 auto c = std::make_shared<Cursor>(coll);
56 std::lock_guard<std::mutex> scoped_lock(mongo_mutex_);
57 cursors_[c->id()] = c;
62 std::lock_guard<std::mutex> scoped_lock(mongo_mutex_);
63 cursors_.erase(curser_id);
67 std::lock_guard<std::mutex> scoped_lock(mongo_mutex_);
std::shared_ptr< Database > connect(const PlTerm &dbTerm)
std::shared_ptr< Cursor > cursor_create(const PlTerm &db_term, const char *coll_name)
std::shared_ptr< Cursor > cursor(const char *curser_id)
static MongoInterface & get()
void cursor_destroy(const char *curser_id)