summaryrefslogtreecommitdiff
path: root/server/src/database.h
diff options
context:
space:
mode:
authordeva <deva>2010-06-10 07:03:06 +0000
committerdeva <deva>2010-06-10 07:03:06 +0000
commit198b0d886817f2c5bc97cfd11857d4b314dffae3 (patch)
tree4fc2d51de46ab69b9e67149abf0ab6a332032f27 /server/src/database.h
parent730eb796bbce6f124be9194f1565b7dda1daddf1 (diff)
Add transaction support on database pr. pracro session. Makes it possible to discard all edited macros.
Diffstat (limited to 'server/src/database.h')
-rw-r--r--server/src/database.h55
1 files changed, 47 insertions, 8 deletions
diff --git a/server/src/database.h b/server/src/database.h
index f253ba5..9b08801 100644
--- a/server/src/database.h
+++ b/server/src/database.h
@@ -37,31 +37,45 @@
class Database {
public:
- Database(std::string _backend, std::string _host, std::string _port, std::string _user, std::string _passwd, std::string _dbname);
+ 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 commitTransaction(std::string user, std::string patientid, Macro &macro, Fields &fields, time_t now = time(NULL)) {
+ void commitTransaction(std::string user,
+ std::string patientid,
+ Macro &macro,
+ Fields &fields,
+ time_t now = time(NULL)) {
if(!dao) return;
mutex.lock();
- PRACRO_DEBUG(db, "%s, %s, %s,...\n", user.c_str(), patientid.c_str(), macro.attributes["name"].c_str());
+ PRACRO_DEBUG(db, "%s, %s, %s,...\n",
+ user.c_str(), patientid.c_str(),
+ macro.attributes["name"].c_str());
dao->commitTransaction(user, patientid, macro, fields, now);
mutex.unlock();
}
// Get a list of values from the db
- Values getValues(std::string patientid, Fieldnames &fieldnames, time_t oldest = 0) {
+ Values getValues(std::string patientid,
+ Fieldnames &fieldnames,
+ time_t oldest = 0) {
if(!dao) return Values();
mutex.lock();
- PRACRO_DEBUG(db, "%s, <%u fieldnames>, %ld\n", patientid.c_str(), fieldnames.size(), oldest);
+ PRACRO_DEBUG(db, "%s, <%u fieldnames>, %ld\n",
+ patientid.c_str(), fieldnames.size(), oldest);
Values values = dao->getLatestValues(patientid, NULL, fieldnames, oldest);
mutex.unlock();
return values;
}
// Check if a macro has been committed.
- bool checkMacro(std::string patientid, std::string macro, time_t oldest = 0) {
- PRACRO_DEBUG(db, "%s, %s, %ld\n", patientid.c_str(), macro.c_str(), oldest);
+ bool checkMacro(std::string patientid,
+ std::string macro,
+ time_t oldest = 0) {
+ PRACRO_DEBUG(db, "%s, %s, %ld\n",
+ patientid.c_str(), macro.c_str(), oldest);
if(!dao) return false;
mutex.lock();
bool res = dao->nrOfCommits(patientid, macro, oldest) > 0;
@@ -71,7 +85,8 @@ public:
// Get latest resume of a given macro
std::string getResume(std::string patientid, Macro &macro, time_t oldest) {
- PRACRO_DEBUG(db, "%s, %s, %ld\n", patientid.c_str(), macro.attributes["name"].c_str(), oldest);
+ PRACRO_DEBUG(db, "%s, %s, %ld\n",
+ patientid.c_str(), macro.attributes["name"].c_str(), oldest);
if(!dao) return "";
Fieldnames fn;
fn.push_back("journal.resume");
@@ -111,6 +126,30 @@ public:
return fieldnames;
}
+ void commit()
+ {
+ if(!dao) return;
+ return dao->commit();
+ }
+
+ void discard()
+ {
+ if(!dao) return;
+ return dao->discard();
+ }
+
+ std::string serialise()
+ {
+ if(!dao) return "";
+ return dao->serialise();
+ }
+
+ void restore(const std::string &data)
+ {
+ if(!dao) return;
+ return dao->restore(data);
+ }
+
private:
PracroDAO *dao;
Mutex mutex;