hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ORMFunctionalObject.hpp
Go to the documentation of this file.
1 
15 #ifndef ORM_FUNCTIONAL_OBJECT_HPP
16 #define ORM_FUNCTIONAL_OBJECT_HPP
17 
18 
22 #include "FakeDB.hpp"
23 #include "BaseDB.hpp"
24 #include "Response.hpp"
25 #include "DataBaseDriverConfig.hpp"
26 #include "Logger.hpp"
27 
28 #include <functional>
29 
30 
31 namespace HCE
32 {
33 
38 {
39 public:
40  explicit ORMFunctionalObject(const DataBaseDriverConfig& db_config);
41  virtual ~ORMFunctionalObject() throw();
42 public:
48  std::string processJSON(const std::string& input_message);
54  //Documents processObj(const std::string& input_message);
55  Poco::SharedPtr<Response> processObj(const Request&);
61 public:
65  inline unsigned int getErrorCode() const { return _errorCode; }
69  inline std::string getErrorMsg() const { return _errorMsg; }
70 private:
75  void init();
76 private:
77  void createDriverByName();
78  void setDriverUrl();
79  void setDatabaseName();
80  void setWritePolicy();
81  void setWriteUnique();
82 private:
83  void put( const std::string & key, const std::string & value ) {
84  this->_dbDriver->put(key,value);
85  this->_status = this->_dbDriver->getLastError();
86  }
87  std::string get ( const std::string & key ) {
88  std::string value(this->_dbDriver->get(key));
89  this->_status = this->_dbDriver->getLastError();
90  return value;
91  }
92  std::vector<std::string> get_all () {
93  std::vector<std::string> value (this->_dbDriver->get_all());
94  this->_status = this->_dbDriver->getLastError();
95  return value;
96  }
97  void del (const std::string& key) {
98  this->_dbDriver->del(key);
99  this->_status = _dbDriver->getLastError();
100  }
101 private:
106  Poco::SharedPtr<Response> putData(const std::string&);
107  Poco::SharedPtr<Response> getData(const std::string&);
108  Poco::SharedPtr<Response> delData(const std::string&);
109  Poco::SharedPtr<Response> checkData(const std::string&);
110  Poco::SharedPtr<Response> getAllKeys(const std::string&);
111  Poco::SharedPtr<Response> adminData(const std::string&);
115  inline int getLastError() { return _dbDriver->getLastError(); }
116 private:
117 //public:
118  //template<typename T>
119  //STATUS loadResourceFromJSON(const std::string&, T&);
123  STATUS loadResourcesFromJSON(const std::string&, std::map<std::string, std::string>&);
124  STATUS loadDocIdsFromJSON(const std::string&, std::vector<std::string>&);
130  void init_command();
131  const std::string getDBEngine() const { return this->_dbConfig.getDriverName(); }
132 private:
133  unsigned int _errorCode;
134  std::string _errorMsg;
135  STATUS _status;
136  //typedef Poco::SharedPtr<Response> (HCE::ORMFunctionalObject::*FP)(const std::string&);
137  typedef std::function<Poco::SharedPtr<HCE::Response>(ORMFunctionalObject*,const std::string&)> FP;
138  std::vector<FP> command;
139 private:
140  Poco::SharedPtr<HCE::BaseDB> _dbDriver;
141  HCE::DataBaseDriverConfig _dbConfig;
142  Poco::DynamicFactory<HCE::BaseDB> _factory;
143 };
144 
145 inline void ORMFunctionalObject::createDriverByName() {
146  this->_status = ACTION_GENERAL_FAILURE;
147  this->_dbDriver = this->_factory.createInstance( this->_dbConfig.getDriverName() );
148  this->_status = ACTION_SUCCESS;
149 }
150 
151 inline void ORMFunctionalObject::setDriverUrl() {
152  this->_status = ACTION_GENERAL_FAILURE;
153  if (this->_dbDriver) {
154  this->_dbDriver->setDriverUrl( this->_dbConfig.getDataBaseUrl() );
155  this->_status = ACTION_SUCCESS;
156  }
157 }
158 
159 inline void ORMFunctionalObject::setDatabaseName() {
160  this->_status = ACTION_GENERAL_FAILURE;
161  if (this->_dbDriver) {
162  this->_dbDriver->setDatabaseName( this->_dbConfig.getDataBaseName() );
163  this->_status = ACTION_SUCCESS;
164  }
165 }
166 
167 
168 inline void ORMFunctionalObject::setWritePolicy() {
169  this->_status = ACTION_GENERAL_FAILURE;
170  if (this->_dbDriver) {
171  this->_dbDriver->setWritePolicy(this->_dbConfig.getWritePolicy());
172  this->_status = ACTION_SUCCESS;
173  }
174 }
175 
176 
177 inline void ORMFunctionalObject::setWriteUnique() {
178  this->_status = ACTION_GENERAL_FAILURE;
179  if (this->_dbDriver) {
180  this->_dbDriver->setWriteUnique(this->_dbConfig.getWriteUnique());
181  this->_status = ACTION_SUCCESS;
182  }
183 }
184 
185 
186 }
187 
188 #endif