diff options
author | bertho <bertho> | 2009-02-10 13:39:25 +0000 |
---|---|---|
committer | bertho <bertho> | 2009-02-10 13:39:25 +0000 |
commit | bbe2b5f899a9c1bd7c99181f8702ec03c60f3028 (patch) | |
tree | 6da04c039a0e04930bb1c7e4fea5b14e52f9bc57 /server/src/database.h | |
parent | 3f1b036458bf9b348b65c36fa30ecb177800d703 (diff) |
- Rewrite part of the database backend setup and abstraction
- Fix some printf's into debug statements
Diffstat (limited to 'server/src/database.h')
-rw-r--r-- | server/src/database.h | 82 |
1 files changed, 30 insertions, 52 deletions
diff --git a/server/src/database.h b/server/src/database.h index e311584..85d4cc4 100644 --- a/server/src/database.h +++ b/server/src/database.h @@ -1,4 +1,5 @@ /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set et sw=2 ts=2: */ /*************************************************************************** * database.h * @@ -27,74 +28,51 @@ #ifndef __PRACRO_DATABASE_H__ #define __PRACRO_DATABASE_H__ -#include <config.h> - -#include <pqxx/pqxx> - -#include <string> +#include <time.h> +#include "pracrodao.h" #include "transaction.h" #include "template.h" -#include <time.h> - -#include <map> - -class Value { -public: - Value() : value(""), timestamp(0) {} - std::string value; - time_t timestamp; -}; -typedef std::map< std::string, Value > Values; - -typedef std::vector< std::string > Fieldnames; +#include "debug.h" class Database { public: - Database(std::string hostname, - std::string user, - std::string password); + Database(std::string _backend, std::string _host, std::string _port, std::string _user, std::string _passwd, std::string _dbname); ~Database(); // Make a commit to the db - void commit(std::string user, - std::string cpr, - Macro ¯o, - Fields &fields, - time_t now = time(NULL)); + void commitTransaction(std::string user, std::string cpr, Macro ¯o, Fields &fields, time_t now = time(NULL)) { + PRACRO_DEBUG(db, "%s, %s, %s,...\n", user.c_str(), cpr.c_str(), macro.attributes["name"].c_str()); + if(dao) dao->commitTransaction(user, cpr, macro, fields, now); + } // Get a list of values from the db - Values getValues(std::string cpr, - Fieldnames &fieldnames, - time_t oldest = 0); + Values getValues(std::string cpr, Fieldnames &fieldnames, time_t oldest = 0) { + PRACRO_DEBUG(db, "%s, <%u fieldnames>, %ld\n", cpr.c_str(), fieldnames.size(), oldest); + if(dao) return dao->getLatestValues(cpr, NULL, fieldnames, oldest); + else return Values(); + } // Check if a macro has been committed. - bool checkMacro(std::string cpr, - std::string macro, - time_t oldest = 0); + bool checkMacro(std::string cpr, std::string macro, time_t oldest = 0) { + PRACRO_DEBUG(db, "%s, %s, %ld\n", cpr.c_str(), macro.c_str(), oldest); + if(!dao) return false; + return dao->nrOfCommits(cpr, macro, oldest) > 0; + } - // Put an entry in the journal table - void putResume(std::string user, - std::string cpr, - Macro &_macro, - std::string resume, - time_t now, - bool store_in_journal); - // Get latest resume of a given macro - std::string getResume(std::string cpr, - std::string macro, - time_t oldest); - - // Connect to the db - void connect() {} - - // Disconnect from the db - void disconnect() {} + std::string getResume(std::string cpr, Macro ¯o, time_t oldest) { + PRACRO_DEBUG(db, "%s, %s, %ld\n", cpr.c_str(), macro.attributes["name"].c_str(), oldest); + if(!dao) return ""; + Fieldnames fn; + fn.push_back("journal.resume"); + Values v = dao->getLatestValues(cpr, ¯o, fn, oldest); + Values::iterator i = v.find("journal.resume"); + if(i != v.end()) return i->second.value; + else return ""; + } private: -#ifndef WITHOUT_DB - pqxx::connection c; -#endif/*WITHOUT_DB*/ + PracroDAO *dao; }; #endif/*__PRACRO_DATABASE_H__*/ |