CARMA C++
PDB_MongoDB.h
1 /*
2  * CARMA Project Database MongoDB Utilities
3  */
4 
5 #ifndef CARMA_OBSERVERTOOLS_PDB_MONGODB_H
6 #define CARMA_OBSERVERTOOLS_PDB_MONGODB_H
7 
8 #include <carma/observertools/ProjectDatabaseManager.h>
9 #include <carma/observertools/ProjectDatabaseManagerImpl.h>
10 
11 #include <mongo/client/dbclient.h>
12 #include <mongo/bson/bsonobj.h>
13 
14 #include <boost/shared_ptr.hpp>
15 
16 #include <string>
17 
18 typedef boost::shared_ptr<mongo::DBClientConnection> DBClientConnectionPtr;
19 
20 namespace carma {
21 namespace observertools {
22 
23 struct PDB_DB_Params {
24  const DBClientConnectionPtr conn;
25 
26  const std::string DATABASE_NAME;
27 
28  const std::string PROJECTS;
29  const std::string OBSBLOCKS;
30  const std::string SUBOBSBLOCKS;
31  const std::string TRIALS;
32  const std::string SCRIPTS;
33 
34  // Constructor
35  PDB_DB_Params(const PDBMArgs &args);
36 
37  // Helper
38  std::string getCollection(const std::string &name) const;
39 };
40 
41 // Initialize the MongoDB Database Client Driver
42 // Only needs to be run once per application startup
43 void initializeDatabaseClientDriver();
44 
45 // Add all of the necessary database indexes
46 void addDatabaseIndexes(const PDB_DB_Params &db);
47 
48 // Generate a MongoDB database query from a BSON Object
49 mongo::BSONObj generateQueryFromBSONObject(const mongo::BSONObj &obj);
50 
51 // Remove a single BSON Object from the database
52 void removeFromDatabase(const DBClientConnectionPtr conn, const std::string &collection, const mongo::Query &query);
53 
54 // Write a single BSON Object to the database
55 void writeToDatabase(const DBClientConnectionPtr conn, const std::string &collection, const mongo::Query &query, const mongo::BSONObj &obj);
56 
57 // Check to see if a document exists in the database
58 bool documentExists(const DBClientConnectionPtr conn, const std::string &collection, const mongo::BSONObj &query);
59 
60 } // namespace carma::observertools
61 } // namespace carma
62 
63 #endif /* CARMA_OBSERVERTOOLS_PDB_MONGODB_H */
64 
65 /* vim: set ts=8 sts=8 sw=8 noet tw=92: */