summaryrefslogtreecommitdiff
path: root/server/src/database.h
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/database.h')
-rw-r--r--server/src/database.h82
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 &macro,
- Fields &fields,
- time_t now = time(NULL));
+ void commitTransaction(std::string user, std::string cpr, Macro &macro, 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 &macro, 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, &macro, 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__*/