Mercurial > hg > orthanc
annotate OrthancServer/Sources/Database/SQLiteDatabaseWrapper.h @ 4833:970092a67897
fix PrintVersion()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 25 Nov 2021 19:05:41 +0100 |
parents | 7053502fbf97 |
children | 2e71a08eea15 43e613a7756b |
rev | line source |
---|---|
183 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1286
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
4437
d9473bd5ed43
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
4831
7053502fbf97
added copyright UCLouvain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4628
diff
changeset
|
6 * Copyright (C) 2021-2021 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
183 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
9 * modify it under the terms of the GNU General Public License as | |
10 * published by the Free Software Foundation, either version 3 of the | |
11 * License, or (at your option) any later version. | |
12 * | |
13 * In addition, as a special exception, the copyright holders of this | |
14 * program give permission to link the code of its release with the | |
15 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
16 * that use the same license as the "OpenSSL" library), and distribute | |
17 * the linked executables. You must obey the GNU General Public License | |
18 * in all respects for all of the code used other than "OpenSSL". If you | |
19 * modify file(s) with this exception, you may extend this exception to | |
20 * your version of the file(s), but you are not obligated to do so. If | |
21 * you do not wish to do so, delete this exception statement from your | |
22 * version. If you delete this exception statement from all source files | |
23 * in the program, then also delete it here. | |
24 * | |
25 * This program is distributed in the hope that it will be useful, but | |
26 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
28 * General Public License for more details. | |
29 * | |
30 * You should have received a copy of the GNU General Public License | |
31 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
32 **/ | |
33 | |
34 | |
35 #pragma once | |
36 | |
1247 | 37 #include "IDatabaseWrapper.h" |
38 | |
4045 | 39 #include "../../../OrthancFramework/Sources/SQLite/Connection.h" |
1242 | 40 |
4594
d494b4f1103e
removed the global database mutex from ServerIndex and StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4591
diff
changeset
|
41 #include <boost/thread/mutex.hpp> |
d494b4f1103e
removed the global database mutex from ServerIndex and StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4591
diff
changeset
|
42 |
183 | 43 namespace Orthanc |
44 { | |
45 /** | |
46 * This class manages an instance of the Orthanc SQLite database. It | |
47 * translates low-level requests into SQL statements. Mutual | |
48 * exclusion MUST be implemented at a higher level. | |
49 **/ | |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
50 class SQLiteDatabaseWrapper : public IDatabaseWrapper |
183 | 51 { |
52 private: | |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
53 class TransactionBase; |
4589
bec74e29f86b
attaching the listener to transactions in IDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4570
diff
changeset
|
54 class SignalFileDeleted; |
bec74e29f86b
attaching the listener to transactions in IDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4570
diff
changeset
|
55 class SignalResourceDeleted; |
bec74e29f86b
attaching the listener to transactions in IDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4570
diff
changeset
|
56 class SignalRemainingAncestor; |
4570
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
57 class ReadOnlyTransaction; |
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
58 class ReadWriteTransaction; |
3058
6faf575ba9cc
refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3056
diff
changeset
|
59 class LookupFormatter; |
3019
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3017
diff
changeset
|
60 |
4594
d494b4f1103e
removed the global database mutex from ServerIndex and StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4591
diff
changeset
|
61 boost::mutex mutex_; |
d494b4f1103e
removed the global database mutex from ServerIndex and StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4591
diff
changeset
|
62 SQLite::Connection db_; |
d494b4f1103e
removed the global database mutex from ServerIndex and StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4591
diff
changeset
|
63 TransactionBase* activeTransaction_; |
d494b4f1103e
removed the global database mutex from ServerIndex and StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4591
diff
changeset
|
64 SignalRemainingAncestor* signalRemainingAncestor_; |
d494b4f1103e
removed the global database mutex from ServerIndex and StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4591
diff
changeset
|
65 unsigned int version_; |
183 | 66 |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2772
diff
changeset
|
67 void GetChangesInternal(std::list<ServerIndexChange>& target, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2772
diff
changeset
|
68 bool& done, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2772
diff
changeset
|
69 SQLite::Statement& s, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2772
diff
changeset
|
70 uint32_t maxResults); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2772
diff
changeset
|
71 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2772
diff
changeset
|
72 void GetExportedResourcesInternal(std::list<ExportedResource>& target, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2772
diff
changeset
|
73 bool& done, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2772
diff
changeset
|
74 SQLite::Statement& s, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2772
diff
changeset
|
75 uint32_t maxResults); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2772
diff
changeset
|
76 |
183 | 77 public: |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2773
diff
changeset
|
78 SQLiteDatabaseWrapper(const std::string& path); |
1247 | 79 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2773
diff
changeset
|
80 SQLiteDatabaseWrapper(); |
1247 | 81 |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
82 virtual ~SQLiteDatabaseWrapper(); |
1672
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
83 |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
84 virtual void Open() ORTHANC_OVERRIDE; |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
85 |
4594
d494b4f1103e
removed the global database mutex from ServerIndex and StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4591
diff
changeset
|
86 virtual void Close() ORTHANC_OVERRIDE; |
1672
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
87 |
4589
bec74e29f86b
attaching the listener to transactions in IDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4570
diff
changeset
|
88 virtual IDatabaseWrapper::ITransaction* StartTransaction(TransactionType type, |
bec74e29f86b
attaching the listener to transactions in IDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4570
diff
changeset
|
89 IDatabaseListener& listener) |
3050
d8a91acb7424
working on a database compatibility layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3038
diff
changeset
|
90 ORTHANC_OVERRIDE; |
2772
f3df536e7366
moving the outdated database plugin sample into the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2697
diff
changeset
|
91 |
4594
d494b4f1103e
removed the global database mutex from ServerIndex and StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4591
diff
changeset
|
92 virtual void FlushToDisk() ORTHANC_OVERRIDE; |
2772
f3df536e7366
moving the outdated database plugin sample into the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2697
diff
changeset
|
93 |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
94 virtual bool HasFlushToDisk() const ORTHANC_OVERRIDE |
2772
f3df536e7366
moving the outdated database plugin sample into the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2697
diff
changeset
|
95 { |
f3df536e7366
moving the outdated database plugin sample into the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2697
diff
changeset
|
96 return true; |
f3df536e7366
moving the outdated database plugin sample into the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2697
diff
changeset
|
97 } |
f3df536e7366
moving the outdated database plugin sample into the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2697
diff
changeset
|
98 |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
99 virtual unsigned int GetDatabaseVersion() ORTHANC_OVERRIDE |
2772
f3df536e7366
moving the outdated database plugin sample into the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2697
diff
changeset
|
100 { |
f3df536e7366
moving the outdated database plugin sample into the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2697
diff
changeset
|
101 return version_; |
f3df536e7366
moving the outdated database plugin sample into the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2697
diff
changeset
|
102 } |
f3df536e7366
moving the outdated database plugin sample into the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2697
diff
changeset
|
103 |
f3df536e7366
moving the outdated database plugin sample into the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2697
diff
changeset
|
104 virtual void Upgrade(unsigned int targetVersion, |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
105 IStorageArea& storageArea) ORTHANC_OVERRIDE; |
2772
f3df536e7366
moving the outdated database plugin sample into the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2697
diff
changeset
|
106 |
4628
5fabef29c4ff
added new primitive "hasRevisionsSupport" in database SDK, added "CheckRevisions" to URI "/system"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4594
diff
changeset
|
107 virtual bool HasRevisionsSupport() const ORTHANC_OVERRIDE |
5fabef29c4ff
added new primitive "hasRevisionsSupport" in database SDK, added "CheckRevisions" to URI "/system"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4594
diff
changeset
|
108 { |
5fabef29c4ff
added new primitive "hasRevisionsSupport" in database SDK, added "CheckRevisions" to URI "/system"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4594
diff
changeset
|
109 return false; // TODO - REVISIONS |
5fabef29c4ff
added new primitive "hasRevisionsSupport" in database SDK, added "CheckRevisions" to URI "/system"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4594
diff
changeset
|
110 } |
2772
f3df536e7366
moving the outdated database plugin sample into the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2697
diff
changeset
|
111 |
f3df536e7366
moving the outdated database plugin sample into the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2697
diff
changeset
|
112 |
f3df536e7366
moving the outdated database plugin sample into the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2697
diff
changeset
|
113 /** |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
114 * The "StartTransaction()" method is guaranteed to return a class |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
115 * derived from "UnitTestsTransaction". The methods of |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
116 * "UnitTestsTransaction" give access to additional information |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
117 * about the underlying SQLite database to be used in unit tests. |
2772
f3df536e7366
moving the outdated database plugin sample into the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2697
diff
changeset
|
118 **/ |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
119 class UnitTestsTransaction : public ITransaction |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
120 { |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
121 protected: |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
122 SQLite::Connection& db_; |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
123 |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
124 public: |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
125 UnitTestsTransaction(SQLite::Connection& db) : |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
126 db_(db) |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
127 { |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
128 } |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
129 |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
130 void GetChildren(std::list<std::string>& childrenPublicIds, |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
131 int64_t id); |
183 | 132 |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
133 int64_t GetTableRecordCount(const std::string& table); |
183 | 134 |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
135 bool GetParentPublicId(std::string& target, |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
136 int64_t id); |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
137 |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
138 int64_t CreateResource(const std::string& publicId, |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
139 ResourceType type); |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
140 |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
141 void AttachChild(int64_t parent, |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
142 int64_t child); |
521 | 143 |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
144 void SetIdentifierTag(int64_t id, |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
145 const DicomTag& tag, |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
146 const std::string& value); |
3084 | 147 |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
148 void SetMainDicomTag(int64_t id, |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
149 const DicomTag& tag, |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
150 const std::string& value); |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
151 }; |
183 | 152 }; |
153 } |