CommonStorage.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package MemoryX::CommonStorage
17 * @author Alexey Kozlov ( kozlov at kit dot edu)
18 * @date 2012
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #include "CommonStorage.h"
24 #include "Database.h"
25 #include "Collection.h"
26 
27 
28 #include <ArmarXCore/interface/core/Log.h>
30 
31 #include <mongo/client/dbclient.h>
32 #include <mongo/client/dbclientinterface.h>
33 
34 #include <IceUtil/UUID.h>
35 #include <Ice/ObjectAdapter.h>
36 
37 #include <fstream>
38 
39 #include "GridFileWrapper.h"
40 
41 #include <filesystem>
42 
43 #include <memory>
44 
45 namespace memoryx
46 {
47  const char MONGO_ID_FIELD[] = "_id";
48 
49  std::string CommonStorage::getDefaultName() const
50  {
51  return "CommonStorage";
52  }
53 
55  {
56  // http://api.mongodb.com/cxx/current/namespacemongo_1_1client.html#aad4213a224b92333d2395839e4c81498
57  // initialize() MUST be called EXACTLY once after entering 'main' and before using the driver.
58  // Do not call initialize() before entering 'main' (i.e. from a static initializer), as it
59  // relies on all static initialization having been completed.
60  mongo::client::initialize();
61 
62  accessGridFSFilesMutex.reset(new std::mutex());
63  if (getProperty<std::string>("MongoHost").isSet())
64  {
65  hostAndPort = getProperty<std::string>("MongoHost").getValue();
66  }
67  else if (!getIceProperties()->getProperty("ArmarX.MongoHost").empty())
68  {
69  hostAndPort = getIceProperties()->getProperty("ArmarX.MongoHost");
70  }
71  else if (getenv("MONGODB_HOST"))
72  {
73  hostAndPort = getenv("MONGODB_HOST");
74  }
75  else
76  {
77  hostAndPort = getProperty<std::string>("MongoHost").getValue();
78  }
79 
80  if (hostAndPort.find(':') == std::string::npos)
81  {
82  if (!getIceProperties()->getProperty("ArmarX.MongoPort").empty())
83  {
84  hostAndPort += ":" + getIceProperties()->getProperty("ArmarX.MongoPort");
85  }
86  else if (getenv("MONGODB_PORT"))
87  {
88  hostAndPort += ":" + std::string(getenv("MONGODB_PORT"));
89  }
90  }
91 
92  ARMARX_IMPORTANT << "Using MongoDB on " << hostAndPort;
93  // dbName = getProperty<std::string>("MongoDBName").getValue();
94 
95  useAuth = getProperty<bool>("MongoAuth").getValue();
96  userName = getProperty<std::string>("MongoUser").getValue();
97 
98  connectionCheckerTask = new armarx::PeriodicTask<CommonStorage>(this, &CommonStorage::checkConnection, 1000);
99  }
100 
102  {
103  ARMARX_INFO << "Starting MemoryX::CommonStorage";
104 
105  while (!connect() && !this->getObjectScheduler()->isTerminationRequested())
106  {
107  sleep(5);
108  }
109 
110  pwdDigest = createPasswordDigest(userName, getProperty<std::string>("MongoPassword").getValue());
111  connectionCheckerTask->start();
112  ARMARX_INFO << "MemoryX::CommonStorage started";
113  }
114 
116  {
117  connectionCheckerTask->stop();
118  {
119  std::unique_lock l(openedDatabasesMutex);
120  openedDatabases.clear();
121  }
122  {
123  std::unique_lock l(openedCollectionsMutex);
124  openedCollections.clear();
125  }
126  {
127  std::unique_lock l(openedFilesMutex);
128  openedFiles.clear();
129  }
130  {
131  std::unique_lock l(openedGridFSMutex);
132  openedGridFS.clear();
133  }
134 
135  mongo::client::shutdown();
136  }
137 
139  {
141  }
142 
143  bool CommonStorage::connect()
144  {
145  try
146  {
147  openedGridFS.clear();
148  conn.reset(new mongo::DBClientConnection);
149  conn->connect(hostAndPort);
150  }
151  catch (const mongo::DBException& e)
152  {
153  ARMARX_ERROR << "Can't connect to MongoDB: " << e.what();
154  return false;
155  }
156  catch (const std::exception& e)
157  {
158  ARMARX_ERROR << "Can't connect to MongoDB: " << e.what();
159  return false;
160  }
161 
162  ARMARX_INFO << "Connected to Mongo: host = " << hostAndPort;
163 
164  return true;
165  }
166 
167 
168  void CommonStorage::checkConnection()
169  {
170  try
171  {
172  mongo::DBClientConnection conn;
173  conn.connect(hostAndPort);
174  conn.getDatabaseNames();
175  }
176  catch (...)
177  {
178  ARMARX_ERROR << "Connection to MongoDB lost";
179  this->getObjectScheduler()->disconnected(true);
180  }
181  }
182 
183  CommonStorage::ConnectionWrapper CommonStorage::getConnection()
184  {
185  std::shared_ptr<mongo::DBClientConnection> conn;
186  {
187  std::lock_guard<std::mutex> guard {serverSettingsMutex};
188  if (pool.empty())
189  {
190  while (true)
191  {
192  try
193  {
194  conn.reset(new mongo::DBClientConnection());
195  conn->connect(hostAndPort);
196  }
197  catch (std::exception& e)
198  {
199  ARMARX_ERROR << "Can't connect to MongoDB: " << e.what();
200  continue;
201  }
202  break;
203  }
204  }
205  else
206  {
207  conn = std::move(pool.front());
208  pool.pop_front();
209  }
210  }
211  return {*this, std::move(conn)};
212  }
213 
214  std::string CommonStorage::createPasswordDigest(const std::string& username, const std::string& password)
215  {
216  // No real connection is required here.
217  // In later versions of the API this is a static function
218  std::string digest = getConnection().conn().createPasswordDigest(username, password);
219  return digest;
220  }
221 
222  std::string CommonStorage::extractDBNameFromNS(const std::string& ns)
223  {
224  const size_t found = ns.find_first_of('.');
225  return (found != std::string::npos) ? ns.substr(0, found) : "";
226  }
227 
228  bool CommonStorage::forceAuthenticate(const std::string& dbName,
229  const std::string& userName, const std::string& password)
230  {
231  std::string errmsg;
232  bool result = false;
233  result = getConnection().conn().auth(dbName, userName, pwdDigest, errmsg, false);
234 
235  if (result)
236  {
237  authDBs.insert(dbName);
238  }
239 
240  return result;
241  }
242 
243  bool CommonStorage::authenticateNS(const std::string& ns)
244  {
245  const std::string dbName = extractDBNameFromNS(ns);
246 
247  // check that database part is present in ns string
248  if (dbName.empty())
249  {
250  throw DBNotSpecifiedException("Database name not specified for collection: " + ns +
251  ". Please use <dbName>.<collectionName> format!");
252  }
253 
254  return authenticateDB(dbName);
255  }
256 
257  bool CommonStorage::authenticateDB(const std::string& dbName)
258  {
259  if (!useAuth)
260  {
261  return true;
262  }
263 
264  ARMARX_INFO << "Try to Auth: db = " << dbName <<
265  ", user = " << userName << ", pwd = " << pwdDigest << std::endl;
266 
267  if (authDBs.count(dbName))
268  {
269  return true;
270  }
271  else
272  {
273  return forceAuthenticate(dbName, userName, pwdDigest);
274  }
275  }
276 
277  bool CommonStorage::authDB(const std::string& dbName,
278  const std::string& userName, const std::string& password,
279  const Ice::Current&)
280  {
281  pwdDigest = createPasswordDigest(userName, password);
282  return forceAuthenticate(dbName, userName, this->pwdDigest);
283  }
284 
285  std::string CommonStorage::getMongoHostAndPort(const ::Ice::Current& c)
286  {
287  return hostAndPort;
288  }
289 
290  NameList CommonStorage::getDBNames(const ::Ice::Current&)
291  {
292  authenticateDB("admin");
293 
294  {
295  std::list<std::string> result = getConnection().conn().getDatabaseNames();
296  return NameList(result.begin(), result.end());
297  }
298  }
299 
300  NameList CommonStorage::getCollectionNames(const ::std::string& dbName, const ::Ice::Current&)
301  {
302  std::list<std::string> result = getConnection().conn().getCollectionNames(dbName);
303  return NameList(result.begin(), result.end());
304  }
305 
306  bool CommonStorage::isConnected(const ::Ice::Current& c)
307  {
308  return true;
309  }
310 
311  bool CommonStorage::reconnect(const ::std::string& hostAndPort, const ::std::string& userName, const ::std::string& password,
312  const ::Ice::Current&)
313  {
314  this->hostAndPort = hostAndPort;
315  this->userName = userName;
316  this->pwdDigest = createPasswordDigest(userName, password);
317  this->useAuth = !userName.empty();
318  return connect();
319  }
320 
321  DatabaseInterfacePrx CommonStorage::requestDatabase(const ::std::string& dbName, const ::Ice::Current& c)
322  {
323  // authenticate if needed
324  if (authenticateDB(dbName))
325  {
326  DatabasePtr db = new Database(this, dbName);
327  Ice::Identity dbId = db->getIceId();
328  {
329  std::unique_lock l(openedDatabasesMutex);
330  openedDatabases[dbId] = db;
331  }
332  Ice::ObjectPrx node = c.adapter->add(db, dbId);
333  return DatabaseInterfacePrx::uncheckedCast(node);
334  }
335  else
336  {
337  throw MongoAuthenticationException("Mongo authentication failed (user = " + userName +
338  ", database = " + dbName + ")");
339  }
340  }
341 
342  void CommonStorage::releaseDatabase(const DatabaseInterfacePrx& db, const ::Ice::Current&)
343  {
344  std::unique_lock l(openedDatabasesMutex);
345  openedDatabases.erase(db->ice_getIdentity());
346  }
347 
348  CollectionInterfacePrx CommonStorage::requestCollection(const std::string& collectionNS, const ::Ice::Current& c)
349  {
350  // authenticate if needed
351  if (authenticateNS(collectionNS))
352  {
353  CollectionPtr coll = new Collection(this, collectionNS);
354  Ice::Identity collId = coll->getIceId();
355  {
356  std::unique_lock l(openedCollectionsMutex);
357  openedCollections[collId] = coll;
358  }
359  Ice::ObjectPrx node = c.adapter->add(coll, collId);
360  return CollectionInterfacePrx::uncheckedCast(node);
361  }
362  else
363  {
364  throw MongoAuthenticationException("Mongo authentication failed (user = " + userName +
365  ", collection = " + collectionNS + ")");
366  }
367  }
368 
369  void CommonStorage::releaseCollection(const CollectionInterfacePrx& coll, const ::Ice::Current& c)
370  {
371  std::unique_lock l(openedCollectionsMutex);
372  openedCollections.erase(coll->ice_getIdentity());
373  }
374 
375  void CommonStorage::dropCollection(const std::string& collectionNS, const ::Ice::Current& c)
376  {
377  // authenticate if needed
378  if (authenticateNS(collectionNS))
379  {
380  getConnection().conn().dropCollection(collectionNS);
381  }
382  else
383  {
384  throw MongoAuthenticationException("Mongo authentication failed (user = " + userName +
385  ", collection = " + collectionNS + ")");
386  }
387  }
388 
389  std::string CommonStorage::getDocumentId(const mongo::BSONObj& doc)
390  {
391  return getDocumentField(doc, MONGO_ID_FIELD);
392  }
393 
394  std::string CommonStorage::getDocumentField(const mongo::BSONObj& doc, const std::string& fieldName)
395  {
396  if (doc.hasField(fieldName.c_str()))
397  {
398  const mongo::BSONElement field = doc[fieldName.c_str()];
399 
400  switch (field.type())
401  {
402  case mongo::jstOID:
403  return field.OID().toString();
404 
405  case mongo::String:
406  return field.str();
407 
408  default:
409  return field.toString(false);
410  }
411  }
412  else
413  {
414  return "";
415  }
416  }
417 
418  GridFSPtr CommonStorage::getGridFS(const std::string& dbName)
419  {
420  std::unique_lock l(openedGridFSMutex);
421  std::map<std::string, GridFSPtr>::const_iterator it = openedGridFS.find(dbName);
422 
423  if (it != openedGridFS.end())
424  {
425  return it->second;
426  }
427  else
428  {
429  GridFSPtr gridFS(new mongo::GridFS(*conn, dbName));
430  openedGridFS[dbName] = gridFS;
431  return gridFS;
432  }
433  }
434 
435  std::string CommonStorage::storeFile(const std::string& dbName, const std::string& fileName,
436  const ::std::string& gridFSName /* = "" */, const Ice::Current& c)
437  {
438  GridFSPtr gridfs = getGridFS(dbName);
439 
440  {
441  ARMARX_DEBUG << "Storing file: " << VAROUT(gridFSName) << VAROUT(fileName);
442  if (!std::filesystem::exists(fileName))
443  {
444  throw FileNotFoundException("File could not be found: " + fileName, fileName);
445  }
446  std::unique_lock l(*accessGridFSFilesMutex);
447  mongo::GridFile oldFile = gridfs->findFileByName((gridFSName.empty()) ? fileName : gridFSName);
448  const mongo::BSONObj newFileDoc = gridfs->storeFile(fileName, gridFSName);
449  mongo::GridFile newFile = gridfs->findFileByName((gridFSName.empty()) ? fileName : gridFSName);
450 
451  std::string oldId;
452  if (keepOldFileIfEqual(oldFile, newFile, newFileDoc, dbName, oldId))
453  {
454  return oldId;
455  }
456 
457  return getDocumentId(newFileDoc);
458  }
459  }
460 
461  std::string CommonStorage::storeTextFile(const std::string& dbName,
462  const std::string& bufferToStore, const std::string& gridFSName,
463  const Ice::Current& c)
464  {
465  GridFSPtr gridfs = getGridFS(dbName);
466  {
467  if (gridFSName.empty())
468  {
469  throw armarx::LocalException("gridFSName must not be empty");
470  }
471  std::unique_lock l(*accessGridFSFilesMutex);
472  mongo::GridFile oldFile = gridfs->findFileByName(gridFSName);
473  const mongo::BSONObj newFileDoc = gridfs->storeFile(bufferToStore.c_str(), bufferToStore.size(), gridFSName);
474  mongo::GridFile newFile = gridfs->findFileByName(gridFSName);
475 
476  std::string oldId;
477  if (keepOldFileIfEqual(oldFile, newFile, newFileDoc, dbName, oldId))
478  {
479  return oldId;
480  }
481  return getDocumentId(newFileDoc);
482  }
483  }
484 
485  std::string CommonStorage::storeBinaryFile(const std::string& dbName,
486  const memoryx::Blob& bufferToStore, const std::string& gridFSName,
487  const Ice::Current& c)
488  {
489  GridFSPtr gridfs = getGridFS(dbName);
490  {
491  if (gridFSName.empty())
492  {
493  throw armarx::LocalException("gridFSName must not be empty");
494  }
495  std::unique_lock l(*accessGridFSFilesMutex);
496  mongo::GridFile oldFile = gridfs->findFileByName(gridFSName);
497 
498  const mongo::BSONObj newFileDoc = gridfs->storeFile(reinterpret_cast<const char*>(&bufferToStore[0]), bufferToStore.size(), gridFSName);
499  mongo::GridFile newFile = gridfs->findFileByName(gridFSName);
500 
501  std::string oldId;
502  if (keepOldFileIfEqual(oldFile, newFile, newFileDoc, dbName, oldId))
503  {
504  return oldId;
505  }
506 
507  return getDocumentId(newFileDoc);
508  }
509  }
510 
511  bool CommonStorage::keepOldFileIfEqual(const mongo::GridFile& oldFile, const mongo::GridFile newFile, const mongo::BSONObj& newFileDoc, const std::string dbName, std::string& oldId)
512  {
513  if (oldFile.exists())
514  {
515  std::string docId = (oldFile.getFileField("_id").OID().toString());
516 
517  if (!docId.empty() && newFile.getMD5() == oldFile.getMD5())
518  {
519  // keep old file
520  removeFileByQuery(dbName, newFileDoc);
521  oldId = docId;
522  return true;
523  }
524  }
525  return false;
526  }
527 
528  mongo::GridFile CommonStorage::getFileByQuery(const std::string& dbName,
529  const mongo::BSONObj& query)
530  {
531  GridFSPtr gfs = getGridFS(dbName);
532  {
533  // this mutex was needed to avoid crashes when multiple clients access GridFS
534  std::unique_lock l(*accessGridFSFilesMutex);
535  auto find = [&]()
536  {
537  mongo::GridFile gf = gfs->findFile(query);
538  if (!gf.exists())
539  {
540  ARMARX_WARNING_S << "Could not query file." << VAROUT(dbName) << ";" << VAROUT(query);
541  }
542  return gf;
543  };
544 
545  try
546  {
547  return find();
548  }
549  catch (...)
550  {
551  // dirty hack: try twice
552  return find();
553  }
554  }
555  }
556 
557  GridFileInterfacePrx CommonStorage::createFileProxy(mongo::GridFile gridFile, const Ice::Current& c)
558  {
559  if (gridFile.exists())
560  {
561  GridFileWrapperPtr fileWrapper = new GridFileWrapper(gridFile, accessGridFSFilesMutex);
562  Ice::Identity fileIceId = fileWrapper->getIceId();
563  {
564  std::unique_lock l(openedFilesMutex);
565  openedFiles[fileIceId] = fileWrapper;
566  }
567  Ice::ObjectPrx node = c.adapter->add(fileWrapper, fileIceId);
568  return GridFileInterfacePrx::uncheckedCast(node);
569  }
570  else
571  {
572  ARMARX_WARNING << "Grid file does not exit " << gridFile.getFilename();
573  return GridFileInterfacePrx();
574  }
575  }
576 
577  GridFileInterfacePrx CommonStorage::getFileProxyById(const std::string& dbName,
578  const std::string& fileId, const Ice::Current& c)
579  {
580  const mongo::BSONObj query = BSON(MONGO_ID_FIELD << mongo::OID(fileId));
581  mongo::GridFile gridFile = getFileByQuery(dbName, query);
582  return createFileProxy(gridFile, c);
583  }
584 
585  GridFileInterfacePrx CommonStorage::getFileProxyByName(const std::string& dbName,
586  const std::string& gridFSName, const Ice::Current& c)
587  {
588  const mongo::BSONObj query = BSON("filename" << gridFSName);
589  mongo::GridFile gridFile = getFileByQuery(dbName, query);
590  return createFileProxy(gridFile, c);
591  }
592 
593  void CommonStorage::releaseFileProxy(const GridFileInterfacePrx& fileProxy,
594  const Ice::Current& c)
595  {
596  if (fileProxy)
597  {
598  std::unique_lock l(openedFilesMutex);
599  c.adapter->remove(fileProxy->ice_getIdentity());
600  openedFiles.erase(fileProxy->ice_getIdentity());
601  }
602  }
603 
604  bool CommonStorage::readTextFile(mongo::GridFile& gridFile,
605  std::string& buffer)
606  {
607  if (gridFile.exists())
608  {
609  std::ostringstream ss;
610  gridFile.write(ss);
611  buffer = ss.str();
612  return true;
613  }
614  else
615  {
616  return false;
617  }
618  }
619 
620  bool CommonStorage::readBinaryFile(mongo::GridFile& gridFile,
621  memoryx::Blob& buffer)
622  {
623  if (gridFile.exists())
624  {
625  buffer.reserve(gridFile.getContentLength());
626  std::filebuf sb;
627  sb.pubsetbuf((char*) &buffer[0], buffer.capacity());
628  std::iostream os(&sb);
629  gridFile.write(os);
630  os.flush();
631  return true;
632  }
633  else
634  {
635  return false;
636  }
637  }
638 
639 
640  bool CommonStorage::getTextFileById(const std::string& dbName,
641  const std::string& fileId, std::string& buffer, const Ice::Current& c)
642  {
643  const mongo::BSONObj query = BSON(MONGO_ID_FIELD << mongo::OID(fileId));
644  mongo::GridFile gridFile = getFileByQuery(dbName, query);
645  return readTextFile(gridFile, buffer);
646  }
647 
648  bool CommonStorage::getBinaryFileById(const std::string& dbName,
649  const std::string& fileId, memoryx::Blob& buffer,
650  const Ice::Current& c)
651  {
652  const mongo::BSONObj query = BSON(MONGO_ID_FIELD << mongo::OID(fileId));
653  mongo::GridFile gridFile = getFileByQuery(dbName, query);
654  return readBinaryFile(gridFile, buffer);
655  }
656 
657  bool CommonStorage::getTextFileByName(const std::string& dbName,
658  const std::string& gridFSName, std::string& buffer,
659  const Ice::Current& c)
660  {
661  const mongo::BSONObj query = BSON("filename" << gridFSName);
662  mongo::GridFile gridFile = getFileByQuery(dbName, query);
663  return readTextFile(gridFile, buffer);
664  }
665 
666  bool CommonStorage::getBinaryFileByName(const std::string& dbName,
667  const std::string& gridFSName, memoryx::Blob& buffer,
668  const Ice::Current& c)
669  {
670  const mongo::BSONObj query = BSON("filename" << gridFSName);
671  mongo::GridFile gridFile = getFileByQuery(dbName, query);
672  return readBinaryFile(gridFile, buffer);
673  }
674 
675 
676  void CommonStorage::removeFileByQuery(const std::string& dbName, const mongo::BSONObj& fileQuery)
677  {
678  std::string GridFsFilesNamespace = dbName + ".fs.files";
679  std::string GridFsChunksNamespace = dbName + ".fs.chunks";
680 
681  try
682  {
683  auto conn = getConnection();
684  std::unique_ptr<mongo::DBClientCursor> files = conn.conn().query(GridFsFilesNamespace, fileQuery);
685 
686  while (files->more())
687  {
688  mongo::BSONObj file = files->next();
689  mongo::BSONElement id = file["_id"];
690  //ARMARX_LOG << "Removing {(files)_id: " << id << "} from database [" << dbName << "]";
691  conn.conn().remove(GridFsFilesNamespace, BSON("_id" << id));
692  conn.conn().remove(GridFsChunksNamespace, BSON("files_id" << id));
693  }
694  }
695  catch (mongo::DBException& e)
696  {
697  ARMARX_ERROR << "Error removing file by query " << fileQuery << ": " << e.what();
698  }
699  }
700 
701  NameList CommonStorage::getFileNameList(const std::string& dbName, const Ice::Current& c)
702  {
703  NameList result;
704  auto gridfs = getGridFS(dbName);
705  std::unique_ptr<mongo::DBClientCursor> list = gridfs->list();
706 
707  while (list->more())
708  {
709  mongo::BSONObj query = list->nextSafe();
710  auto file = getFileByQuery(dbName, query);
711  // ARMARX_INFO << file.getFilename() << " - " << file.getContentType();
712  result.push_back(file.getFilename());
713  }
714 
715  return result;
716  }
717 
718  NameList CommonStorage::getFileIdList(const std::string& dbName, const Ice::Current& c)
719  {
720  NameList result;
721  auto gridfs = getGridFS(dbName);
722  {
723  std::unique_lock l(*accessGridFSFilesMutex);
724 
725  std::unique_ptr<mongo::DBClientCursor> list = gridfs->list();
726 
727  while (list->more())
728  {
729  mongo::BSONObj query = list->nextSafe();
730  result.push_back(getDocumentId(query));
731  }
732  }
733  return result;
734  }
735 
736 
737  bool CommonStorage::removeFileById(const std::string& dbName,
738  const std::string& fileId, const Ice::Current&)
739  {
740  const mongo::BSONObj fileQuery = BSON(MONGO_ID_FIELD << mongo::OID(fileId));
741  auto gridfs = getGridFS(dbName);
742  {
743  std::unique_lock l(*accessGridFSFilesMutex);
744  mongo::GridFile gridFile = gridfs->findFile(fileQuery);
745 
746  if (!gridFile.exists())
747  {
748  return false;
749  }
750  }
751 
752  removeFileByQuery(dbName, fileQuery);
753  return true;
754  }
755 
756  bool CommonStorage::removeFileByName(const std::string& dbName,
757  const std::string& gridFSName, const Ice::Current& c)
758  {
759  auto gridfs = getGridFS(dbName);
760  {
761  std::unique_lock l(*accessGridFSFilesMutex);
762  gridfs->removeFile(gridFSName);
763  }
764  return true;
765  }
766 
767 
768  Ice::Int CommonStorage::count(const std::string& ns)
769  {
770  Ice::Int count = 0;
771 
772  try
773  {
774  count = getConnection().conn().count(ns);
775  }
776  catch (mongo::DBException& e)
777  {
778  ARMARX_ERROR << "Error on db.count(" << ns << "): " << e.what();
779  }
780 
781  return count;
782  }
783 
784  DBStorableData CommonStorage::findByMongoId(const std::string& ns, const std::string& id)
785  {
786  // try to init mongo id from provided string
787  mongo::OID oid;
788 
789  try
790  {
791  oid.init(id);
792  }
793  catch (mongo::AssertionException& e)
794  {
795  ARMARX_ERROR << "findByMongoId failed for id " << id << ": " << e.what() << "\nNS: " << ns;
796  throw InvalidMongoIdException(e.what(), id);
797  }
798 
799  mongo::Query query = mongo::Query(BSON(MONGO_ID_FIELD << oid));
800  DBStorableDataList result = findByMongoQuery(ns, query, true);
801 
802  return result.size() > 0 ? result[0] : DBStorableData();
803  }
804 
805  DBStorableDataList CommonStorage::findByFieldValue(const std::string& ns, const std::string& fieldName, const ::std::string& fieldValue)
806  {
807  const mongo::Query query = mongo::Query(BSON(fieldName << fieldValue));
808  return findByMongoQuery(ns, query, false);
809  }
810 
811  DBStorableDataList CommonStorage::findByFieldValueList(const std::string& ns, const std::string& fieldName, const NameList& fieldValueList)
812  {
813  mongo::BSONArrayBuilder b;
814 
815  for (const auto& it : fieldValueList)
816  {
817  b.append(it);
818  }
819 
820  const mongo::Query query(BSON(fieldName << mongo::Query(BSON("$in" << b.arr()))));
821  return findByMongoQuery(ns, query, false);
822  }
823 
824  DBStorableData CommonStorage::findOneByFieldValue(const std::string& ns, const std::string& fieldName, const ::std::string& fieldValue)
825  {
826  const mongo::Query query = mongo::Query(BSON(fieldName << fieldValue));
827  const DBStorableDataList result = findByMongoQuery(ns, query, false);
828  return result.size() > 0 ? result[0] : DBStorableData();
829  }
830 
831  DBStorableDataList CommonStorage::findByQuery(const std::string& ns, const std::string& query, const std::string& where)
832  {
833  mongo::Query q(query);
834 
835  if (!where.empty())
836  {
837  q.where(where);
838  }
839 
840  return findByMongoQuery(ns, q, false);
841  }
842 
843  DBStorableData CommonStorage::findOneByQuery(const std::string& ns, const std::string& query)
844  {
845  const DBStorableDataList result = findByMongoQuery(ns, mongo::Query(query), false);
846  return result.size() > 0 ? result[0] : DBStorableData();
847  }
848 
849  DBStorableDataList CommonStorage::findAll(const std::string& ns)
850  {
851  const mongo::Query query;
852  return findByMongoQuery(ns, query, false);
853  }
854 
855  DBStorableData CommonStorage::findAllUniqueByFieldName(const std::string& ns, const ::std::string& fieldName)
856  {
857  auto conn = getConnection();
858  mongo::BSONObj fetch;
859  std::size_t dotPosition = ns.find_first_of(".");
860  std::string databaseName = ns.substr(0, dotPosition);
861  std::string collectionName = ns.substr(dotPosition + 1, ns.size());
862  conn.conn().runCommand(databaseName, BSON("distinct" << collectionName << "key" << fieldName), fetch);
863  mongo::BSONObj fetchedValues = fetch.getObjectField("values");
864  DBStorableData result;
865  result.JSON = fetchedValues.jsonString();
866  return result;
867  }
868 
869  EntityIdList CommonStorage::findAllIds(const std::string& ns)
870  {
871  const mongo::Query query;
872  return (EntityIdList) findFieldByMongoQuery(ns, query, MONGO_ID_FIELD);
873  }
874 
875  NameList CommonStorage::findAllFieldValues(const std::string& ns, const std::string& fieldName)
876  {
877  const mongo::Query query;
878  return findFieldByMongoQuery(ns, query, fieldName);
879  }
880 
881 
882  NameList CommonStorage::findFieldByMongoQuery(const std::string& ns, const mongo::Query& query, const std::string& fieldName)
883  {
884  NameList result;
885  try
886  {
887  auto conn = getConnection();
888  boost::scoped_ptr<mongo::DBClientCursor> cursor(conn.conn().query(ns, query));
889 
890  while (cursor->more())
891  {
892  result.push_back(getDocumentField(cursor->next(), fieldName));
893  }
894  }
895  catch (mongo::DBException& e)
896  {
897  ARMARX_ERROR << "Error fetching field values by query: " << e.what();
898  }
899 
900  return result;
901  }
902 
903  DBStorableDataList CommonStorage::findByMongoQuery(const std::string& ns, const mongo::Query& query,
904  bool justOne /* = false */)
905  {
906  DBStorableDataList result;
907  try
908  {
909  auto conn = getConnection();
910  boost::scoped_ptr<mongo::DBClientCursor> cursor(conn.conn().query(ns, query, justOne ? 1 : 0));
911 
912  while (cursor->more())
913  {
914  DBStorableData obj;
915  obj.JSON = cursor->nextSafe().jsonString();
916  result.push_back(obj);
917  }
918  }
919  catch (mongo::DBException& e)
920  {
921  ARMARX_ERROR << "Error fetching objects by query: " << e.what();
922  }
923 
924  return result;
925  }
926 
927  std::string CommonStorage::insert(const std::string& ns, const DBStorableData& obj,
928  bool upsert /* = false */)
929  {
930  std::string result = "";
931 
932  try
933  {
934  mongo::BSONObj bsonObj = mongo::fromjson(obj.JSON);
935 
936  // check if _id field already present; if not, it must be generated here
937  if (bsonObj.hasField(MONGO_ID_FIELD))
938  {
939  result = getDocumentId(bsonObj);
940  }
941  else
942  {
943  // we need this trick to return generated mongoID to caller
944  mongo::BSONObjBuilder builder;
945  mongo::OID newID = mongo::OID::gen();
946  builder.append(MONGO_ID_FIELD, newID);
947  builder.appendElements(bsonObj);
948  bsonObj = builder.obj();
949  result = newID.toString();
950  }
951 
952  if (upsert)
953  {
954  mongo::Query query = mongo::Query(BSON(MONGO_ID_FIELD << bsonObj[MONGO_ID_FIELD]));
955  getConnection().conn().update(ns, query, bsonObj, true);
956  }
957  else
958  {
959  getConnection().conn().insert(ns, bsonObj);
960  }
961 
962  }
963  catch (mongo::DBException& e)
964  {
965  ARMARX_ERROR << "Error inserting object: " << e.what();
966  }
967 
968  return result;
969  }
970 
971  std::vector<std::string> CommonStorage::insertList(const std::string& ns, const DBStorableDataList& objectList)
972  {
973  std::vector<std::string> result(objectList.size(), "");
974 
975  try
976  {
977  std::vector<mongo::BSONObj> bsonObjects;
978  bsonObjects.reserve(objectList.size());
979 
980  for (size_t i = 0; i < objectList.size(); i++)
981  {
982  bsonObjects.push_back(mongo::fromjson(objectList[i].JSON));
983  result[i] = getDocumentId(bsonObjects[i]);
984 
985  // check if _id field already present; if not, it must be generated here
986  if (!bsonObjects[i].hasField(MONGO_ID_FIELD))
987  {
988  // we need this trick to return the generated mongoID to caller
989  mongo::OID newID = mongo::OID::gen();
990  result[i] = newID.toString();
991 
992  mongo::BSONObjBuilder builder;
993  builder.append(MONGO_ID_FIELD, newID);
994  builder.appendElements(bsonObjects[i]);
995  bsonObjects[i] = builder.obj();
996  }
997  }
998 
999  getConnection().conn().insert(ns, bsonObjects);
1000  }
1001  catch (mongo::DBException& e)
1002  {
1003  ARMARX_ERROR << "Error inserting object: " << e.what();
1004  }
1005 
1006  return result;
1007  }
1008 
1009  bool CommonStorage::update(const std::string& ns, const DBStorableData& obj, const std::string& keyField,
1010  bool upsert /*= false*/)
1011  {
1012  bool result = false;
1013 
1014  try
1015  {
1016  const mongo::BSONObj mongoObj = mongo::fromjson(obj.JSON);
1017 
1018  if (!mongoObj.hasField(keyField.c_str()))
1019  {
1020  throw FieldNotFoundException("field not found in supplied JSON object", keyField);
1021  }
1022 
1023  mongo::Query query(BSON(keyField << mongoObj[keyField]));
1024  {
1025  getConnection().conn().update(ns, query, mongoObj, upsert);
1026  }
1027  result = true;
1028  }
1029  catch (const mongo::DBException& e)
1030  {
1031  ARMARX_ERROR << "Error updating object: " << e.what();
1032  }
1033 
1034  return result;
1035  }
1036 
1037  bool CommonStorage::updateByQuery(const std::string& ns, const std::string& query, const mongo::BSONObj& obj)
1038  {
1039  bool result = false;
1040 
1041  try
1042  {
1043  conn->update(ns, query, obj);
1044  result = true;
1045  }
1046  catch (mongo::DBException& e)
1047  {
1048  ARMARX_ERROR << "Error updating object: " << e.what();
1049  }
1050 
1051  return result;
1052  }
1053 
1054  bool CommonStorage::removeByMongoId(const std::string& ns, const std::string& id)
1055  {
1056  // try to init mongo id from provided string
1057  mongo::OID oid;
1058 
1059  try
1060  {
1061  oid.init(id);
1062  }
1063  catch (mongo::AssertionException& e)
1064  {
1065  throw InvalidMongoIdException(e.what(), id);
1066  }
1067 
1068  mongo::Query query(BSON(MONGO_ID_FIELD << oid));
1069  return removeByMongoQuery(ns, query);
1070  }
1071 
1072  bool CommonStorage::removeByFieldValue(const std::string& ns, const std::string& fieldName, const std::string& fieldValue)
1073  {
1074  const mongo::Query query(BSON(fieldName << fieldValue));
1075  return removeByMongoQuery(ns, query);
1076  }
1077 
1078  bool CommonStorage::removeByQuery(const std::string& ns, const std::string& query)
1079  {
1080  return removeByMongoQuery(ns, mongo::Query(query));
1081  }
1082 
1083  bool CommonStorage::clearCollection(const std::string& ns)
1084  {
1085  return removeByMongoQuery(ns, mongo::Query());
1086  }
1087 
1088  bool CommonStorage::removeByMongoQuery(const std::string& ns, const mongo::Query& query)
1089  {
1090  int result = false;
1091 
1092  try
1093  {
1094  getConnection().conn().remove(ns, query);
1095  result = true;
1096  }
1097  catch (mongo::DBException& e)
1098  {
1099  ARMARX_ERROR << "Error deleting objects by query: " << e.what();
1100  }
1101 
1102  return result;
1103  }
1104 
1105  bool CommonStorage::ensureIndex(const std::string& ns, const std::string& fieldName, bool unique)
1106  {
1107  int result = false;
1108 
1109  try
1110  {
1111  const mongo::BSONObj keys = BSON(fieldName << 1);
1112  // the ubuntu 14.4 version of the lib does not has a define to querry the version
1113  // due to breaking changes in the interface, we have to call different functions here.
1114  // so we use the macro MONGOCLIENT_VERSION to decide which interface version we use
1115 #ifdef MONGOCLIENT_VERSION
1116  getConnection().conn().createIndex(ns, keys);
1117 #else
1118  getConnection().conn().ensureIndex(ns, keys, unique);
1119 #endif
1120 
1121  result = true;
1122  }
1123  catch (mongo::DBException& e)
1124  {
1125  ARMARX_ERROR << "Error ensuring index: " << e.what();
1126  }
1127 
1128  return result;
1129  }
1130 
1131 
1132  CommonStorage::ConnectionWrapper::ConnectionWrapper(CommonStorage& storage, std::shared_ptr<mongo::DBClientConnection> connPtr):
1133  connPtr{std::move(connPtr)}, hostAndPort{storage.hostAndPort}, storage{&storage}
1134  {}
1135 
1136  CommonStorage::ConnectionWrapper::~ConnectionWrapper()
1137  {
1138  std::lock_guard<std::mutex> guard {storage->serverSettingsMutex};
1139  if (hostAndPort == storage->hostAndPort)
1140  {
1141  storage->pool.emplace_back(std::move(connPtr));
1142  }
1143  }
1144 
1145  mongo::DBClientConnection& CommonStorage::ConnectionWrapper::conn()
1146  {
1147  return *connPtr;
1148  }
1149 }
files
Use of this software is granted under one of the following two to be chosen freely by the user Boost Software License Version Marcin Kalicinski Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this and transmit the and to prepare derivative works of the and to permit third parties to whom the Software is furnished to do all subject to the including the above license this restriction and the following must be included in all copies of the in whole or in and all derivative works of the unless such copies or derivative works are solely in the form of machine executable object code generated by a source language processor THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF FITNESS FOR A PARTICULAR TITLE AND NON INFRINGEMENT IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN TORT OR ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE The MIT Marcin Kalicinski Permission is hereby free of to any person obtaining a copy of this software and associated documentation files(the "Software")
memoryx::CommonStorage::authDB
bool authDB(const ::std::string &dbName, const ::std::string &userName, const ::std::string &password, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: CommonStorage.cpp:277
memoryx::CommonStorage::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: CommonStorage.cpp:101
memoryx::CommonStorage::getCollectionNames
NameList getCollectionNames(const ::std::string &dbName, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: CommonStorage.cpp:300
memoryx::CommonStorage::getTextFileById
bool getTextFileById(const ::std::string &dbName, const ::std::string &fileId, ::std::string &buffer, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: CommonStorage.cpp:640
memoryx::CommonStorage::findByFieldValue
DBStorableDataList findByFieldValue(const std::string &ns, const std::string &fieldName, const ::std::string &fieldValue)
Definition: CommonStorage.cpp:805
memoryx::CommonStorage::releaseCollection
void releaseCollection(const CollectionInterfacePrx &coll, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: CommonStorage.cpp:369
memoryx::CommonStorage::count
Ice::Int count(const std::string &ns)
Definition: CommonStorage.cpp:768
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
memoryx::CommonStorage::removeByFieldValue
bool removeByFieldValue(const std::string &ns, const std::string &fieldName, const std::string &fieldValue)
Definition: CommonStorage.cpp:1072
CommonStorage.h
GridFileWrapper.h
memoryx::CommonStorage::findByMongoId
DBStorableData findByMongoId(const std::string &ns, const std::string &id)
Definition: CommonStorage.cpp:784
memoryx::CommonStorage::clearCollection
bool clearCollection(const std::string &ns)
Definition: CommonStorage.cpp:1083
list
list(APPEND SOURCES ${QT_RESOURCES}) set(COMPONENT_LIBS ArmarXGui ArmarXCoreObservers ArmarXCoreEigen3Variants PlotterController $
Definition: CMakeLists.txt:49
memoryx::CommonStorage::removeFileByName
bool removeFileByName(const ::std::string &dbName, const ::std::string &gridFSName, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: CommonStorage.cpp:756
memoryx::CommonStorage::findAll
DBStorableDataList findAll(const std::string &ns)
Definition: CommonStorage.cpp:849
memoryx::CommonStorage::storeFile
std::string storeFile(const ::std::string &dbName, const ::std::string &fileName, const ::std::string &gridFSName="", const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: CommonStorage.cpp:435
memoryx::CommonStorage::getMongoHostAndPort
std::string getMongoHostAndPort(const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: CommonStorage.cpp:285
memoryx::CommonStorage::insert
std::string insert(const std::string &ns, const DBStorableData &obj, bool upsert=false)
Definition: CommonStorage.cpp:927
memoryx::CommonStoragePropertyDefinitions
Definition: CommonStorage.h:51
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
memoryx::CommonStorage::findAllFieldValues
NameList findAllFieldValues(const std::string &ns, const std::string &fieldName)
Definition: CommonStorage.cpp:875
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
memoryx::CommonStorage::findByQuery
DBStorableDataList findByQuery(const std::string &ns, const std::string &query, const std::string &where="")
Definition: CommonStorage.cpp:831
Collection.h
memoryx::CommonStorage::storeBinaryFile
std::string storeBinaryFile(const ::std::string &dbName, const memoryx::Blob &bufferToStore, const ::std::string &gridFSName="", const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: CommonStorage.cpp:485
memoryx::CommonStorage::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: CommonStorage.cpp:115
memoryx::Collection
Definition: Collection.h:33
memoryx::CommonStorage::findAllUniqueByFieldName
DBStorableData findAllUniqueByFieldName(const std::string &ns, const ::std::string &fieldName)
Definition: CommonStorage.cpp:855
memoryx::CommonStorage::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: CommonStorage.cpp:54
cxxopts::empty
bool empty(const std::string &s)
Definition: cxxopts.hpp:255
memoryx::CommonStorage::updateByQuery
bool updateByQuery(const std::string &ns, const std::string &query, const mongo::BSONObj &obj)
Definition: CommonStorage.cpp:1037
memoryx::CommonStorage::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: CommonStorage.cpp:49
memoryx::CommonStorage::storeTextFile
std::string storeTextFile(const ::std::string &dbName, const ::std::string &bufferToStore, const ::std::string &gridFSName="", const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: CommonStorage.cpp:461
memoryx::CommonStorage::removeFileById
bool removeFileById(const ::std::string &dbName, const ::std::string &fileId, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: CommonStorage.cpp:737
memoryx::CommonStorage::getBinaryFileById
bool getBinaryFileById(const ::std::string &dbName, const ::std::string &fileId, memoryx::Blob &buffer, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: CommonStorage.cpp:648
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:523
memoryx::CommonStorage::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: CommonStorage.cpp:138
memoryx::CommonStorage::getFileNameList
NameList getFileNameList(const std::string &dbName, const Ice::Current &c=Ice::emptyCurrent) override
Definition: CommonStorage.cpp:701
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
memoryx::CommonStorage::requestCollection
CollectionInterfacePrx requestCollection(const std::string &collectionNS, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: CommonStorage.cpp:348
memoryx::CommonStorage::findOneByFieldValue
DBStorableData findOneByFieldValue(const std::string &ns, const std::string &fieldName, const ::std::string &fieldValue)
Definition: CommonStorage.cpp:824
memoryx::CommonStorage::reconnect
bool reconnect(const ::std::string &hostAndPort, const ::std::string &userName, const ::std::string &password, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: CommonStorage.cpp:311
ArmarXObjectScheduler.h
memoryx::CommonStorage::findByFieldValueList
DBStorableDataList findByFieldValueList(const std::string &ns, const std::string &fieldName, const NameList &fieldValueList)
Definition: CommonStorage.cpp:811
memoryx::CommonStorage::removeFileByQuery
void removeFileByQuery(const std::string &dbName, const mongo::BSONObj &fileQuery)
Definition: CommonStorage.cpp:676
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
memoryx::CommonStorage::releaseDatabase
void releaseDatabase(const DatabaseInterfacePrx &db, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: CommonStorage.cpp:342
memoryx::MONGO_ID_FIELD
const char MONGO_ID_FIELD[]
Definition: CommonStorage.cpp:47
memoryx::CommonStorage::dropCollection
void dropCollection(const std::string &collectionNS, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: CommonStorage.cpp:375
q
#define q
memoryx::CommonStorage::getDBNames
NameList getDBNames(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: CommonStorage.cpp:290
ARMARX_WARNING_S
#define ARMARX_WARNING_S
Definition: Logging.h:206
Database.h
memoryx::Database
The Database class provides an interface to a database.
Definition: Database.h:35
memoryx::CommonStorage::getFileIdList
NameList getFileIdList(const std::string &dbName, const Ice::Current &c=Ice::emptyCurrent) override
Definition: CommonStorage.cpp:718
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
memoryx::CommonStorage::getTextFileByName
bool getTextFileByName(const ::std::string &dbName, const ::std::string &gridFSName, ::std::string &buffer, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: CommonStorage.cpp:657
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::PropertyUser::getProperty
Property< PropertyType > getProperty(const std::string &name)
Property creation and retrieval.
Definition: PropertyUser.h:179
VAROUT
#define VAROUT(x)
Definition: StringHelpers.h:182
memoryx::CommonStorage::getFileProxyByName
GridFileInterfacePrx getFileProxyByName(const ::std::string &dbName, const ::std::string &gridFSName, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: CommonStorage.cpp:585
memoryx::GridFileWrapperPtr
IceInternal::Handle< GridFileWrapper > GridFileWrapperPtr
Definition: CommonStorage.h:48
IceUtil::Handle< class PropertyDefinitionContainer >
memoryx::CommonStorage::getFileProxyById
GridFileInterfacePrx getFileProxyById(const ::std::string &dbName, const ::std::string &fileId, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: CommonStorage.cpp:577
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:916
memoryx::CommonStorage::releaseFileProxy
void releaseFileProxy(const GridFileInterfacePrx &fileProxy, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: CommonStorage.cpp:593
memoryx::CommonStorage::isConnected
bool isConnected(const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: CommonStorage.cpp:306
cxxopts::String
std::string String
Definition: cxxopts.hpp:209
memoryx::CommonStorage::removeByMongoId
bool removeByMongoId(const std::string &ns, const std::string &id)
Definition: CommonStorage.cpp:1054
armarx::PropertyUser::getIceProperties
Ice::PropertiesPtr getIceProperties() const
Returns the set of Ice properties.
Definition: PropertyUser.cpp:229
armarx::PeriodicTask
Definition: ArmarXManager.h:70
memoryx::CommonStorage::removeByQuery
bool removeByQuery(const std::string &ns, const std::string &query)
Definition: CommonStorage.cpp:1078
memoryx::CommonStorage::update
bool update(const std::string &ns, const DBStorableData &obj, const std::string &keyField, bool upsert=false)
Definition: CommonStorage.cpp:1009
memoryx::CommonStorage::requestDatabase
DatabaseInterfacePrx requestDatabase(const ::std::string &dbName, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: CommonStorage.cpp:321
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
memoryx::CommonStorage::findOneByQuery
DBStorableData findOneByQuery(const std::string &ns, const std::string &query)
Definition: CommonStorage.cpp:843
memoryx::CommonStorage::findAllIds
EntityIdList findAllIds(const std::string &ns)
Definition: CommonStorage.cpp:869
memoryx::CommonStorage::ensureIndex
bool ensureIndex(const std::string &ns, const std::string &fieldName, bool unique)
Definition: CommonStorage.cpp:1105
armarx::ManagedIceObject::getObjectScheduler
ArmarXObjectSchedulerPtr getObjectScheduler() const
Definition: ManagedIceObject.cpp:731
memoryx::CommonStorage::insertList
std::vector< std::string > insertList(const std::string &ns, const DBStorableDataList &objectList)
Definition: CommonStorage.cpp:971
memoryx::CommonStorage::getBinaryFileByName
bool getBinaryFileByName(const ::std::string &dbName, const ::std::string &gridFSName, memoryx::Blob &buffer, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: CommonStorage.cpp:666
memoryx::CommonStorage
The CommonStorage class provides an interface to MongoDB.
Definition: CommonStorage.h:74
memoryx::GridFSPtr
std::shared_ptr< mongo::GridFS > GridFSPtr
Definition: CommonStorage.h:49