29#include <Ice/ObjectAdapter.h>
30#include <IceUtil/UUID.h>
33#include <ArmarXCore/interface/core/Log.h>
39#include <mongo/client/dbclient.h>
40#include <mongo/client/dbclientinterface.h>
49 return "CommonStorage";
55 return "CommonStorage";
65 mongo::client::initialize();
67 accessGridFSFilesMutex.reset(
new std::mutex());
76 else if (getenv(
"MONGODB_HOST"))
78 hostAndPort = getenv(
"MONGODB_HOST");
85 if (hostAndPort.find(
':') == std::string::npos)
91 else if (getenv(
"MONGODB_PORT"))
93 hostAndPort +=
":" + std::string(getenv(
"MONGODB_PORT"));
103 connectionCheckerTask =
119 connectionCheckerTask->start();
126 connectionCheckerTask->stop();
128 std::unique_lock l(openedDatabasesMutex);
129 openedDatabases.clear();
132 std::unique_lock l(openedCollectionsMutex);
133 openedCollections.clear();
136 std::unique_lock l(openedFilesMutex);
140 std::unique_lock l(openedGridFSMutex);
141 openedGridFS.clear();
144 mongo::client::shutdown();
155 CommonStorage::connect()
159 openedGridFS.clear();
160 conn.reset(
new mongo::DBClientConnection);
161 conn->connect(hostAndPort);
163 catch (
const mongo::DBException& e)
165 ARMARX_ERROR <<
"Can't connect to MongoDB: " << e.what();
168 catch (
const std::exception& e)
170 ARMARX_ERROR <<
"Can't connect to MongoDB: " << e.what();
174 ARMARX_INFO <<
"Connected to Mongo: host = " << hostAndPort;
180 CommonStorage::checkConnection()
184 mongo::DBClientConnection conn;
185 conn.connect(hostAndPort);
186 conn.getDatabaseNames();
195 CommonStorage::ConnectionWrapper
196 CommonStorage::getConnection()
198 std::shared_ptr<mongo::DBClientConnection> conn;
200 std::lock_guard<std::mutex> guard{serverSettingsMutex};
207 conn.reset(
new mongo::DBClientConnection());
208 conn->connect(hostAndPort);
210 catch (std::exception& e)
212 ARMARX_ERROR <<
"Can't connect to MongoDB: " << e.what();
220 conn = std::move(pool.front());
224 return {*
this, std::move(conn)};
228 CommonStorage::createPasswordDigest(
const std::string& username,
const std::string& password)
232 std::string digest = getConnection().conn().createPasswordDigest(username, password);
237 CommonStorage::extractDBNameFromNS(
const std::string& ns)
239 const size_t found = ns.find_first_of(
'.');
240 return (found != std::string::npos) ? ns.substr(0, found) :
"";
244 CommonStorage::forceAuthenticate(
const std::string& dbName,
245 const std::string& userName,
246 const std::string& password)
250 result = getConnection().conn().auth(dbName, userName, pwdDigest, errmsg,
false);
254 authDBs.insert(dbName);
261 CommonStorage::authenticateNS(
const std::string& ns)
263 const std::string dbName = extractDBNameFromNS(ns);
268 throw DBNotSpecifiedException(
"Database name not specified for collection: " + ns +
269 ". Please use <dbName>.<collectionName> format!");
272 return authenticateDB(dbName);
276 CommonStorage::authenticateDB(
const std::string& dbName)
283 ARMARX_INFO <<
"Try to Auth: db = " << dbName <<
", user = " << userName
284 <<
", pwd = " << pwdDigest << std::endl;
286 if (authDBs.count(dbName))
292 return forceAuthenticate(dbName, userName, pwdDigest);
298 const std::string& userName,
299 const std::string& password,
302 pwdDigest = createPasswordDigest(userName, password);
303 return forceAuthenticate(dbName, userName, this->pwdDigest);
315 authenticateDB(
"admin");
318 std::list<std::string> result = getConnection().conn().getDatabaseNames();
319 return NameList(result.begin(), result.end());
326 std::list<std::string> result = getConnection().conn().getCollectionNames(dbName);
327 return NameList(result.begin(), result.end());
338 const ::std::string& userName,
339 const ::std::string& password,
340 const ::Ice::Current&)
342 this->hostAndPort = hostAndPort;
343 this->userName = userName;
344 this->pwdDigest = createPasswordDigest(userName, password);
345 this->useAuth = !userName.empty();
353 if (authenticateDB(dbName))
356 Ice::Identity dbId = db->getIceId();
358 std::unique_lock l(openedDatabasesMutex);
359 openedDatabases[dbId] = db;
361 Ice::ObjectPrx node =
c.adapter->add(db, dbId);
362 return DatabaseInterfacePrx::uncheckedCast(node);
366 throw MongoAuthenticationException(
"Mongo authentication failed (user = " + userName +
367 ", database = " + dbName +
")");
374 std::unique_lock l(openedDatabasesMutex);
375 openedDatabases.erase(db->ice_getIdentity());
378 CollectionInterfacePrx
382 if (authenticateNS(collectionNS))
385 Ice::Identity collId = coll->getIceId();
387 std::unique_lock l(openedCollectionsMutex);
388 openedCollections[collId] = coll;
390 Ice::ObjectPrx node =
c.adapter->add(coll, collId);
391 return CollectionInterfacePrx::uncheckedCast(node);
395 throw MongoAuthenticationException(
"Mongo authentication failed (user = " + userName +
396 ", collection = " + collectionNS +
")");
403 std::unique_lock l(openedCollectionsMutex);
404 openedCollections.erase(coll->ice_getIdentity());
411 if (authenticateNS(collectionNS))
413 getConnection().conn().dropCollection(collectionNS);
417 throw MongoAuthenticationException(
"Mongo authentication failed (user = " + userName +
418 ", collection = " + collectionNS +
")");
423 CommonStorage::getDocumentId(
const mongo::BSONObj& doc)
429 CommonStorage::getDocumentField(
const mongo::BSONObj& doc,
const std::string& fieldName)
431 if (doc.hasField(fieldName.c_str()))
433 const mongo::BSONElement field = doc[fieldName.c_str()];
435 switch (field.type())
438 return field.OID().toString();
444 return field.toString(
false);
454 CommonStorage::getGridFS(
const std::string& dbName)
456 std::unique_lock l(openedGridFSMutex);
457 std::map<std::string, GridFSPtr>::const_iterator it = openedGridFS.find(dbName);
459 if (it != openedGridFS.end())
465 GridFSPtr gridFS(
new mongo::GridFS(*conn, dbName));
466 openedGridFS[dbName] = gridFS;
473 const std::string& fileName,
474 const ::std::string& gridFSName ,
475 const Ice::Current&
c)
481 if (!std::filesystem::exists(fileName))
483 throw FileNotFoundException(
"File could not be found: " + fileName, fileName);
485 std::unique_lock l(*accessGridFSFilesMutex);
486 mongo::GridFile oldFile =
487 gridfs->findFileByName((gridFSName.empty()) ? fileName : gridFSName);
488 const mongo::BSONObj newFileDoc = gridfs->storeFile(fileName, gridFSName);
489 mongo::GridFile newFile =
490 gridfs->findFileByName((gridFSName.empty()) ? fileName : gridFSName);
493 if (keepOldFileIfEqual(oldFile, newFile, newFileDoc, dbName, oldId))
498 return getDocumentId(newFileDoc);
504 const std::string& bufferToStore,
505 const std::string& gridFSName,
506 const Ice::Current&
c)
510 if (gridFSName.empty())
512 throw armarx::LocalException(
"gridFSName must not be empty");
514 std::unique_lock l(*accessGridFSFilesMutex);
515 mongo::GridFile oldFile = gridfs->findFileByName(gridFSName);
516 const mongo::BSONObj newFileDoc =
517 gridfs->storeFile(bufferToStore.c_str(), bufferToStore.size(), gridFSName);
518 mongo::GridFile newFile = gridfs->findFileByName(gridFSName);
521 if (keepOldFileIfEqual(oldFile, newFile, newFileDoc, dbName, oldId))
525 return getDocumentId(newFileDoc);
531 const memoryx::Blob& bufferToStore,
532 const std::string& gridFSName,
533 const Ice::Current&
c)
537 if (gridFSName.empty())
539 throw armarx::LocalException(
"gridFSName must not be empty");
541 std::unique_lock l(*accessGridFSFilesMutex);
542 mongo::GridFile oldFile = gridfs->findFileByName(gridFSName);
544 const mongo::BSONObj newFileDoc = gridfs->storeFile(
545 reinterpret_cast<const char*
>(&bufferToStore[0]), bufferToStore.size(), gridFSName);
546 mongo::GridFile newFile = gridfs->findFileByName(gridFSName);
549 if (keepOldFileIfEqual(oldFile, newFile, newFileDoc, dbName, oldId))
554 return getDocumentId(newFileDoc);
559 CommonStorage::keepOldFileIfEqual(
const mongo::GridFile& oldFile,
560 const mongo::GridFile newFile,
561 const mongo::BSONObj& newFileDoc,
562 const std::string dbName,
565 if (oldFile.exists())
567 std::string docId = (oldFile.getFileField(
"_id").OID().toString());
569 if (!docId.empty() && newFile.getMD5() == oldFile.getMD5())
581 CommonStorage::getFileByQuery(
const std::string& dbName,
const mongo::BSONObj& query)
586 std::unique_lock l(*accessGridFSFilesMutex);
589 mongo::GridFile gf = gfs->findFile(query);
611 CommonStorage::createFileProxy(mongo::GridFile gridFile,
const Ice::Current&
c)
613 if (gridFile.exists())
615 GridFileWrapperPtr fileWrapper =
new GridFileWrapper(gridFile, accessGridFSFilesMutex);
616 Ice::Identity fileIceId = fileWrapper->getIceId();
618 std::unique_lock l(openedFilesMutex);
619 openedFiles[fileIceId] = fileWrapper;
621 Ice::ObjectPrx node =
c.adapter->add(fileWrapper, fileIceId);
622 return GridFileInterfacePrx::uncheckedCast(node);
626 ARMARX_WARNING <<
"Grid file does not exit " << gridFile.getFilename();
627 return GridFileInterfacePrx();
633 const std::string& fileId,
634 const Ice::Current&
c)
636 const mongo::BSONObj query = BSON(
MONGO_ID_FIELD << mongo::OID(fileId));
637 mongo::GridFile gridFile = getFileByQuery(dbName, query);
638 return createFileProxy(gridFile,
c);
643 const std::string& gridFSName,
644 const Ice::Current&
c)
646 const mongo::BSONObj query = BSON(
"filename" << gridFSName);
647 mongo::GridFile gridFile = getFileByQuery(dbName, query);
648 return createFileProxy(gridFile,
c);
656 std::unique_lock l(openedFilesMutex);
657 c.adapter->remove(fileProxy->ice_getIdentity());
658 openedFiles.erase(fileProxy->ice_getIdentity());
663 CommonStorage::readTextFile(mongo::GridFile& gridFile, std::string& buffer)
665 if (gridFile.exists())
667 std::ostringstream ss;
679 CommonStorage::readBinaryFile(mongo::GridFile& gridFile, memoryx::Blob& buffer)
681 if (gridFile.exists())
683 buffer.reserve(gridFile.getContentLength());
685 sb.pubsetbuf((
char*)&buffer[0], buffer.capacity());
686 std::iostream os(&sb);
699 const std::string& fileId,
701 const Ice::Current&
c)
703 const mongo::BSONObj query = BSON(
MONGO_ID_FIELD << mongo::OID(fileId));
704 mongo::GridFile gridFile = getFileByQuery(dbName, query);
705 return readTextFile(gridFile, buffer);
710 const std::string& fileId,
711 memoryx::Blob& buffer,
712 const Ice::Current&
c)
714 const mongo::BSONObj query = BSON(
MONGO_ID_FIELD << mongo::OID(fileId));
715 mongo::GridFile gridFile = getFileByQuery(dbName, query);
716 return readBinaryFile(gridFile, buffer);
721 const std::string& gridFSName,
723 const Ice::Current&
c)
725 const mongo::BSONObj query = BSON(
"filename" << gridFSName);
726 mongo::GridFile gridFile = getFileByQuery(dbName, query);
727 return readTextFile(gridFile, buffer);
732 const std::string& gridFSName,
733 memoryx::Blob& buffer,
734 const Ice::Current&
c)
736 const mongo::BSONObj query = BSON(
"filename" << gridFSName);
737 mongo::GridFile gridFile = getFileByQuery(dbName, query);
738 return readBinaryFile(gridFile, buffer);
744 std::string GridFsFilesNamespace = dbName +
".fs.files";
745 std::string GridFsChunksNamespace = dbName +
".fs.chunks";
749 auto conn = getConnection();
750 std::unique_ptr<mongo::DBClientCursor> files =
751 conn.conn().query(GridFsFilesNamespace, fileQuery);
753 while (files->more())
755 mongo::BSONObj file = files->next();
756 mongo::BSONElement
id = file[
"_id"];
758 conn.conn().remove(GridFsFilesNamespace, BSON(
"_id" <<
id));
759 conn.conn().remove(GridFsChunksNamespace, BSON(
"files_id" <<
id));
762 catch (mongo::DBException& e)
764 ARMARX_ERROR <<
"Error removing file by query " << fileQuery <<
": " << e.what();
772 auto gridfs = getGridFS(dbName);
773 std::unique_ptr<mongo::DBClientCursor> list = gridfs->list();
777 mongo::BSONObj query = list->nextSafe();
778 auto file = getFileByQuery(dbName, query);
780 result.push_back(file.getFilename());
790 auto gridfs = getGridFS(dbName);
792 std::unique_lock l(*accessGridFSFilesMutex);
794 std::unique_ptr<mongo::DBClientCursor> list = gridfs->list();
798 mongo::BSONObj query = list->nextSafe();
799 result.push_back(getDocumentId(query));
807 const std::string& fileId,
810 const mongo::BSONObj fileQuery = BSON(
MONGO_ID_FIELD << mongo::OID(fileId));
811 auto gridfs = getGridFS(dbName);
813 std::unique_lock l(*accessGridFSFilesMutex);
814 mongo::GridFile gridFile = gridfs->findFile(fileQuery);
816 if (!gridFile.exists())
828 const std::string& gridFSName,
829 const Ice::Current&
c)
831 auto gridfs = getGridFS(dbName);
833 std::unique_lock l(*accessGridFSFilesMutex);
834 gridfs->removeFile(gridFSName);
846 count = getConnection().conn().count(ns);
848 catch (mongo::DBException& e)
850 ARMARX_ERROR <<
"Error on db.count(" << ns <<
"): " << e.what();
866 catch (mongo::AssertionException& e)
868 ARMARX_ERROR <<
"findByMongoId failed for id " <<
id <<
": " << e.what()
870 throw InvalidMongoIdException(e.what(),
id);
874 DBStorableDataList result = findByMongoQuery(ns, query,
true);
876 return result.size() > 0 ? result[0] : DBStorableData();
881 const std::string& fieldName,
882 const ::std::string& fieldValue)
884 const mongo::Query query = mongo::Query(BSON(fieldName << fieldValue));
885 return findByMongoQuery(ns, query,
false);
890 const std::string& fieldName,
891 const NameList& fieldValueList)
893 mongo::BSONArrayBuilder b;
895 for (
const auto& it : fieldValueList)
900 const mongo::Query query(BSON(fieldName << mongo::Query(BSON(
"$in" << b.arr()))));
901 return findByMongoQuery(ns, query,
false);
906 const std::string& fieldName,
907 const ::std::string& fieldValue)
909 const mongo::Query query = mongo::Query(BSON(fieldName << fieldValue));
910 const DBStorableDataList result = findByMongoQuery(ns, query,
false);
911 return result.size() > 0 ? result[0] : DBStorableData();
916 const std::string& query,
917 const std::string& where)
919 mongo::Query
q(query);
926 return findByMongoQuery(ns,
q,
false);
932 const DBStorableDataList result = findByMongoQuery(ns, mongo::Query(query),
false);
933 return result.size() > 0 ? result[0] : DBStorableData();
939 const mongo::Query query;
940 return findByMongoQuery(ns, query,
false);
946 auto conn = getConnection();
947 mongo::BSONObj fetch;
948 std::size_t dotPosition = ns.find_first_of(
".");
949 std::string databaseName = ns.substr(0, dotPosition);
950 std::string collectionName = ns.substr(dotPosition + 1, ns.size());
951 conn.conn().runCommand(
952 databaseName, BSON(
"distinct" << collectionName <<
"key" << fieldName), fetch);
953 mongo::BSONObj fetchedValues = fetch.getObjectField(
"values");
954 DBStorableData result;
955 result.JSON = fetchedValues.jsonString();
962 const mongo::Query query;
963 return (EntityIdList)findFieldByMongoQuery(ns, query,
MONGO_ID_FIELD);
969 const mongo::Query query;
970 return findFieldByMongoQuery(ns, query, fieldName);
974 CommonStorage::findFieldByMongoQuery(
const std::string& ns,
975 const mongo::Query& query,
976 const std::string& fieldName)
981 auto conn = getConnection();
982 boost::scoped_ptr<mongo::DBClientCursor> cursor(conn.conn().query(ns, query));
984 while (cursor->more())
986 result.push_back(getDocumentField(cursor->next(), fieldName));
989 catch (mongo::DBException& e)
991 ARMARX_ERROR <<
"Error fetching field values by query: " << e.what();
998 CommonStorage::findByMongoQuery(
const std::string& ns,
999 const mongo::Query& query,
1002 DBStorableDataList result;
1005 auto conn = getConnection();
1006 boost::scoped_ptr<mongo::DBClientCursor> cursor(
1007 conn.conn().query(ns, query, justOne ? 1 : 0));
1009 while (cursor->more())
1012 obj.JSON = cursor->nextSafe().jsonString();
1013 result.push_back(obj);
1016 catch (mongo::DBException& e)
1018 ARMARX_ERROR <<
"Error fetching objects by query: " << e.what();
1026 const DBStorableData& obj,
1029 std::string result =
"";
1033 mongo::BSONObj bsonObj = mongo::fromjson(obj.JSON);
1038 result = getDocumentId(bsonObj);
1043 mongo::BSONObjBuilder builder;
1044 mongo::OID newID = mongo::OID::gen();
1046 builder.appendElements(bsonObj);
1047 bsonObj = builder.obj();
1048 result = newID.toString();
1054 getConnection().conn().update(ns, query, bsonObj,
true);
1058 getConnection().conn().insert(ns, bsonObj);
1061 catch (mongo::DBException& e)
1063 ARMARX_ERROR <<
"Error inserting object: " << e.what();
1069 std::vector<std::string>
1072 std::vector<std::string> result(objectList.size(),
"");
1076 std::vector<mongo::BSONObj> bsonObjects;
1077 bsonObjects.reserve(objectList.size());
1079 for (
size_t i = 0; i < objectList.size(); i++)
1081 bsonObjects.push_back(mongo::fromjson(objectList[i].JSON));
1082 result[i] = getDocumentId(bsonObjects[i]);
1088 mongo::OID newID = mongo::OID::gen();
1089 result[i] = newID.toString();
1091 mongo::BSONObjBuilder builder;
1093 builder.appendElements(bsonObjects[i]);
1094 bsonObjects[i] = builder.obj();
1098 getConnection().conn().insert(ns, bsonObjects);
1100 catch (mongo::DBException& e)
1102 ARMARX_ERROR <<
"Error inserting object: " << e.what();
1110 const DBStorableData& obj,
1111 const std::string& keyField,
1114 bool result =
false;
1118 const mongo::BSONObj mongoObj = mongo::fromjson(obj.JSON);
1120 if (!mongoObj.hasField(keyField.c_str()))
1122 throw FieldNotFoundException(
"field not found in supplied JSON object", keyField);
1125 mongo::Query query(BSON(keyField << mongoObj[keyField]));
1127 getConnection().conn().update(ns, query, mongoObj, upsert);
1131 catch (
const mongo::DBException& e)
1141 const std::string& query,
1142 const mongo::BSONObj& obj)
1144 bool result =
false;
1148 conn->update(ns, query, obj);
1151 catch (mongo::DBException& e)
1169 catch (mongo::AssertionException& e)
1171 throw InvalidMongoIdException(e.what(),
id);
1175 return removeByMongoQuery(ns, query);
1180 const std::string& fieldName,
1181 const std::string& fieldValue)
1183 const mongo::Query query(BSON(fieldName << fieldValue));
1184 return removeByMongoQuery(ns, query);
1190 return removeByMongoQuery(ns, mongo::Query(query));
1196 return removeByMongoQuery(ns, mongo::Query());
1200 CommonStorage::removeByMongoQuery(
const std::string& ns,
const mongo::Query& query)
1206 getConnection().conn().remove(ns, query);
1209 catch (mongo::DBException& e)
1211 ARMARX_ERROR <<
"Error deleting objects by query: " << e.what();
1224 const mongo::BSONObj keys = BSON(fieldName << 1);
1228#ifdef MONGOCLIENT_VERSION
1229 getConnection().conn().createIndex(ns, keys);
1231 getConnection().conn().ensureIndex(ns, keys, unique);
1236 catch (mongo::DBException& e)
1244 CommonStorage::ConnectionWrapper::ConnectionWrapper(
1246 std::shared_ptr<mongo::DBClientConnection> connPtr) :
1247 connPtr{
std::move(connPtr)}, hostAndPort{storage.hostAndPort}, storage{&storage}
1251 CommonStorage::ConnectionWrapper::~ConnectionWrapper()
1253 std::lock_guard<std::mutex> guard{storage->serverSettingsMutex};
1254 if (hostAndPort == storage->hostAndPort)
1256 storage->pool.emplace_back(std::move(connPtr));
1260 mongo::DBClientConnection&
1261 CommonStorage::ConnectionWrapper::conn()
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
ArmarXObjectSchedulerPtr getObjectScheduler() const
The periodic task executes one thread method repeatedly using the time period specified in the constr...
Ice::PropertiesPtr getIceProperties() const
Returns the set of Ice properties.
The CommonStorage class provides an interface to MongoDB.
void onInitComponent() override
Pure virtual hook for the subclass.
bool isConnected(const ::Ice::Current &c=Ice::emptyCurrent) override
bool removeByMongoId(const std::string &ns, const std::string &id)
bool getBinaryFileById(const ::std::string &dbName, const ::std::string &fileId, memoryx::Blob &buffer, const ::Ice::Current &c=Ice::emptyCurrent) override
bool removeFileById(const ::std::string &dbName, const ::std::string &fileId, const ::Ice::Current &c=Ice::emptyCurrent) override
bool removeByQuery(const std::string &ns, const std::string &query)
void releaseCollection(const CollectionInterfacePrx &coll, const ::Ice::Current &c=Ice::emptyCurrent) override
GridFileInterfacePrx getFileProxyById(const ::std::string &dbName, const ::std::string &fileId, const ::Ice::Current &c=Ice::emptyCurrent) override
Ice::Int count(const std::string &ns)
bool clearCollection(const std::string &ns)
NameList getDBNames(const ::Ice::Current &=Ice::emptyCurrent) override
std::string storeBinaryFile(const ::std::string &dbName, const memoryx::Blob &bufferToStore, const ::std::string &gridFSName="", const ::Ice::Current &c=Ice::emptyCurrent) override
bool getTextFileById(const ::std::string &dbName, const ::std::string &fileId, ::std::string &buffer, const ::Ice::Current &c=Ice::emptyCurrent) override
DBStorableData findByMongoId(const std::string &ns, const std::string &id)
GridFileInterfacePrx getFileProxyByName(const ::std::string &dbName, const ::std::string &gridFSName, const ::Ice::Current &c=Ice::emptyCurrent) override
NameList getFileIdList(const std::string &dbName, const Ice::Current &c=Ice::emptyCurrent) override
bool removeFileByName(const ::std::string &dbName, const ::std::string &gridFSName, const ::Ice::Current &c=Ice::emptyCurrent) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
std::string insert(const std::string &ns, const DBStorableData &obj, bool upsert=false)
DBStorableDataList findByQuery(const std::string &ns, const std::string &query, const std::string &where="")
void releaseFileProxy(const GridFileInterfacePrx &fileProxy, const ::Ice::Current &c=Ice::emptyCurrent) override
bool removeByFieldValue(const std::string &ns, const std::string &fieldName, const std::string &fieldValue)
DBStorableDataList findAll(const std::string &ns)
NameList findAllFieldValues(const std::string &ns, const std::string &fieldName)
bool update(const std::string &ns, const DBStorableData &obj, const std::string &keyField, bool upsert=false)
std::string storeTextFile(const ::std::string &dbName, const ::std::string &bufferToStore, const ::std::string &gridFSName="", const ::Ice::Current &c=Ice::emptyCurrent) override
std::vector< std::string > insertList(const std::string &ns, const DBStorableDataList &objectList)
DBStorableData findOneByQuery(const std::string &ns, const std::string &query)
DBStorableData findOneByFieldValue(const std::string &ns, const std::string &fieldName, const ::std::string &fieldValue)
DBStorableDataList findByFieldValue(const std::string &ns, const std::string &fieldName, const ::std::string &fieldValue)
void onConnectComponent() override
Pure virtual hook for the subclass.
CollectionInterfacePrx requestCollection(const std::string &collectionNS, const ::Ice::Current &c=Ice::emptyCurrent) override
DBStorableData findAllUniqueByFieldName(const std::string &ns, const ::std::string &fieldName)
bool ensureIndex(const std::string &ns, const std::string &fieldName, bool unique)
DatabaseInterfacePrx requestDatabase(const ::std::string &dbName, const ::Ice::Current &=Ice::emptyCurrent) override
static std::string GetDefaultName()
NameList getCollectionNames(const ::std::string &dbName, const ::Ice::Current &=Ice::emptyCurrent) override
bool updateByQuery(const std::string &ns, const std::string &query, const mongo::BSONObj &obj)
EntityIdList findAllIds(const std::string &ns)
bool reconnect(const ::std::string &hostAndPort, const ::std::string &userName, const ::std::string &password, const ::Ice::Current &=Ice::emptyCurrent) override
void releaseDatabase(const DatabaseInterfacePrx &db, const ::Ice::Current &=Ice::emptyCurrent) override
bool authDB(const ::std::string &dbName, const ::std::string &userName, const ::std::string &password, const ::Ice::Current &=Ice::emptyCurrent) override
std::string storeFile(const ::std::string &dbName, const ::std::string &fileName, const ::std::string &gridFSName="", const ::Ice::Current &c=Ice::emptyCurrent) override
void onExitComponent() override
Hook for subclass.
void dropCollection(const std::string &collectionNS, const ::Ice::Current &c=Ice::emptyCurrent) override
NameList getFileNameList(const std::string &dbName, const Ice::Current &c=Ice::emptyCurrent) override
DBStorableDataList findByFieldValueList(const std::string &ns, const std::string &fieldName, const NameList &fieldValueList)
std::string getMongoHostAndPort(const ::Ice::Current &c=Ice::emptyCurrent) override
std::string getDefaultName() const override
Retrieve default name of component.
bool getBinaryFileByName(const ::std::string &dbName, const ::std::string &gridFSName, memoryx::Blob &buffer, const ::Ice::Current &c=Ice::emptyCurrent) override
void removeFileByQuery(const std::string &dbName, const mongo::BSONObj &fileQuery)
bool getTextFileByName(const ::std::string &dbName, const ::std::string &gridFSName, ::std::string &buffer, const ::Ice::Current &c=Ice::emptyCurrent) override
The Database class provides an interface to a database.
#define ARMARX_INFO
The normal logging level.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
#define ARMARX_WARNING_S
The logging level for unexpected behaviour, but not a serious problem.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
constexpr std::size_t find(string_view str, char_type c) noexcept
IceUtil::Handle< Database > DatabasePtr
IceInternal::Handle< GridFileWrapper > GridFileWrapperPtr
std::shared_ptr< mongo::GridFS > GridFSPtr
const char MONGO_ID_FIELD[]
IceUtil::Handle< Collection > CollectionPtr