Mercurial > hg > orthanc
annotate OrthancServer/Sources/Database/SQLiteDatabaseWrapper.h @ 5676:b744a2cf408a find-refactoring
shorten ParentRetrieveSpecification/ChildrenRetrieveSpecification as ParentSpecification/ChildrenSpecification
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 06 Jul 2024 15:04:28 +0200 |
parents | f7adfb22e20e |
children | 3765085693e5 afd421225eb4 8279eaab0d1d |
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 |
5640
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5517
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5517
diff
changeset
|
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5220
diff
changeset
|
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
183 | 8 * |
9 * This program is free software: you can redistribute it and/or | |
10 * modify it under the terms of the GNU General Public License as | |
11 * published by the Free Software Foundation, either version 3 of the | |
12 * License, or (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, but | |
15 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 * General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
21 **/ | |
22 | |
23 | |
24 #pragma once | |
25 | |
5455
176bc05f85f4
DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents:
5220
diff
changeset
|
26 #include "BaseDatabaseWrapper.h" |
1247 | 27 |
4045 | 28 #include "../../../OrthancFramework/Sources/SQLite/Connection.h" |
1242 | 29 |
4594
d494b4f1103e
removed the global database mutex from ServerIndex and StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4591
diff
changeset
|
30 #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
|
31 |
183 | 32 namespace Orthanc |
33 { | |
34 /** | |
35 * This class manages an instance of the Orthanc SQLite database. It | |
36 * translates low-level requests into SQL statements. Mutual | |
37 * exclusion MUST be implemented at a higher level. | |
38 **/ | |
5455
176bc05f85f4
DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents:
5220
diff
changeset
|
39 class SQLiteDatabaseWrapper : public BaseDatabaseWrapper |
183 | 40 { |
41 private: | |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
42 class TransactionBase; |
4589
bec74e29f86b
attaching the listener to transactions in IDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4570
diff
changeset
|
43 class SignalFileDeleted; |
bec74e29f86b
attaching the listener to transactions in IDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4570
diff
changeset
|
44 class SignalResourceDeleted; |
bec74e29f86b
attaching the listener to transactions in IDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4570
diff
changeset
|
45 class SignalRemainingAncestor; |
4570
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
46 class ReadOnlyTransaction; |
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
47 class ReadWriteTransaction; |
3058
6faf575ba9cc
refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3056
diff
changeset
|
48 class LookupFormatter; |
3019
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3017
diff
changeset
|
49 |
4594
d494b4f1103e
removed the global database mutex from ServerIndex and StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4591
diff
changeset
|
50 boost::mutex mutex_; |
d494b4f1103e
removed the global database mutex from ServerIndex and StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4591
diff
changeset
|
51 SQLite::Connection db_; |
d494b4f1103e
removed the global database mutex from ServerIndex and StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4591
diff
changeset
|
52 TransactionBase* activeTransaction_; |
d494b4f1103e
removed the global database mutex from ServerIndex and StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4591
diff
changeset
|
53 SignalRemainingAncestor* signalRemainingAncestor_; |
d494b4f1103e
removed the global database mutex from ServerIndex and StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4591
diff
changeset
|
54 unsigned int version_; |
5455
176bc05f85f4
DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents:
5220
diff
changeset
|
55 IDatabaseWrapper::Capabilities dbCapabilities_; |
183 | 56 |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2772
diff
changeset
|
57 void GetChangesInternal(std::list<ServerIndexChange>& target, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2772
diff
changeset
|
58 bool& done, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2772
diff
changeset
|
59 SQLite::Statement& s, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2772
diff
changeset
|
60 uint32_t maxResults); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2772
diff
changeset
|
61 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2772
diff
changeset
|
62 void GetExportedResourcesInternal(std::list<ExportedResource>& target, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2772
diff
changeset
|
63 bool& done, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2772
diff
changeset
|
64 SQLite::Statement& s, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2772
diff
changeset
|
65 uint32_t maxResults); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2772
diff
changeset
|
66 |
183 | 67 public: |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2773
diff
changeset
|
68 SQLiteDatabaseWrapper(const std::string& path); |
1247 | 69 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2773
diff
changeset
|
70 SQLiteDatabaseWrapper(); |
1247 | 71 |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
72 virtual ~SQLiteDatabaseWrapper(); |
1672
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
73 |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
74 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
|
75 |
4594
d494b4f1103e
removed the global database mutex from ServerIndex and StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4591
diff
changeset
|
76 virtual void Close() ORTHANC_OVERRIDE; |
1672
4c5a85c3ff43
sample database plugin now working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1671
diff
changeset
|
77 |
4589
bec74e29f86b
attaching the listener to transactions in IDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4570
diff
changeset
|
78 virtual IDatabaseWrapper::ITransaction* StartTransaction(TransactionType type, |
bec74e29f86b
attaching the listener to transactions in IDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4570
diff
changeset
|
79 IDatabaseListener& listener) |
3050
d8a91acb7424
working on a database compatibility layer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3038
diff
changeset
|
80 ORTHANC_OVERRIDE; |
2772
f3df536e7366
moving the outdated database plugin sample into the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2697
diff
changeset
|
81 |
4594
d494b4f1103e
removed the global database mutex from ServerIndex and StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4591
diff
changeset
|
82 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
|
83 |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
84 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
|
85 { |
f3df536e7366
moving the outdated database plugin sample into the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2697
diff
changeset
|
86 return version_; |
f3df536e7366
moving the outdated database plugin sample into the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2697
diff
changeset
|
87 } |
f3df536e7366
moving the outdated database plugin sample into the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2697
diff
changeset
|
88 |
f3df536e7366
moving the outdated database plugin sample into the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2697
diff
changeset
|
89 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
|
90 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
|
91 |
5517
0d433132b249
refactoring IDatabaseWrapper::Capabilities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5497
diff
changeset
|
92 virtual const Capabilities GetDatabaseCapabilities() const ORTHANC_OVERRIDE |
4628
5fabef29c4ff
added new primitive "hasRevisionsSupport" in database SDK, added "CheckRevisions" to URI "/system"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4594
diff
changeset
|
93 { |
5455
176bc05f85f4
DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents:
5220
diff
changeset
|
94 return dbCapabilities_; |
4628
5fabef29c4ff
added new primitive "hasRevisionsSupport" in database SDK, added "CheckRevisions" to URI "/system"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4594
diff
changeset
|
95 } |
2772
f3df536e7366
moving the outdated database plugin sample into the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2697
diff
changeset
|
96 |
5493
b3ebe249ed5b
At startup, when using a database plugin, display the latency to access the DB
Alain Mazy <am@osimis.io>
parents:
5455
diff
changeset
|
97 virtual uint64_t MeasureLatency() ORTHANC_OVERRIDE |
5220
df39c7583a49
preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
98 { |
5493
b3ebe249ed5b
At startup, when using a database plugin, display the latency to access the DB
Alain Mazy <am@osimis.io>
parents:
5455
diff
changeset
|
99 throw OrthancException(ErrorCode_NotImplemented); |
5220
df39c7583a49
preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
100 } |
df39c7583a49
preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
101 |
2772
f3df536e7366
moving the outdated database plugin sample into the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2697
diff
changeset
|
102 /** |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
103 * 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
|
104 * 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
|
105 * "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
|
106 * 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
|
107 **/ |
5455
176bc05f85f4
DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents:
5220
diff
changeset
|
108 class UnitTestsTransaction : public BaseDatabaseWrapper::BaseTransaction |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
109 { |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
110 protected: |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
111 SQLite::Connection& db_; |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
112 |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
113 public: |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
114 UnitTestsTransaction(SQLite::Connection& db) : |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
115 db_(db) |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
116 { |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
117 } |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
118 |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
119 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
|
120 int64_t id); |
183 | 121 |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
122 int64_t GetTableRecordCount(const std::string& table); |
183 | 123 |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
124 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
|
125 int64_t id); |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
126 |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
127 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
|
128 ResourceType type); |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
129 |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
130 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
|
131 int64_t child); |
521 | 132 |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
133 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
|
134 const DicomTag& tag, |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
135 const std::string& value); |
3084 | 136 |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
137 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
|
138 const DicomTag& tag, |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
139 const std::string& value); |
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
140 }; |
183 | 141 }; |
142 } |