Mercurial > hg > orthanc
comparison Core/SQLite/Transaction.cpp @ 1220:9b9026560a5f
SQLite wrapper is now fully independent of Orthanc
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 10 Nov 2014 16:33:51 +0100 |
parents | a811bdf8b8eb |
children | 63d47b1fa239 |
comparison
equal
deleted
inserted
replaced
1219:c4ae92753d57 | 1220:9b9026560a5f |
---|---|
1 /** | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, | 3 * |
4 * Belgium | 4 * Copyright (C) 2012-2014 Sebastien Jodogne <s.jodogne@gmail.com>, |
5 * Medical Physics Department, CHU of Liege, Belgium | |
5 * | 6 * |
6 * Copyright (c) 2012 The Chromium Authors. All rights reserved. | 7 * Copyright (c) 2012 The Chromium Authors. All rights reserved. |
7 * | 8 * |
8 * Redistribution and use in source and binary forms, with or without | 9 * Redistribution and use in source and binary forms, with or without |
9 * modification, are permitted provided that the following conditions are | 10 * modification, are permitted provided that the following conditions are |
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
34 **/ | 35 **/ |
35 | 36 |
36 | 37 |
38 #if ORTHANC_SQLITE_STANDALONE != 1 | |
37 #include "../PrecompiledHeaders.h" | 39 #include "../PrecompiledHeaders.h" |
40 #endif | |
41 | |
38 #include "Transaction.h" | 42 #include "Transaction.h" |
43 #include "OrthancSQLiteException.h" | |
39 | 44 |
40 namespace Orthanc | 45 namespace Orthanc |
41 { | 46 { |
42 namespace SQLite | 47 namespace SQLite |
43 { | 48 { |
57 | 62 |
58 void Transaction::Begin() | 63 void Transaction::Begin() |
59 { | 64 { |
60 if (isOpen_) | 65 if (isOpen_) |
61 { | 66 { |
62 throw OrthancException("SQLite: Beginning a transaction twice!"); | 67 throw OrthancSQLiteException("SQLite: Beginning a transaction twice!"); |
63 } | 68 } |
64 | 69 |
65 isOpen_ = connection_.BeginTransaction(); | 70 isOpen_ = connection_.BeginTransaction(); |
66 if (!isOpen_) | 71 if (!isOpen_) |
67 { | 72 { |
68 throw OrthancException("SQLite: Unable to create a transaction"); | 73 throw OrthancSQLiteException("SQLite: Unable to create a transaction"); |
69 } | 74 } |
70 } | 75 } |
71 | 76 |
72 void Transaction::Rollback() | 77 void Transaction::Rollback() |
73 { | 78 { |
74 if (!isOpen_) | 79 if (!isOpen_) |
75 { | 80 { |
76 throw OrthancException("SQLite: Attempting to roll back a nonexistent transaction. " | 81 throw OrthancSQLiteException("SQLite: Attempting to roll back a nonexistent transaction. " |
77 "Did you remember to call Begin()?"); | 82 "Did you remember to call Begin()?"); |
78 } | 83 } |
79 | 84 |
80 isOpen_ = false; | 85 isOpen_ = false; |
81 | 86 |
82 connection_.RollbackTransaction(); | 87 connection_.RollbackTransaction(); |
84 | 89 |
85 void Transaction::Commit() | 90 void Transaction::Commit() |
86 { | 91 { |
87 if (!isOpen_) | 92 if (!isOpen_) |
88 { | 93 { |
89 throw OrthancException("SQLite: Attempting to roll back a nonexistent transaction. " | 94 throw OrthancSQLiteException("SQLite: Attempting to roll back a nonexistent transaction. " |
90 "Did you remember to call Begin()?"); | 95 "Did you remember to call Begin()?"); |
91 } | 96 } |
92 | 97 |
93 isOpen_ = false; | 98 isOpen_ = false; |
94 | 99 |
95 if (!connection_.CommitTransaction()) | 100 if (!connection_.CommitTransaction()) |
96 { | 101 { |
97 throw OrthancException("SQLite: Failure when committing the transaction"); | 102 throw OrthancSQLiteException("SQLite: Failure when committing the transaction"); |
98 } | 103 } |
99 } | 104 } |
100 } | 105 } |
101 } | 106 } |