HCE project C++ developers source code library  1.1.1
HCE project developer library
 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 private:
81  void put( const std::string & key, const std::string & value ) {
82  this->_dbDriver->put(key,value);
83  this->_status = this->_dbDriver->getLastError();
84  }
85  std::string get ( const std::string & key ) {
86  std::string value(this->_dbDriver->get(key));
87  this->_status = this->_dbDriver->getLastError();
88  return value;
89  }
90  std::vector<std::string> get_all () {
91  std::vector<std::string> value (this->_dbDriver->get_all());
92  this->_status = this->_dbDriver->getLastError();
93  return value;
94  }
95  void del (const std::string& key) {
96  this->_dbDriver->del(key);
97  this->_status = _dbDriver->getLastError();
98  }
99 private:
104  Poco::SharedPtr<Response> putData(const std::string&);
105  Poco::SharedPtr<Response> getData(const std::string&);
106  Poco::SharedPtr<Response> delData(const std::string&);
107  Poco::SharedPtr<Response> checkData(const std::string&);
108  Poco::SharedPtr<Response> adminData(const std::string&);
112  inline int getLastError() { return _dbDriver->getLastError(); }
113 private:
114 //public:
115  //template<typename T>
116  //STATUS loadResourceFromJSON(const std::string&, T&);
120  STATUS loadResourcesFromJSON(const std::string&, std::map<std::string, std::string>&);
121  STATUS loadDocIdsFromJSON(const std::string&, std::vector<std::string>&);
127  void init_command();
128  const std::string getDBEngine() const { return this->_dbConfig.getDriverName(); }
129 private:
130  unsigned int _errorCode;
131  std::string _errorMsg;
132  STATUS _status;
133  //typedef Poco::SharedPtr<Response> (HCE::ORMFunctionalObject::*FP)(const std::string&);
134  typedef std::function<Poco::SharedPtr<HCE::Response>(ORMFunctionalObject*,const std::string&)> FP;
135  std::vector<FP> command;
136 private:
137  Poco::SharedPtr<HCE::BaseDB> _dbDriver;
138  HCE::DataBaseDriverConfig _dbConfig;
139  Poco::DynamicFactory<HCE::BaseDB> _factory;
140 };
141 
142 inline void ORMFunctionalObject::createDriverByName() {
143  this->_status = ACTION_GENERAL_FAILURE;
144  this->_dbDriver = this->_factory.createInstance( this->_dbConfig.getDriverName() );
145  this->_status = ACTION_SUCCESS;
146 }
147 
148 inline void ORMFunctionalObject::setDriverUrl() {
149  this->_status = ACTION_GENERAL_FAILURE;
150  if (this->_dbDriver) {
151  this->_dbDriver->setDriverUrl( this->_dbConfig.getDataBaseUrl() );
152  this->_status = ACTION_SUCCESS;
153  }
154 }
155 
156 inline void ORMFunctionalObject::setDatabaseName() {
157  this->_status = ACTION_GENERAL_FAILURE;
158  if (this->_dbDriver) {
159  this->_dbDriver->setDatabaseName( this->_dbConfig.getDataBaseName() );
160  this->_status = ACTION_SUCCESS;
161  }
162 }
163 
164 }
165 
166 #endif