Mercurial > hg > orthanc-databases
comparison Framework/SQLite/SQLiteDatabase.cpp @ 23:b2ff1cd2907a
handling of implicit transactions in DatabaseManager
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 12 Jul 2018 10:44:17 +0200 |
parents | 7cea966b6829 |
children | 714c5d2bee76 |
comparison
equal
deleted
inserted
replaced
22:1e9bad493475 | 23:b2ff1cd2907a |
---|---|
21 | 21 |
22 #include "SQLiteDatabase.h" | 22 #include "SQLiteDatabase.h" |
23 | 23 |
24 #include "SQLiteStatement.h" | 24 #include "SQLiteStatement.h" |
25 #include "SQLiteTransaction.h" | 25 #include "SQLiteTransaction.h" |
26 #include "../Common/ImplicitTransaction.h" | |
26 | 27 |
27 #include <Core/OrthancException.h> | 28 #include <Core/OrthancException.h> |
28 | 29 |
29 namespace OrthancDatabases | 30 namespace OrthancDatabases |
30 { | 31 { |
39 | 40 |
40 IPrecompiledStatement* SQLiteDatabase::Compile(const Query& query) | 41 IPrecompiledStatement* SQLiteDatabase::Compile(const Query& query) |
41 { | 42 { |
42 return new SQLiteStatement(*this, query); | 43 return new SQLiteStatement(*this, query); |
43 } | 44 } |
45 | |
44 | 46 |
47 namespace | |
48 { | |
49 class SQLiteImplicitTransaction : public ImplicitTransaction | |
50 { | |
51 private: | |
52 SQLiteDatabase& db_; | |
45 | 53 |
46 ITransaction* SQLiteDatabase::CreateTransaction() | 54 protected: |
55 virtual IResult* ExecuteInternal(IPrecompiledStatement& statement, | |
56 const Dictionary& parameters) | |
57 { | |
58 return dynamic_cast<SQLiteStatement&>(statement).Execute(*this, parameters); | |
59 } | |
60 | |
61 virtual void ExecuteWithoutResultInternal(IPrecompiledStatement& statement, | |
62 const Dictionary& parameters) | |
63 { | |
64 dynamic_cast<SQLiteStatement&>(statement).ExecuteWithoutResult(*this, parameters); | |
65 } | |
66 | |
67 public: | |
68 SQLiteImplicitTransaction(SQLiteDatabase& db) : | |
69 db_(db) | |
70 { | |
71 } | |
72 }; | |
73 } | |
74 | |
75 ITransaction* SQLiteDatabase::CreateTransaction(bool isImplicit) | |
47 { | 76 { |
48 return new SQLiteTransaction(*this); | 77 if (isImplicit) |
78 { | |
79 return new SQLiteImplicitTransaction(*this); | |
80 } | |
81 else | |
82 { | |
83 return new SQLiteTransaction(*this); | |
84 } | |
49 } | 85 } |
50 } | 86 } |