Mercurial > hg > orthanc
annotate Core/SQLite/Transaction.cpp @ 967:dfc076546821
add suffix Tests to unit test sources
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 27 Jun 2014 15:36:38 +0200 |
parents | a811bdf8b8eb |
children | 9b9026560a5f |
rev | line source |
---|---|
0 | 1 /** |
59 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
689 | 3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, |
0 | 4 * Belgium |
5 * | |
17 | 6 * Copyright (c) 2012 The Chromium Authors. All rights reserved. |
7 * | |
8 * Redistribution and use in source and binary forms, with or without | |
9 * modification, are permitted provided that the following conditions are | |
10 * met: | |
0 | 11 * |
17 | 12 * * Redistributions of source code must retain the above copyright |
13 * notice, this list of conditions and the following disclaimer. | |
14 * * Redistributions in binary form must reproduce the above | |
15 * copyright notice, this list of conditions and the following disclaimer | |
16 * in the documentation and/or other materials provided with the | |
17 * distribution. | |
18 * * Neither the name of Google Inc., the name of the CHU of Liege, | |
19 * nor the names of its contributors may be used to endorse or promote | |
20 * products derived from this software without specific prior written | |
21 * permission. | |
22 * | |
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
32 * (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. | |
0 | 34 **/ |
35 | |
36 | |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
37 #include "../PrecompiledHeaders.h" |
0 | 38 #include "Transaction.h" |
39 | |
59 | 40 namespace Orthanc |
0 | 41 { |
42 namespace SQLite | |
43 { | |
44 Transaction::Transaction(Connection& connection) : | |
45 connection_(connection), | |
46 isOpen_(false) | |
47 { | |
48 } | |
49 | |
50 Transaction::~Transaction() | |
51 { | |
52 if (isOpen_) | |
53 { | |
54 connection_.RollbackTransaction(); | |
55 } | |
56 } | |
57 | |
58 void Transaction::Begin() | |
59 { | |
60 if (isOpen_) | |
61 { | |
59 | 62 throw OrthancException("SQLite: Beginning a transaction twice!"); |
0 | 63 } |
64 | |
65 isOpen_ = connection_.BeginTransaction(); | |
66 if (!isOpen_) | |
67 { | |
59 | 68 throw OrthancException("SQLite: Unable to create a transaction"); |
0 | 69 } |
70 } | |
71 | |
72 void Transaction::Rollback() | |
73 { | |
74 if (!isOpen_) | |
75 { | |
59 | 76 throw OrthancException("SQLite: Attempting to roll back a nonexistent transaction. " |
0 | 77 "Did you remember to call Begin()?"); |
78 } | |
79 | |
80 isOpen_ = false; | |
81 | |
82 connection_.RollbackTransaction(); | |
83 } | |
84 | |
85 void Transaction::Commit() | |
86 { | |
87 if (!isOpen_) | |
88 { | |
59 | 89 throw OrthancException("SQLite: Attempting to roll back a nonexistent transaction. " |
0 | 90 "Did you remember to call Begin()?"); |
91 } | |
92 | |
93 isOpen_ = false; | |
94 | |
95 if (!connection_.CommitTransaction()) | |
96 { | |
59 | 97 throw OrthancException("SQLite: Failure when committing the transaction"); |
0 | 98 } |
99 } | |
100 } | |
101 } |