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