Commit ab721847 authored by Ronan's avatar Ronan

feat(SmartTransaction): don't use soci::transaction, use soci::session methods...

feat(SmartTransaction): don't use soci::transaction, use soci::session methods to deal directly with transactions
parent 3f16a719
......@@ -20,8 +20,6 @@
#ifndef _L_ABSTRACT_DB_P_H_
#define _L_ABSTRACT_DB_P_H_
#include <thread>
#include "abstract-db.h"
#include "db/session/db-session.h"
#include "object/object-p.h"
......@@ -36,8 +34,6 @@ public:
DbSession dbSession;
const std::thread::id threadId = std::this_thread::get_id();
private:
AbstractDb::Backend backend;
......
......@@ -37,23 +37,31 @@ LINPHONE_BEGIN_NAMESPACE
class SmartTransaction {
public:
SmartTransaction (soci::session *session, const char *name) :
mTransaction(*session), mName(name), mIsCommitted(false) {
mSession(session), mName(name), mIsCommitted(false) {
lInfo() << "Start transaction " << this << " in MainDb::" << mName << ".";
mSession->begin();
}
~SmartTransaction () {
if (!mIsCommitted)
if (!mIsCommitted) {
lInfo() << "Rollback transaction " << this << " in MainDb::" << mName << ".";
mSession->rollback();
}
}
void commit () {
mTransaction.commit();
mIsCommitted = true;
if (mIsCommitted) {
lError() << "Transaction " << this << " in MainDb::" << mName << " already committed!!!";
return;
}
lInfo() << "Commit transaction " << this << " in MainDb::" << mName << ".";
mIsCommitted = true;
mSession->commit();
}
private:
soci::transaction mTransaction;
soci::session *mSession;
const char *mName;
bool mIsCommitted;
......@@ -86,8 +94,6 @@ public:
DbExceptionHandler (DbExceptionHandlerInfo &info, Function &&function) : mFunction(std::move(function)) {
MainDb *mainDb = info.mainDb;
L_ASSERT(mainDb->getPrivate()->threadId == std::this_thread::get_id());
const char *name = info.name;
soci::session *session = mainDb->getPrivate()->dbSession.getBackendSession();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment