AOSharedServiceLibrary
neo4j_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_NEO4J_INCLUDE_NEO4J_INTERFACE_H_
26 #define AOSSL_NEO4J_INCLUDE_NEO4J_INTERFACE_H_
27 
28 #include <neo4j-client.h>
29 #include <string>
30 #include <unordered_map>
31 #include <exception>
32 
33 #include "aossl/core/include/slot_pool.h"
34 
35 // Neo4j Exception
36 
37 // A child class of std::exception
38 // which holds error information
39 struct Neo4jException: public std::exception {
40  // An error message passed on initialization
41  std::string int_msg;
42  const char * int_msg_cstr;
43  neo4j_result_stream_t *results = NULL;
44 
45  // Create a Neo4j Exception, and store the given error message
46  inline Neo4jException(std::string msg) {
47  int_msg = "Error in Neo4j Request: " + msg;
48  int_msg_cstr = int_msg.c_str();
49  }
50 
51  inline Neo4jException(std::string msg, neo4j_result_stream_t *r) {
52  int_msg = "Error in Neo4j Request: " + msg;
53  int_msg_cstr = int_msg.c_str();
54  results = r;
55  }
56 
57  Neo4jException() {}
58  ~Neo4jException() throw() {if (results) {neo4j_close_results(results);}}
59  // Show the error message in readable format
60  const char * what() const throw() {
61  return int_msg_cstr;
62  }
63 };
64 
65 // Query Results
66 
68 
72  public:
73  virtual ~DbListInterface() {}
74 
76  virtual bool get_bool_element(unsigned int ind) = 0;
77 
79  virtual int get_int_element(unsigned int ind) = 0;
80 
82  virtual double get_float_element(unsigned int ind) = 0;
83 
85  virtual std::string get_string_element(unsigned int ind, \
86  int char_buffer_size) = 0;
87 
89  virtual std::string get_string_element(unsigned int ind) = 0;
90 
92  virtual std::string to_string() = 0;
93 
95  virtual unsigned int size() = 0;
96 };
97 
99 
103  public:
104  virtual ~DbMapInterface() {}
105 
107  virtual unsigned int size() = 0;
108 
110  virtual bool element_exists(std::string key) = 0;
111 
113  virtual std::string get_string_element(std::string key, \
114  int char_buffer_size) = 0;
115 
117  virtual std::string get_string_element(std::string key) = 0;
118 
120  virtual bool get_bool_element(std::string key) = 0;
121 
123  virtual int get_int_element(std::string key) = 0;
124 
126  virtual double get_float_element(std::string key) = 0;
127 
129  virtual DbListInterface* get_list_element(std::string key) = 0;
130 
132  virtual std::string to_string() = 0;
133 };
134 
136 
140  public:
141  virtual ~DbObjectInterface() {}
142 
144 
147  virtual bool is_node() = 0;
148 
150 
153  virtual bool is_edge() = 0;
154 
156 
159  virtual bool is_path() = 0;
160 
162  virtual std::string to_string() = 0;
163 
165 
168  virtual DbMapInterface* properties() = 0;
169 
171 
174  virtual DbListInterface* labels() = 0;
175 
177 
180  virtual std::string type() = 0;
181 
183 
186  virtual bool forward() = 0;
187 
189 
192  virtual unsigned int size() = 0;
193 
195 
198  virtual DbObjectInterface* get_path_element(int path_index) = 0;
199 };
200 
202 
203 // Represents a single query Result, returned by the iterator
204 // Consists of a set of nodes and edges
206  public:
207  virtual ~ResultTreeInterface() {}
208 
210  virtual DbObjectInterface* get(int index) = 0;
211 
212  virtual bool exists() = 0;
213 };
214 
216 
221  public:
222  virtual ~ResultsIteratorInterface() {}
223 
225  virtual void clear() = 0;
226 
228 
231  virtual bool empty() = 0;
232 
234  virtual unsigned int length() = 0;
235 
237  virtual ResultTreeInterface* next() = 0;
238 };
239 
240 // Neo4j Admin
241 
243 
248  public:
249  virtual ~Neo4jQueryParameterInterface() {}
250 
252  virtual int get_type() = 0;
253 
255  virtual bool get_boolean_value() = 0;
256 
258  virtual bool get_boolean_value(int index) = 0;
259 
261  virtual std::string get_string_value() = 0;
262 
264  virtual std::string get_string_value(int index) = 0;
265 
267  virtual const char * get_cstring_value() = 0;
268 
270  virtual int get_integer_value() = 0;
271 
273  virtual int get_integer_value(int index) = 0;
274 
276  virtual double get_double_value() = 0;
277 
279  virtual double get_double_value(int index) = 0;
280 
282  virtual bool is_array() = 0;
283 
285  virtual unsigned int size() = 0;
286 
288  virtual void add_value(float new_val) = 0;
289 
291  virtual void add_value(int new_val) = 0;
292 
294  virtual void add_value(bool new_val) = 0;
295 
297  virtual void add_value(std::string new_val) = 0;
298 
300  virtual void add_value(const char * new_val) = 0;
301 
302  // Internal Use only - Used by Neo4j Admin when executing query.
303  virtual neo4j_value_t get_neo4j_list() = 0;
304 };
305 
307 
312  public:
313  virtual ~Neo4jInterface() {}
314 
316  virtual ResultsIteratorInterface* execute(const char * query) = 0;
317 
319  virtual ResultsIteratorInterface* execute(std::string query) = 0;
320 
322  virtual ResultsIteratorInterface* execute(const char * query, \
323  std::unordered_map<std::string, Neo4jQueryParameterInterface*>\
324  query_params) = 0;
325 
327  virtual ResultsIteratorInterface* execute(std::string query, \
328  std::unordered_map<std::string, Neo4jQueryParameterInterface*> \
329  query_params) = 0;
330 };
331 
332 #endif // AOSSL_NEO4J_INCLUDE_NEO4J_INTERFACE_H_
A Neo4j Object.
Definition: neo4j_interface.h:139
Neo4j Query Interface.
Definition: neo4j_interface.h:311
Neo4j Query Parameter Interface.
Definition: neo4j_interface.h:247
A Neo4j Map.
Definition: neo4j_interface.h:102
Tree of Query Results.
Definition: neo4j_interface.h:205
Definition: neo4j_interface.h:39
A Neo4j List.
Definition: neo4j_interface.h:71
Results Iterator for viewing query results.
Definition: neo4j_interface.h:220