annotate Core/SQLite/Transaction.h @ 1221:2255e66da726

getting rid of the dependency against Boost in the SQLite C++ wrapper
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 10 Nov 2014 17:05:50 +0100
parents 9b9026560a5f
children 9b4977e3c19d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
59
c996319e90bc renaming in Core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1220
9b9026560a5f SQLite wrapper is now fully independent of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
3 *
9b9026560a5f SQLite wrapper is now fully independent of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
4 * Copyright (C) 2012-2014 Sebastien Jodogne <s.jodogne@gmail.com>,
9b9026560a5f SQLite wrapper is now fully independent of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
5 * Medical Physics Department, CHU of Liege, Belgium
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
17
db4d996ea264 licensing of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
7 * Copyright (c) 2012 The Chromium Authors. All rights reserved.
db4d996ea264 licensing of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
8 *
db4d996ea264 licensing of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
9 * Redistribution and use in source and binary forms, with or without
db4d996ea264 licensing of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
10 * modification, are permitted provided that the following conditions are
db4d996ea264 licensing of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
11 * met:
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
17
db4d996ea264 licensing of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
13 * * Redistributions of source code must retain the above copyright
db4d996ea264 licensing of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
14 * notice, this list of conditions and the following disclaimer.
db4d996ea264 licensing of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
15 * * Redistributions in binary form must reproduce the above
db4d996ea264 licensing of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
16 * copyright notice, this list of conditions and the following disclaimer
db4d996ea264 licensing of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
17 * in the documentation and/or other materials provided with the
db4d996ea264 licensing of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
18 * distribution.
db4d996ea264 licensing of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
19 * * Neither the name of Google Inc., the name of the CHU of Liege,
db4d996ea264 licensing of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
20 * nor the names of its contributors may be used to endorse or promote
db4d996ea264 licensing of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
21 * products derived from this software without specific prior written
db4d996ea264 licensing of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
22 * permission.
db4d996ea264 licensing of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
23 *
db4d996ea264 licensing of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
db4d996ea264 licensing of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
db4d996ea264 licensing of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
db4d996ea264 licensing of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
db4d996ea264 licensing of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
28 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
db4d996ea264 licensing of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
db4d996ea264 licensing of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
db4d996ea264 licensing of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
db4d996ea264 licensing of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
db4d996ea264 licensing of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
db4d996ea264 licensing of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 **/
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #pragma once
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #include "Connection.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
59
c996319e90bc renaming in Core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
42 namespace Orthanc
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 namespace SQLite
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 {
1221
2255e66da726 getting rid of the dependency against Boost in the SQLite C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1220
diff changeset
46 class Transaction : public NonCopyable
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 private:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 Connection& connection_;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 // True when the transaction is open, false when it's already been committed
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 // or rolled back.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 bool isOpen_;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 public:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 explicit Transaction(Connection& connection);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 ~Transaction();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 // Returns true when there is a transaction that has been successfully begun.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 bool IsOpen() const { return isOpen_; }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 // Begins the transaction. This uses the default sqlite "deferred" transaction
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 // type, which means that the DB lock is lazily acquired the next time the
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 // database is accessed, not in the begin transaction command.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 void Begin();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 // Rolls back the transaction. This will happen automatically if you do
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 // nothing when the transaction goes out of scope.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 void Rollback();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 // Commits the transaction, returning true on success.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 void Commit();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 };
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 }