Mercurial > hg > orthanc
annotate OrthancFramework/Sources/SQLite/Transaction.cpp @ 5666:aa231c18b9d2 find-refactoring
adding computed tags
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 04 Jul 2024 18:31:54 +0200 |
parents | f7adfb22e20e |
children |
rev | line source |
---|---|
0 | 1 /** |
59 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
1220
9b9026560a5f
SQLite wrapper is now fully independent of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
3 * |
3063 | 4 * Copyright (C) 2012-2016 Sebastien Jodogne <s.jodogne@orthanc-labs.com>, |
1220
9b9026560a5f
SQLite wrapper is now fully independent of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
5 * Medical Physics Department, CHU of Liege, Belgium |
5640
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
6 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
7 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
8 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
0 | 9 * |
17 | 10 * Copyright (c) 2012 The Chromium Authors. All rights reserved. |
11 * | |
12 * Redistribution and use in source and binary forms, with or without | |
13 * modification, are permitted provided that the following conditions are | |
14 * met: | |
0 | 15 * |
17 | 16 * * Redistributions of source code must retain the above copyright |
17 * notice, this list of conditions and the following disclaimer. | |
18 * * Redistributions in binary form must reproduce the above | |
19 * copyright notice, this list of conditions and the following disclaimer | |
20 * in the documentation and/or other materials provided with the | |
21 * distribution. | |
22 * * Neither the name of Google Inc., the name of the CHU of Liege, | |
23 * nor the names of its contributors may be used to endorse or promote | |
24 * products derived from this software without specific prior written | |
25 * permission. | |
26 * | |
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
30 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
31 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
32 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
33 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
34 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
35 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
36 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
0 | 38 **/ |
39 | |
40 | |
1220
9b9026560a5f
SQLite wrapper is now fully independent of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
41 #if ORTHANC_SQLITE_STANDALONE != 1 |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
42 #include "../PrecompiledHeaders.h" |
1220
9b9026560a5f
SQLite wrapper is now fully independent of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
43 #endif |
9b9026560a5f
SQLite wrapper is now fully independent of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
44 |
0 | 45 #include "Transaction.h" |
1220
9b9026560a5f
SQLite wrapper is now fully independent of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
46 #include "OrthancSQLiteException.h" |
0 | 47 |
59 | 48 namespace Orthanc |
0 | 49 { |
50 namespace SQLite | |
51 { | |
52 Transaction::Transaction(Connection& connection) : | |
53 connection_(connection), | |
54 isOpen_(false) | |
55 { | |
56 } | |
57 | |
58 Transaction::~Transaction() | |
59 { | |
60 if (isOpen_) | |
61 { | |
62 connection_.RollbackTransaction(); | |
63 } | |
64 } | |
65 | |
4304 | 66 bool Transaction::IsOpen() const |
67 { | |
68 return isOpen_; | |
69 } | |
70 | |
0 | 71 void Transaction::Begin() |
72 { | |
4304 | 73 if (isOpen_) |
0 | 74 { |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1291
diff
changeset
|
75 throw OrthancSQLiteException(ErrorCode_SQLiteTransactionAlreadyStarted); |
0 | 76 } |
77 | |
78 isOpen_ = connection_.BeginTransaction(); | |
79 if (!isOpen_) | |
80 { | |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1291
diff
changeset
|
81 throw OrthancSQLiteException(ErrorCode_SQLiteTransactionBegin); |
0 | 82 } |
83 } | |
84 | |
85 void Transaction::Rollback() | |
86 { | |
87 if (!isOpen_) | |
88 { | |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1291
diff
changeset
|
89 throw OrthancSQLiteException(ErrorCode_SQLiteRollbackWithoutTransaction); |
0 | 90 } |
91 | |
92 isOpen_ = false; | |
93 | |
94 connection_.RollbackTransaction(); | |
95 } | |
96 | |
97 void Transaction::Commit() | |
98 { | |
99 if (!isOpen_) | |
100 { | |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1291
diff
changeset
|
101 throw OrthancSQLiteException(ErrorCode_SQLiteRollbackWithoutTransaction); |
0 | 102 } |
103 | |
104 isOpen_ = false; | |
105 | |
106 if (!connection_.CommitTransaction()) | |
107 { | |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1291
diff
changeset
|
108 throw OrthancSQLiteException(ErrorCode_SQLiteTransactionCommit); |
0 | 109 } |
110 } | |
111 } | |
112 } |