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.h48
1 files changed, 36 insertions, 12 deletions
diff --git a/server/src/database.h b/server/src/database.h
index 0bc37c0..a366f43 100644
--- a/server/src/database.h
+++ b/server/src/database.h
@@ -42,29 +42,44 @@ public:
std::string _passwd, std::string _dbname);
~Database();
+ std::string sessionId()
+ {
+ if(dao && sessionid == "") {
+ sessionid = dao->newSessionId();
+ }
+ return sessionid;
+ }
+
+ void setSessionId(std::string sessionid)
+ {
+ this->sessionid = sessionid;
+ }
+
// Make a commit to the db
void commitTransaction(Transaction &transaction,
Commit &commit,
Macro &macro,
- time_t now = time(NULL)) {
+ time_t now = time(NULL))
+ {
if(!dao) return;
mutex.lock();
DEBUG(db, "%s, %s, %s,...\n",
transaction.user.c_str(), transaction.cpr.c_str(),
macro.attributes["name"].c_str());
- dao->commitTransaction(transaction, commit, macro, now);
+ dao->commitTransaction(sessionId(), transaction, commit, macro, now);
mutex.unlock();
}
// Get a list of values from the db
Values getValues(std::string patientid,
Fieldnames &fieldnames,
- time_t oldest = 0) {
+ time_t oldest = 0)
+ {
if(!dao) return Values();
mutex.lock();
DEBUG(db, "%s, <%u fieldnames>, %ld\n",
patientid.c_str(), fieldnames.size(), oldest);
- Values values = dao->getLatestValues(patientid, NULL, fieldnames, oldest);
+ Values values = dao->getLatestValues(sessionid, patientid, NULL, fieldnames, oldest);
mutex.unlock();
return values;
}
@@ -72,25 +87,27 @@ public:
// Check if a macro has been committed.
bool checkMacro(std::string patientid,
std::string macro,
- time_t oldest = 0) {
+ time_t oldest = 0)
+ {
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;
+ bool res = dao->nrOfCommits(sessionid, patientid, macro, oldest) > 0;
mutex.unlock();
return res;
}
// Get latest resume of a given macro
- std::string getResume(std::string patientid, Macro &macro, time_t oldest) {
+ std::string getResume(std::string patientid, Macro &macro, time_t oldest)
+ {
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");
mutex.lock();
- Values v = dao->getLatestValues(patientid, &macro, fn, oldest);
+ Values v = dao->getLatestValues(sessionid, patientid, &macro, fn, oldest);
mutex.unlock();
Values::iterator i = v.find("journal.resume");
if(i != v.end()) return i->second.value;
@@ -127,14 +144,20 @@ public:
void commit()
{
- if(!dao) return;
- return dao->commit();
+ if(!dao || sessionid == "") return;
+ return dao->commit(sessionId());
+ }
+
+ void nocommit()
+ {
+ if(!dao || sessionid == "") return;
+ return dao->nocommit(sessionId());
}
void discard()
{
- if(!dao) return;
- return dao->discard();
+ if(!dao || sessionid == "") return;
+ return dao->discard(sessionId());
}
std::string serialise()
@@ -152,6 +175,7 @@ public:
private:
PracroDAO *dao;
Mutex mutex;
+ std::string sessionid;
};
#endif/*__PRACRO_DATABASE_H__*/