Mercurial > hg > orthanc-databases
annotate Framework/Plugins/StorageBackend.cpp @ 395:a7a029043670 db-protobuf
integration mainline->db-protobuf
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 05 Apr 2023 14:53:57 +0200 |
parents | 3d6886f3e5b3 |
children | ecd0b719cff5 |
rev | line source |
---|---|
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
389
3d6886f3e5b3
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
359
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
3d6886f3e5b3
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
359
diff
changeset
|
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * This program is free software: you can redistribute it and/or |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * modify it under the terms of the GNU Affero General Public License |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * as published by the Free Software Foundation, either version 3 of |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * the License, or (at your option) any later version. |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, but |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * Affero General Public License for more details. |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * You should have received a copy of the GNU Affero General Public License |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 **/ |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 #include "StorageBackend.h" |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 #if HAS_ORTHANC_EXCEPTION != 1 |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 # error HAS_ORTHANC_EXCEPTION must be set to 1 |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 #endif |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
29 #include "../../Framework/Common/BinaryStringValue.h" |
245
9d00e5e073e8
rename FileValue as ResultFileValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
244
diff
changeset
|
30 #include "../../Framework/Common/ResultFileValue.h" |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
31 |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
32 #include <Compatibility.h> // For std::unique_ptr<> |
249
7f5ee2b42a86
better performance warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
33 #include <Logging.h> |
152 | 34 #include <OrthancException.h> |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 |
269
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
36 #include <boost/thread.hpp> |
231
0a9b48d19643
removed mutex out of DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
230
diff
changeset
|
37 #include <cassert> |
194
a51ce147dbe0
refactoring using new class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
38 #include <limits> |
a51ce147dbe0
refactoring using new class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
39 |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 #define ORTHANC_PLUGINS_DATABASE_CATCH \ |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 catch (::Orthanc::OrthancException& e) \ |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 { \ |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); \ |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 } \ |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 catch (::std::runtime_error& e) \ |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 { \ |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 std::string s = "Exception in storage area back-end: " + std::string(e.what()); \ |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 OrthancPluginLogError(context_, s.c_str()); \ |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 return OrthancPluginErrorCode_DatabasePlugin; \ |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 } \ |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 catch (...) \ |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 { \ |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 OrthancPluginLogError(context_, "Native exception"); \ |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 return OrthancPluginErrorCode_DatabasePlugin; \ |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 } |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 namespace OrthancDatabases |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 { |
269
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
61 class StorageBackend::ReadWholeOperation : public StorageBackend::IDatabaseOperation |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
62 { |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
63 private: |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
64 IFileContentVisitor& visitor_; |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
65 const char* uuid_; |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
66 OrthancPluginContentType type_; |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
67 |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
68 public: |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
69 ReadWholeOperation(IFileContentVisitor& visitor, |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
70 const char* uuid, |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
71 OrthancPluginContentType type) : |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
72 visitor_(visitor), |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
73 uuid_(uuid), |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
74 type_(type) |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
75 { |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
76 } |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
77 |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
78 virtual void Execute(StorageBackend::IAccessor& accessor) ORTHANC_OVERRIDE |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
79 { |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
80 accessor.ReadWhole(visitor_, uuid_, type_); |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
81 } |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
82 }; |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
83 |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
84 |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
85 StorageBackend::StorageBackend(IDatabaseFactory* factory, |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
86 unsigned int maxRetries) : |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
87 manager_(factory), |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
88 maxRetries_(maxRetries) |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 { |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 } |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
91 |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
92 void StorageBackend::AccessorBase::Create(const std::string& uuid, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
93 const void* content, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
94 size_t size, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
95 OrthancPluginContentType type) |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
96 { |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
97 DatabaseManager::Transaction transaction(manager_, TransactionType_ReadWrite); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
98 |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
99 { |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
100 DatabaseManager::CachedStatement statement( |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
101 STATEMENT_FROM_HERE, manager_, |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
102 "INSERT INTO StorageArea VALUES (${uuid}, ${content}, ${type})"); |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
103 |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
104 statement.SetParameterType("uuid", ValueType_Utf8String); |
244
02cd7254c949
separating class InputFileValue from FileValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
242
diff
changeset
|
105 statement.SetParameterType("content", ValueType_InputFile); |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
106 statement.SetParameterType("type", ValueType_Integer64); |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
107 |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
108 Dictionary args; |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
109 args.SetUtf8Value("uuid", uuid); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
110 args.SetFileValue("content", content, size); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
111 args.SetIntegerValue("type", type); |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
112 |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
113 statement.Execute(args); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
114 } |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
115 |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
116 transaction.Commit(); |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
117 } |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
118 |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
119 |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
120 void StorageBackend::AccessorBase::ReadWhole(StorageBackend::IFileContentVisitor& visitor, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
121 const std::string& uuid, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
122 OrthancPluginContentType type) |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
123 { |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
124 DatabaseManager::Transaction transaction(manager_, TransactionType_ReadOnly); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
125 |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
126 { |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
127 DatabaseManager::CachedStatement statement( |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
128 STATEMENT_FROM_HERE, manager_, |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
129 "SELECT content FROM StorageArea WHERE uuid=${uuid} AND type=${type}"); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
130 |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
131 statement.SetParameterType("uuid", ValueType_Utf8String); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
132 statement.SetParameterType("type", ValueType_Integer64); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
133 |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
134 Dictionary args; |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
135 args.SetUtf8Value("uuid", uuid); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
136 args.SetIntegerValue("type", type); |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
137 |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
138 statement.Execute(args); |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
139 |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
140 if (statement.IsDone()) |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
141 { |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
142 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
143 } |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
144 else if (statement.GetResultFieldsCount() != 1) |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
145 { |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
146 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
147 } |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
148 else |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
149 { |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
150 const IValue& value = statement.GetResultField(0); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
151 |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
152 switch (value.GetType()) |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
153 { |
245
9d00e5e073e8
rename FileValue as ResultFileValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
244
diff
changeset
|
154 case ValueType_ResultFile: |
246
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
155 { |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
156 std::string content; |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
157 dynamic_cast<const ResultFileValue&>(value).ReadWhole(content); |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
158 visitor.Assign(content); |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
159 break; |
246
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
160 } |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
161 |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
162 case ValueType_BinaryString: |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
163 visitor.Assign(dynamic_cast<const BinaryStringValue&>(value).GetContent()); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
164 break; |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
165 |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
166 default: |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
167 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
168 } |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
169 } |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
170 } |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
171 |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
172 transaction.Commit(); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
173 |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
174 if (!visitor.IsSuccess()) |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
175 { |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
176 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database, "Could not read attachment from the storage area"); |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
177 } |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
178 } |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
179 |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
180 |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
181 void StorageBackend::AccessorBase::ReadRange(IFileContentVisitor& visitor, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
182 const std::string& uuid, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
183 OrthancPluginContentType type, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
184 uint64_t start, |
246
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
185 size_t length) |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
186 { |
246
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
187 /** |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
188 * This is a generic implementation, that will only work if |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
189 * "ResultFileValue" is implemented by the database backend. For |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
190 * instance, this will *not* work with MySQL, as the latter uses |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
191 * BLOB columns to store files. |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
192 **/ |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
193 DatabaseManager::Transaction transaction(manager_, TransactionType_ReadOnly); |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
194 |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
195 { |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
196 DatabaseManager::CachedStatement statement( |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
197 STATEMENT_FROM_HERE, manager_, |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
198 "SELECT content FROM StorageArea WHERE uuid=${uuid} AND type=${type}"); |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
199 |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
200 statement.SetParameterType("uuid", ValueType_Utf8String); |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
201 statement.SetParameterType("type", ValueType_Integer64); |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
202 |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
203 Dictionary args; |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
204 args.SetUtf8Value("uuid", uuid); |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
205 args.SetIntegerValue("type", type); |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
206 |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
207 statement.Execute(args); |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
208 |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
209 if (statement.IsDone()) |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
210 { |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
211 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource); |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
212 } |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
213 else if (statement.GetResultFieldsCount() != 1) |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
214 { |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
215 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
216 } |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
217 else |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
218 { |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
219 const IValue& value = statement.GetResultField(0); |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
220 if (value.GetType() == ValueType_ResultFile) |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
221 { |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
222 std::string content; |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
223 dynamic_cast<const ResultFileValue&>(value).ReadRange(content, start, length); |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
224 visitor.Assign(content); |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
225 } |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
226 else |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
227 { |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
228 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
229 } |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
230 } |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
231 } |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
232 |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
233 transaction.Commit(); |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
234 |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
235 if (!visitor.IsSuccess()) |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
236 { |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
237 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database, "Could not read attachment from the storage area"); |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
238 } |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
239 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
240 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
241 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
242 void StorageBackend::AccessorBase::Remove(const std::string& uuid, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
243 OrthancPluginContentType type) |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
244 { |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
245 DatabaseManager::Transaction transaction(manager_, TransactionType_ReadWrite); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
246 |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
247 { |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
248 DatabaseManager::CachedStatement statement( |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
249 STATEMENT_FROM_HERE, manager_, |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
250 "DELETE FROM StorageArea WHERE uuid=${uuid} AND type=${type}"); |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
251 |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
252 statement.SetParameterType("uuid", ValueType_Utf8String); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
253 statement.SetParameterType("type", ValueType_Integer64); |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
254 |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
255 Dictionary args; |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
256 args.SetUtf8Value("uuid", uuid); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
257 args.SetIntegerValue("type", type); |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
258 |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
259 statement.Execute(args); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
260 } |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
261 |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
262 transaction.Commit(); |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
263 } |
269
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
264 |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
265 |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
266 static OrthancPluginContext* context_ = NULL; |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
267 static std::unique_ptr<StorageBackend> backend_; |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
268 |
12
41543239072d
transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1
diff
changeset
|
269 |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
270 static OrthancPluginErrorCode StorageCreate(const char* uuid, |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
271 const void* content, |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
272 int64_t size, |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
273 OrthancPluginContentType type) |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
274 { |
269
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
275 class Operation : public StorageBackend::IDatabaseOperation |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
276 { |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
277 private: |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
278 const char* uuid_; |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
279 const void* content_; |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
280 int64_t size_; |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
281 OrthancPluginContentType type_; |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
282 |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
283 public: |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
284 Operation(const char* uuid, |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
285 const void* content, |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
286 int64_t size, |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
287 OrthancPluginContentType type) : |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
288 uuid_(uuid), |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
289 content_(content), |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
290 size_(size), |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
291 type_(type) |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
292 { |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
293 } |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
294 |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
295 virtual void Execute(StorageBackend::IAccessor& accessor) ORTHANC_OVERRIDE |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
296 { |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
297 accessor.Create(uuid_, content_, size_, type_); |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
298 } |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
299 }; |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
300 |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
301 |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
302 try |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
303 { |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
304 if (backend_.get() == NULL) |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
305 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
306 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
307 } |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
308 else |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
309 { |
269
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
310 Operation operation(uuid, content, size, type); |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
311 backend_->Execute(operation); |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
312 return OrthancPluginErrorCode_Success; |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
313 } |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
314 } |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
315 ORTHANC_PLUGINS_DATABASE_CATCH; |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
316 } |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
317 |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
318 |
271
6b18d3fbee82
backward compatibility with Orthanc SDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
319 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) |
6b18d3fbee82
backward compatibility with Orthanc SDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
320 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 9, 0) |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
321 static OrthancPluginErrorCode StorageReadWhole(OrthancPluginMemoryBuffer64* target, |
195
53bd9022c58b
Support of "OrthancPluginRegisterStorageArea2()" from Orthanc SDK 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
194
diff
changeset
|
322 const char* uuid, |
53bd9022c58b
Support of "OrthancPluginRegisterStorageArea2()" from Orthanc SDK 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
194
diff
changeset
|
323 OrthancPluginContentType type) |
53bd9022c58b
Support of "OrthancPluginRegisterStorageArea2()" from Orthanc SDK 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
194
diff
changeset
|
324 { |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
325 class Visitor : public StorageBackend::IFileContentVisitor |
195
53bd9022c58b
Support of "OrthancPluginRegisterStorageArea2()" from Orthanc SDK 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
194
diff
changeset
|
326 { |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
327 private: |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
328 OrthancPluginMemoryBuffer64* target_; |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
329 bool success_; |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
330 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
331 public: |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
332 Visitor(OrthancPluginMemoryBuffer64* target) : |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
333 target_(target), |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
334 success_(false) |
195
53bd9022c58b
Support of "OrthancPluginRegisterStorageArea2()" from Orthanc SDK 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
194
diff
changeset
|
335 { |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
336 if (target == NULL) |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
337 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
338 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
339 } |
195
53bd9022c58b
Support of "OrthancPluginRegisterStorageArea2()" from Orthanc SDK 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
194
diff
changeset
|
340 } |
53bd9022c58b
Support of "OrthancPluginRegisterStorageArea2()" from Orthanc SDK 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
194
diff
changeset
|
341 |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
342 virtual bool IsSuccess() const ORTHANC_OVERRIDE |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
343 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
344 return success_; |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
345 } |
195
53bd9022c58b
Support of "OrthancPluginRegisterStorageArea2()" from Orthanc SDK 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
194
diff
changeset
|
346 |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
347 virtual void Assign(const std::string& content) ORTHANC_OVERRIDE |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
348 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
349 if (success_) |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
350 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
351 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
352 } |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
353 else |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
354 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
355 assert(context_ != NULL); |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
356 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
357 if (OrthancPluginCreateMemoryBuffer64(context_, target_, static_cast<uint64_t>(content.size())) != |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
358 OrthancPluginErrorCode_Success) |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
359 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
360 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotEnoughMemory); |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
361 } |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
362 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
363 if (!content.empty()) |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
364 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
365 memcpy(target_->data, content.c_str(), content.size()); |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
366 } |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
367 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
368 success_ = true; |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
369 } |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
370 } |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
371 }; |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
372 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
373 |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
374 try |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
375 { |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
376 if (backend_.get() == NULL) |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
377 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
378 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
379 } |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
380 else |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
381 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
382 Visitor visitor(target); |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
383 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
384 { |
269
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
385 StorageBackend::ReadWholeOperation operation(visitor, uuid, type); |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
386 backend_->Execute(operation); |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
387 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
388 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
389 return OrthancPluginErrorCode_Success; |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
390 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
391 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
392 ORTHANC_PLUGINS_DATABASE_CATCH; |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
393 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
394 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
395 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
396 static OrthancPluginErrorCode StorageReadRange(OrthancPluginMemoryBuffer64* target, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
397 const char* uuid, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
398 OrthancPluginContentType type, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
399 uint64_t start) |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
400 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
401 class Visitor : public StorageBackend::IFileContentVisitor |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
402 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
403 private: |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
404 OrthancPluginMemoryBuffer64* target_; // This buffer is already allocated by the Orthanc core |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
405 bool success_; |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
406 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
407 public: |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
408 Visitor(OrthancPluginMemoryBuffer64* target) : |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
409 target_(target), |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
410 success_(false) |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
411 { |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
412 if (target == NULL) |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
413 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
414 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
415 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
416 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
417 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
418 virtual bool IsSuccess() const ORTHANC_OVERRIDE |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
419 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
420 return success_; |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
421 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
422 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
423 virtual void Assign(const std::string& content) ORTHANC_OVERRIDE |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
424 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
425 if (success_) |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
426 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
427 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
428 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
429 else |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
430 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
431 if (content.size() != target_->size) |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
432 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
433 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
434 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
435 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
436 if (!content.empty()) |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
437 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
438 memcpy(target_->data, content.c_str(), content.size()); |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
439 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
440 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
441 success_ = true; |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
442 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
443 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
444 }; |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
445 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
446 |
269
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
447 class Operation : public StorageBackend::IDatabaseOperation |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
448 { |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
449 private: |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
450 Visitor& visitor_; |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
451 const char* uuid_; |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
452 OrthancPluginContentType type_; |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
453 uint64_t start_; |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
454 size_t length_; |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
455 |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
456 public: |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
457 Operation(Visitor& visitor, |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
458 const char* uuid, |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
459 OrthancPluginContentType type, |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
460 uint64_t start, |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
461 size_t length) : |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
462 visitor_(visitor), |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
463 uuid_(uuid), |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
464 type_(type), |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
465 start_(start), |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
466 length_(length) |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
467 { |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
468 } |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
469 |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
470 virtual void Execute(StorageBackend::IAccessor& accessor) ORTHANC_OVERRIDE |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
471 { |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
472 accessor.ReadRange(visitor_, uuid_, type_, start_, length_); |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
473 } |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
474 }; |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
475 |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
476 |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
477 try |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
478 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
479 if (backend_.get() == NULL) |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
480 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
481 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
482 } |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
483 else |
194
a51ce147dbe0
refactoring using new class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
484 { |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
485 Visitor visitor(target); |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
486 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
487 { |
269
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
488 Operation operation(visitor, uuid, type, start, target->size); |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
489 backend_->Execute(operation); |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
490 } |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
491 |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
492 return OrthancPluginErrorCode_Success; |
194
a51ce147dbe0
refactoring using new class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
493 } |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
494 } |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
495 ORTHANC_PLUGINS_DATABASE_CATCH; |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
496 } |
271
6b18d3fbee82
backward compatibility with Orthanc SDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
497 # endif |
195
53bd9022c58b
Support of "OrthancPluginRegisterStorageArea2()" from Orthanc SDK 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
194
diff
changeset
|
498 #endif |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
499 |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
500 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
501 static OrthancPluginErrorCode StorageRead(void** data, |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
502 int64_t* size, |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
503 const char* uuid, |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
504 OrthancPluginContentType type) |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
505 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
506 class Visitor : public StorageBackend::IFileContentVisitor |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
507 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
508 private: |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
509 void** data_; |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
510 int64_t* size_; |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
511 bool success_; |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
512 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
513 public: |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
514 Visitor(void** data, |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
515 int64_t* size) : |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
516 data_(data), |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
517 size_(size), |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
518 success_(false) |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
519 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
520 } |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
521 |
252 | 522 ~Visitor() |
523 { | |
524 if (data_ != NULL /* this condition is invalidated by "Release()" */ && | |
525 *data_ != NULL) | |
526 { | |
527 free(*data_); | |
528 } | |
529 } | |
530 | |
531 void Release() | |
532 { | |
533 data_ = NULL; | |
534 } | |
535 | |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
536 virtual bool IsSuccess() const ORTHANC_OVERRIDE |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
537 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
538 return success_; |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
539 } |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
540 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
541 virtual void Assign(const std::string& content) ORTHANC_OVERRIDE |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
542 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
543 if (success_) |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
544 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
545 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
546 } |
252 | 547 else if (data_ == NULL) |
548 { | |
549 // "Release()" has been called | |
550 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
551 } | |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
552 else |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
553 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
554 if (content.empty()) |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
555 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
556 *data_ = NULL; |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
557 *size_ = 0; |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
558 } |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
559 else |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
560 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
561 *size_ = static_cast<int64_t>(content.size()); |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
562 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
563 if (static_cast<size_t>(*size_) != content.size()) |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
564 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
565 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotEnoughMemory, |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
566 "File cannot be stored in a 63bit buffer"); |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
567 } |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
568 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
569 *data_ = malloc(*size_); |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
570 if (*data_ == NULL) |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
571 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
572 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotEnoughMemory); |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
573 } |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
574 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
575 memcpy(*data_, content.c_str(), *size_); |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
576 } |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
577 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
578 success_ = true; |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
579 } |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
580 } |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
581 }; |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
582 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
583 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
584 try |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
585 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
586 if (backend_.get() == NULL) |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
587 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
588 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
589 } |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
590 else if (data == NULL || |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
591 size == NULL) |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
592 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
593 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
594 } |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
595 else |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
596 { |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
597 Visitor visitor(data, size); |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
598 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
599 { |
269
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
600 StorageBackend::ReadWholeOperation operation(visitor, uuid, type); |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
601 backend_->Execute(operation); |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
602 } |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
603 |
252 | 604 visitor.Release(); |
605 | |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
606 return OrthancPluginErrorCode_Success; |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
607 } |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
608 } |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
609 ORTHANC_PLUGINS_DATABASE_CATCH; |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
610 } |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
611 |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
612 |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
613 static OrthancPluginErrorCode StorageRemove(const char* uuid, |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
614 OrthancPluginContentType type) |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
615 { |
269
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
616 class Operation : public StorageBackend::IDatabaseOperation |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
617 { |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
618 private: |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
619 const char* uuid_; |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
620 OrthancPluginContentType type_; |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
621 |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
622 public: |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
623 Operation(const char* uuid, |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
624 OrthancPluginContentType type) : |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
625 uuid_(uuid), |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
626 type_(type) |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
627 { |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
628 } |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
629 |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
630 virtual void Execute(StorageBackend::IAccessor& accessor) ORTHANC_OVERRIDE |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
631 { |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
632 accessor.Remove(uuid_, type_); |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
633 } |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
634 }; |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
635 |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
636 |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
637 try |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
638 { |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
639 if (backend_.get() == NULL) |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
640 { |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
641 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
642 } |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
643 else |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
644 { |
269
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
645 Operation operation(uuid, type); |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
646 backend_->Execute(operation); |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
647 return OrthancPluginErrorCode_Success; |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
648 } |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
649 } |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
650 ORTHANC_PLUGINS_DATABASE_CATCH; |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
651 } |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
652 |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
653 |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
654 void StorageBackend::Register(OrthancPluginContext* context, |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
655 StorageBackend* backend) |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
656 { |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
657 if (context == NULL || |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
658 backend == NULL) |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
659 { |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
660 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
661 } |
269
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
662 else if (context_ != NULL || |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
663 backend_.get() != NULL) |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
664 { |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
665 // This function can only be invoked once in the plugin |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
666 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
667 } |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
668 else |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
669 { |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
670 context_ = context; |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
671 backend_.reset(backend); |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
672 |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
673 bool hasLoadedV2 = false; |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
674 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
675 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in Orthanc 1.3.1 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
676 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 9, 0) |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
677 if (OrthancPluginCheckVersionAdvanced(context, 1, 9, 0) == 1) |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
678 { |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
679 OrthancPluginStorageReadRange readRange = NULL; |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
680 if (backend_->HasReadRange()) |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
681 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
682 readRange = StorageReadRange; |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
683 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
684 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
685 OrthancPluginRegisterStorageArea2(context_, StorageCreate, StorageReadWhole, readRange, StorageRemove); |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
686 hasLoadedV2 = true; |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
687 } |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
688 # endif |
195
53bd9022c58b
Support of "OrthancPluginRegisterStorageArea2()" from Orthanc SDK 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
194
diff
changeset
|
689 #endif |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
690 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
691 if (!hasLoadedV2) |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
692 { |
278
e55e4e8f9459
improved log message
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
274
diff
changeset
|
693 LOG(WARNING) << "Performance warning: Your version of the Orthanc core or SDK doesn't support reading of file ranges"; |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
694 OrthancPluginRegisterStorageArea(context_, StorageCreate, StorageRead, StorageRemove); |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
695 } |
270 | 696 |
697 LOG(WARNING) << "The storage area plugin will retry up to " << backend_->GetMaxRetries() | |
698 << " time(s) in the case of a collision"; | |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
699 } |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
700 } |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
701 |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
702 |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
703 void StorageBackend::Finalize() |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
704 { |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
705 backend_.reset(NULL); |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
706 context_ = NULL; |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
707 } |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
708 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
709 |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
710 class StorageBackend::StringVisitor : public StorageBackend::IFileContentVisitor |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
711 { |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
712 private: |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
713 std::string& target_; |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
714 bool success_; |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
715 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
716 public: |
252 | 717 explicit StringVisitor(std::string& target) : |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
718 target_(target), |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
719 success_(false) |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
720 { |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
721 } |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
722 |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
723 virtual bool IsSuccess() const ORTHANC_OVERRIDE |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
724 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
725 return success_; |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
726 } |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
727 |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
728 virtual void Assign(const std::string& content) ORTHANC_OVERRIDE |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
729 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
730 if (success_) |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
731 { |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
732 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
733 } |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
734 else |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
735 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
736 target_.assign(content); |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
737 success_ = true; |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
738 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
739 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
740 }; |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
741 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
742 |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
743 void StorageBackend::ReadWholeToString(std::string& target, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
744 IAccessor& accessor, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
745 const std::string& uuid, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
746 OrthancPluginContentType type) |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
747 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
748 StringVisitor visitor(target); |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
749 accessor.ReadWhole(visitor, uuid, type); |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
750 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
751 if (!visitor.IsSuccess()) |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
752 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
753 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
754 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
755 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
756 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
757 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
758 void StorageBackend::ReadRangeToString(std::string& target, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
759 IAccessor& accessor, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
760 const std::string& uuid, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
761 OrthancPluginContentType type, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
762 uint64_t start, |
246
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
763 size_t length) |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
764 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
765 StringVisitor visitor(target); |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
766 accessor.ReadRange(visitor, uuid, type, start, length); |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
767 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
768 if (!visitor.IsSuccess()) |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
769 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
770 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
771 } |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
772 } |
269
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
773 |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
774 |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
775 void StorageBackend::Execute(IDatabaseOperation& operation) |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
776 { |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
777 std::unique_ptr<IAccessor> accessor(CreateAccessor()); |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
778 if (accessor.get() == NULL) |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
779 { |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
780 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
781 } |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
782 |
323 | 783 #if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 2) |
269
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
784 unsigned int attempt = 0; |
323 | 785 #endif |
269
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
786 |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
787 for (;;) |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
788 { |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
789 try |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
790 { |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
791 operation.Execute(*accessor); |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
792 return; // Success |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
793 } |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
794 catch (Orthanc::OrthancException& e) |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
795 { |
274
b988cb30534f
backward compatibility against old versions of the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
271
diff
changeset
|
796 #if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 2) |
269
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
797 if (e.GetErrorCode() == Orthanc::ErrorCode_DatabaseCannotSerialize) |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
798 { |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
799 if (attempt >= maxRetries_) |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
800 { |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
801 throw; |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
802 } |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
803 else |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
804 { |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
805 attempt++; |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
806 |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
807 // The "rand()" adds some jitter to de-synchronize writers |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
808 boost::this_thread::sleep(boost::posix_time::milliseconds(100 * attempt + 5 * (rand() % 10))); |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
809 } |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
810 } |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
811 else |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
812 { |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
813 throw; |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
814 } |
274
b988cb30534f
backward compatibility against old versions of the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
271
diff
changeset
|
815 #else |
b988cb30534f
backward compatibility against old versions of the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
271
diff
changeset
|
816 throw; |
b988cb30534f
backward compatibility against old versions of the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
271
diff
changeset
|
817 #endif |
269
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
818 } |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
819 } |
567761f0c1ea
fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
820 } |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
821 } |