mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-19 03:58:08 +00:00
feat(SmartTransaction): don't use soci::transaction, use soci::session methods to deal directly with transactions
This commit is contained in:
parent
3f16a71960
commit
ab721847ba
2 changed files with 13 additions and 11 deletions
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue