AOSharedServiceLibrary
mongo_interface.h
1 /*
2 MIT License Block
3 
4 Copyright (c) 2016 Alex Barry
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12 
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 THE SOFTWARE.
23 */
24 
25 #ifndef AOSSL_MONGO_INCLUDE_MONGO_INTERFACE_H_
26 #define AOSSL_MONGO_INCLUDE_MONGO_INTERFACE_H_
27 
28 #include <string>
29 #include <exception>
30 #include <vector>
31 
32 #include "mongo_buffer_interface.h"
33 
35 struct MongoException: public std::exception {
37  std::string int_msg;
38  const char * what_str;
39 
41  inline MongoException(std::string msg) {
42  int_msg = "Error in Mongo Request: " + msg;
43  what_str = int_msg.c_str();
44  }
45 
46  MongoException() {}
47  ~MongoException() throw() {}
48 
50  const char * what() const throw() {
51  return what_str;
52  }
53 };
54 
57  public:
58  virtual ~MongoResponseInterface() {}
60  virtual std::string get_value() = 0;
61  virtual std::string get_err_msg() = 0;
62 };
63 
66  public:
67  virtual ~MongoIteratorInterface() {}
69 
72  virtual MongoResponseInterface* next() = 0;
73 };
74 
76  public:
78  virtual ~MongoInterface() {}
79 
80  // CRUD Operations
81 
83  virtual MongoResponseInterface* create_document(const char * doc, \
84  const char * collection_name) = 0;
86  virtual MongoResponseInterface* create_document(const char * doc) = 0;
88  virtual MongoResponseInterface* create_document(std::string doc) = 0;
90  virtual MongoResponseInterface* create_document(std::string doc, \
91  std::string collection_name) = 0;
93  virtual MongoResponseInterface* create_document(AOSSL::MongoBufferInterface *document) = 0;
94 
96  virtual void delete_document(const char * key) = 0;
98  virtual void delete_document(std::string key) = 0;
100  virtual void delete_document(const char * key, \
101  const char * collection_name) = 0;
103  virtual void delete_document(std::string key, \
104  std::string collection_name) = 0;
105 
107  virtual MongoResponseInterface* load_document(const char * key) = 0;
109  virtual MongoResponseInterface* load_document(std::string key) = 0;
111  virtual MongoResponseInterface* load_document(const char * key, \
112  const char * collection_name) = 0;
114  virtual MongoResponseInterface* load_document(std::string key, \
115  std::string collection_name) = 0;
116 
118  virtual void save_document(const char * doc, const char * key) = 0;
120  virtual void save_document(std::string doc, std::string key) = 0;
122  virtual void save_document(const char * doc, const char * key, \
123  const char * collection_name) = 0;
125  virtual void save_document(std::string doc, std::string key, \
126  std::string collection_name) = 0;
128  virtual void save_document(AOSSL::MongoBufferInterface *document, \
129  const char * key) = 0;
131  virtual void save_document(AOSSL::MongoBufferInterface *document, \
132  std::string key) = 0;
133 
134  // Advanced Operations
135 
137 
140  virtual MongoIteratorInterface* query(const char * query_str, \
141  const char * opts_str) = 0;
143 
146  virtual MongoIteratorInterface* query(std::string query_str, \
147  std::string opts_str) = 0;
149 
152  virtual MongoIteratorInterface* query(const char * query_str, \
153  const char * opts_str, const char * collection_name) = 0;
155 
158  virtual MongoIteratorInterface* query(std::string query_str, \
159  std::string opts_str, std::string collection_name) = 0;
161 
164  virtual MongoIteratorInterface* query(const char * query_str) = 0;
166 
169  virtual MongoIteratorInterface* query(std::string query_str) = 0;
170 
172 
176  virtual void update_by_query(AOSSL::MongoBufferInterface *query, \
177  AOSSL::MongoBufferInterface *update, bool update_multiple) = 0;
178 
180 
183  virtual void update_by_query(AOSSL::MongoBufferInterface *query, \
184  AOSSL::MongoBufferInterface *update) = 0;
185 
187 
190  virtual AOSSL::MongoBufferInterface* update_single_by_query(AOSSL::MongoBufferInterface *query, \
191  AOSSL::MongoBufferInterface *update) = 0;
192 };
193 
194 #endif // AOSSL_MONGO_INCLUDE_MONGO_INTERFACE_H_
Interface used to store Mongo Responses.
Definition: mongo_interface.h:56
Returned from Queries in order to iterate over results.
Definition: mongo_interface.h:65
Mongo Exception, used to store errors passed from Mongo.
Definition: mongo_interface.h:35
A Structure for holding a BSON Document.
Definition: mongo_buffer_interface.h:66
virtual ~MongoInterface()
Destructor.
Definition: mongo_interface.h:78
const char * what() const
Show the error message in readable format.
Definition: mongo_interface.h:50
std::string int_msg
An error message passed on initialization.
Definition: mongo_interface.h:37
MongoException(std::string msg)
Create a Mongo Exception, and store the given error message.
Definition: mongo_interface.h:41
Definition: mongo_interface.h:75