0
|
1 /**
|
59
|
2 * Orthanc - A Lightweight, RESTful DICOM Store
|
398
|
3 * Copyright (C) 2012-2013 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
|
|
37 #pragma once
|
|
38
|
|
39 #include "Connection.h"
|
|
40
|
59
|
41 namespace Orthanc
|
0
|
42 {
|
|
43 namespace SQLite
|
|
44 {
|
|
45 class Transaction : public boost::noncopyable
|
|
46 {
|
|
47 private:
|
|
48 Connection& connection_;
|
|
49
|
|
50 // True when the transaction is open, false when it's already been committed
|
|
51 // or rolled back.
|
|
52 bool isOpen_;
|
|
53
|
|
54 public:
|
|
55 explicit Transaction(Connection& connection);
|
|
56 ~Transaction();
|
|
57
|
|
58 // Returns true when there is a transaction that has been successfully begun.
|
|
59 bool IsOpen() const { return isOpen_; }
|
|
60
|
|
61 // Begins the transaction. This uses the default sqlite "deferred" transaction
|
|
62 // type, which means that the DB lock is lazily acquired the next time the
|
|
63 // database is accessed, not in the begin transaction command.
|
|
64 void Begin();
|
|
65
|
|
66 // Rolls back the transaction. This will happen automatically if you do
|
|
67 // nothing when the transaction goes out of scope.
|
|
68 void Rollback();
|
|
69
|
|
70 // Commits the transaction, returning true on success.
|
|
71 void Commit();
|
|
72 };
|
|
73 }
|
|
74 }
|