#ifndef ADAPTORS_SQL_FAST_ADVERT_DATABASE_CONNECTION_HPP #define ADAPTORS_SQL_FAST_ADVERT_DATABASE_CONNECTION_HPP // Saga Includes #include // Enable SOCI Boost Integration #define SOCI_USE_BOOST // SOCI Includes #include #include #include // Boost Includes #include #include #include // Jenkins Hash #include "jenkins_hash_new.hpp" // Database Connnection Defines #define DATABASE_LAYOUT_VERSION "1.0" // Database Table names #define DATABASE_VERSION_TABLE "version" #define DATABASE_NODE_TABLE "nodes" #define DATABASE_ATTRIBUTES_TABLE "attributes" #define DATABASE_DATA_TABLE "data" namespace sql_fast_advert { struct node { node() : id(), name(""), dir("FALSE"), lft(0), rgt(0) {} int id; std::string name; std::string dir; int lft; int rgt; }; class database_connection { private: util::jenkins_hash hash; soci::connection_pool *pool; std::string connectString; int CONNECTION_POOL_SIZE; int CURRENT_CONNECTION_POOL_SIZE; int BATCH_SIZE; public: // Contructor database_connection(const saga::url &url, std::map &ini_file_options); // Destructor ~database_connection(void); // Grow Connection pool for Async API calls void grow_pool(); // MPTT Operations node find_node(const std::string path); node insert_node(const node parent, const std::string node_name, const bool is_dir = true); void remove_node(const node db_node); std::string get_path(const node db_node); void get_child_nodes(std::vector &ret, const node parent); static bool node_is_leaf(const node db_node); // Attribute Operations bool attribute_exists (const node db_node, const std::string key); bool attribute_is_vector (const node db_node, const std::string key); std::string get_attribute (const node db_node, const std::string key); void set_attribute (const node db_node, const std::string key, const std::string value); void get_vector_attribute (const node db_node, std::vector &ret, const std::string key); void set_vector_attribute (const node db_node, const std::string key, std::vector value); void remove_attribute (const node db_node, const std::string key); void list_attributes (std::vector &ret, const node db_node); void find_attributes (std::vector &ret, const node db_node, const std::string key_pattern, const std::string value_pattern); }; } #endif // ADAPTORS_SQL_FAST_ADVERT_DATABASE_CONNECTION_HPP