summaryrefslogtreecommitdiff
path: root/server/src/session.cc
diff options
context:
space:
mode:
authordeva <deva>2011-02-04 13:34:40 +0000
committerdeva <deva>2011-02-04 13:34:40 +0000
commit6bae4fd17d2660d53279dac9287de52be2a00c6c (patch)
tree595f7aa65558735a3fc05062d39e95e88b026a51 /server/src/session.cc
parente6a824034c742b9a414d32ecfbcc8531180f93dc (diff)
Database pool is now used instead of one connection per session. Admin interface supports session unlock.
Diffstat (limited to 'server/src/session.cc')
-rw-r--r--server/src/session.cc71
1 files changed, 47 insertions, 24 deletions
diff --git a/server/src/session.cc b/server/src/session.cc
index c919e54..7290c31 100644
--- a/server/src/session.cc
+++ b/server/src/session.cc
@@ -43,29 +43,35 @@
#include "configuration.h"
#include "connectionpool.h"
#include "sessionserialiser.h"
+#include "environment.h"
-Session::Session(std::string sessionid, std::string pid, std::string t)
+Session::Session(Environment *e,
+ std::string sid, std::string pid, std::string t)
+ : env(e)
{
_journal = NULL;
- _database = NULL;
+ sessionid = sid;
patientid = pid;
templ = t;
isreadonly = true;
-
- database()->setSessionId(sessionid);
}
Session::~Session()
{
if(_journal) delete _journal;
- if(_database) delete _database;
}
std::string Session::id()
{
- return database()->sessionId();
+ if(sessionid == "") {
+ AutoBorrower<Database*> borrower(env->dbpool);
+ Database *db = borrower.get();
+ sessionid = db->newSessionId();
+ }
+
+ return sessionid;
}
void Session::lock()
@@ -80,7 +86,22 @@ void Session::unlock()
bool Session::active()
{
- return isreadonly || database()->active();
+ if(isreadonly) return true;
+
+ {
+ AutoBorrower<Database*> borrower(env->dbpool);
+ Database *db = borrower.get();
+ return db->active(id());
+ }
+}
+
+void Session::setActive(bool a)
+{
+ if(isreadonly == false) {
+ AutoBorrower<Database*> borrower(env->dbpool);
+ Database *db = borrower.get();
+ return db->setActive(id(), a);
+ }
}
void Session::commit()
@@ -90,17 +111,19 @@ void Session::commit()
delete _journal;
_journal = NULL;
}
- if(_database != NULL) {
- _database->commit();
- delete _database;
- _database = NULL;
+ if(isreadonly == false) {
+ AutoBorrower<Database*> borrower(env->dbpool);
+ Database *db = borrower.get();
+ db->commit(id());
}
}
void Session::nocommit()
{
- if(_database != NULL) {
- _database->nocommit();
+ if(isreadonly == false) {
+ AutoBorrower<Database*> borrower(env->dbpool);
+ Database *db = borrower.get();
+ db->nocommit(id());
}
}
@@ -110,10 +133,10 @@ void Session::discard()
delete _journal;
_journal = NULL;
}
- if(_database != NULL) {
- _database->discard();
- delete _database;
- _database = NULL;
+ if(isreadonly == false) {
+ AutoBorrower<Database*> borrower(env->dbpool);
+ Database *db = borrower.get();
+ db->discard(id());
}
}
@@ -126,7 +149,7 @@ Journal *Session::journal()
}
return _journal;
}
-
+/*
Database *Session::database()
{
if(_database == NULL) {
@@ -136,8 +159,8 @@ Database *Session::database()
}
return _database;
}
-
-Sessions::Sessions()
+*/
+Sessions::Sessions(Environment *e) : env(e)
{
}
@@ -168,7 +191,7 @@ Session *Sessions::newSession(std::string patientid, std::string templ)
}
{ // Look up patientid / template tupple in session files.
- SessionSerialiser ser(Conf::session_path);
+ SessionSerialiser ser(env, Conf::session_path);
Session *session = ser.findFromTupple(patientid, templ);
if(session) {
sessions[session->id()] = session;
@@ -176,7 +199,7 @@ Session *Sessions::newSession(std::string patientid, std::string templ)
}
}
- Session *session = new Session("", patientid, templ);
+ Session *session = new Session(env, "", patientid, templ);
sessions[session->id()] = session;
return session;
}
@@ -188,7 +211,7 @@ Session *Sessions::session(std::string sessionid)
std::string filename = getSessionFilename(Conf::session_path, sessionid);
if(fexists(filename)) {
- SessionSerialiser ser(Conf::session_path);
+ SessionSerialiser ser(env, Conf::session_path);
Session *s = ser.load(sessionid);
sessions[s->id()] = s;
return s;
@@ -229,7 +252,7 @@ void Sessions::store()
{
std::map<std::string, Session*>::iterator i = sessions.begin();
while(i != sessions.end()) {
- SessionSerialiser ser(Conf::session_path);
+ SessionSerialiser ser(env, Conf::session_path);
ser.save(i->second);
delete i->second;
sessions.erase(i);