Mercurial > hg > orthanc-databases
annotate Framework/Plugins/StorageBackend.cpp @ 253:3bc442765b88
new configuration option: "IndexConnectionsCount"
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 14 Apr 2021 15:08:51 +0200 |
parents | 33fa478c119a |
children | d663d9e44f8d |
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 |
193
3236894320d6
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
157
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Affero General Public License |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * 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
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * Affero General Public License for more details. |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * 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
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 **/ |
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 #include "StorageBackend.h" |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 #if HAS_ORTHANC_EXCEPTION != 1 |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 # error HAS_ORTHANC_EXCEPTION must be set to 1 |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 #endif |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
28 #include "../../Framework/Common/BinaryStringValue.h" |
245
9d00e5e073e8
rename FileValue as ResultFileValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
244
diff
changeset
|
29 #include "../../Framework/Common/ResultFileValue.h" |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
30 |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
31 #include <Compatibility.h> // For std::unique_ptr<> |
249
7f5ee2b42a86
better performance warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
32 #include <Logging.h> |
152 | 33 #include <OrthancException.h> |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 |
231
0a9b48d19643
removed mutex out of DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
230
diff
changeset
|
35 #include <cassert> |
194
a51ce147dbe0
refactoring using new class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
36 #include <limits> |
a51ce147dbe0
refactoring using new class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
37 |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 #define ORTHANC_PLUGINS_DATABASE_CATCH \ |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 catch (::Orthanc::OrthancException& e) \ |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 { \ |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); \ |
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 catch (::std::runtime_error& e) \ |
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 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
|
47 OrthancPluginLogError(context_, s.c_str()); \ |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 return OrthancPluginErrorCode_DatabasePlugin; \ |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 } \ |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 catch (...) \ |
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 OrthancPluginLogError(context_, "Native exception"); \ |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 return OrthancPluginErrorCode_DatabasePlugin; \ |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 } |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 |
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 namespace OrthancDatabases |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 { |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
59 void StorageBackend::SetDatabase(IDatabase* database) |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 { |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
61 if (database == NULL) |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
62 { |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
63 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
64 } |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
65 else if (manager_.get() != NULL) |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
66 { |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
67 delete database; |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
68 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
69 } |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
70 else |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
71 { |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
72 manager_.reset(new DatabaseManager(database)); |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
73 } |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 } |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
75 |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
76 DatabaseManager& StorageBackend::GetManager() |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
77 { |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
78 if (manager_.get() == NULL) |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
79 { |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
80 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
81 } |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
82 else |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
83 { |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
84 return *manager_; |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
85 } |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
86 } |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
87 |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
89 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
|
90 const void* content, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
91 size_t size, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
92 OrthancPluginContentType type) |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
93 { |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
94 DatabaseManager::Transaction transaction(manager_, TransactionType_ReadWrite); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
95 |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
96 { |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
97 DatabaseManager::CachedStatement statement( |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
98 STATEMENT_FROM_HERE, manager_, |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
99 "INSERT INTO StorageArea VALUES (${uuid}, ${content}, ${type})"); |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
100 |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
101 statement.SetParameterType("uuid", ValueType_Utf8String); |
244
02cd7254c949
separating class InputFileValue from FileValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
242
diff
changeset
|
102 statement.SetParameterType("content", ValueType_InputFile); |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
103 statement.SetParameterType("type", ValueType_Integer64); |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
104 |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
105 Dictionary args; |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
106 args.SetUtf8Value("uuid", uuid); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
107 args.SetFileValue("content", content, size); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
108 args.SetIntegerValue("type", type); |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
109 |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
110 statement.Execute(args); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
111 } |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
112 |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
113 transaction.Commit(); |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
114 } |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
115 |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
116 |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
117 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
|
118 const std::string& uuid, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
119 OrthancPluginContentType type) |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
120 { |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
121 DatabaseManager::Transaction transaction(manager_, TransactionType_ReadOnly); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
122 |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
123 { |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
124 DatabaseManager::CachedStatement statement( |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
125 STATEMENT_FROM_HERE, manager_, |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
126 "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
|
127 |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
128 statement.SetParameterType("uuid", ValueType_Utf8String); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
129 statement.SetParameterType("type", ValueType_Integer64); |
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 Dictionary args; |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
132 args.SetUtf8Value("uuid", uuid); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
133 args.SetIntegerValue("type", type); |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
134 |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
135 statement.Execute(args); |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
136 |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
137 if (statement.IsDone()) |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
138 { |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
139 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
140 } |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
141 else if (statement.GetResultFieldsCount() != 1) |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
142 { |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
143 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
144 } |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
145 else |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
146 { |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
147 const IValue& value = statement.GetResultField(0); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
148 |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
149 switch (value.GetType()) |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
150 { |
245
9d00e5e073e8
rename FileValue as ResultFileValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
244
diff
changeset
|
151 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
|
152 { |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
153 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
|
154 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
|
155 visitor.Assign(content); |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
156 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
|
157 } |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
158 |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
159 case ValueType_BinaryString: |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
160 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
|
161 break; |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
162 |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
163 default: |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
164 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
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 } |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
167 } |
230
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 transaction.Commit(); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
170 |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
171 if (!visitor.IsSuccess()) |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
172 { |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
173 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
|
174 } |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
175 } |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
176 |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
177 |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
178 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
|
179 const std::string& uuid, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
180 OrthancPluginContentType type, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
181 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
|
182 size_t length) |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
183 { |
246
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
184 /** |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
185 * 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
|
186 * "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
|
187 * 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
|
188 * 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
|
189 **/ |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
190 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
|
191 |
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::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
|
194 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
|
195 "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
|
196 |
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.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
|
198 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
|
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 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
|
201 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
|
202 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
|
203 |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
204 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
|
205 |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
206 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
|
207 { |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
208 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
|
209 } |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
210 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
|
211 { |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
212 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
|
213 } |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
214 else |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
215 { |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
216 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
|
217 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
|
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 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
|
220 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
|
221 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
|
222 } |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
223 else |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
224 { |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
225 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
|
226 } |
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 } |
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 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
|
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 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
|
233 { |
483af3f35a4b
turning ResultFileValue into a base class, and implement its primitives for PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
245
diff
changeset
|
234 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
|
235 } |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
236 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
237 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
238 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
239 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
|
240 OrthancPluginContentType type) |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
241 { |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
242 DatabaseManager::Transaction transaction(manager_, TransactionType_ReadWrite); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
243 |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
244 { |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
245 DatabaseManager::CachedStatement statement( |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
246 STATEMENT_FROM_HERE, manager_, |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
247 "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
|
248 |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
249 statement.SetParameterType("uuid", ValueType_Utf8String); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
250 statement.SetParameterType("type", ValueType_Integer64); |
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 Dictionary args; |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
253 args.SetUtf8Value("uuid", uuid); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
254 args.SetIntegerValue("type", type); |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
255 |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
256 statement.Execute(args); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
257 } |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
258 |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
259 transaction.Commit(); |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
260 } |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
261 |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
262 |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
14
diff
changeset
|
263 |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
264 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
|
265 static std::unique_ptr<StorageBackend> backend_; |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
266 |
12
41543239072d
transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1
diff
changeset
|
267 |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
268 static OrthancPluginErrorCode StorageCreate(const char* uuid, |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
269 const void* content, |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
270 int64_t size, |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
271 OrthancPluginContentType type) |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
272 { |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
273 try |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
274 { |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
275 if (backend_.get() == NULL) |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
276 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
277 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
278 } |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
279 else |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
280 { |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
281 std::unique_ptr<StorageBackend::IAccessor> accessor(backend_->CreateAccessor()); |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
282 accessor->Create(uuid, content, static_cast<size_t>(size), type); |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
283 return OrthancPluginErrorCode_Success; |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
284 } |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
285 } |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
286 ORTHANC_PLUGINS_DATABASE_CATCH; |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
287 } |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
288 |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
289 |
195
53bd9022c58b
Support of "OrthancPluginRegisterStorageArea2()" from Orthanc SDK 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
194
diff
changeset
|
290 #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
|
291 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
|
292 const char* uuid, |
53bd9022c58b
Support of "OrthancPluginRegisterStorageArea2()" from Orthanc SDK 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
194
diff
changeset
|
293 OrthancPluginContentType type) |
53bd9022c58b
Support of "OrthancPluginRegisterStorageArea2()" from Orthanc SDK 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
194
diff
changeset
|
294 { |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
295 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
|
296 { |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
297 private: |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
298 OrthancPluginMemoryBuffer64* target_; |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
299 bool success_; |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
300 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
301 public: |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
302 Visitor(OrthancPluginMemoryBuffer64* target) : |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
303 target_(target), |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
304 success_(false) |
195
53bd9022c58b
Support of "OrthancPluginRegisterStorageArea2()" from Orthanc SDK 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
194
diff
changeset
|
305 { |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
306 if (target == NULL) |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
307 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
308 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
|
309 } |
195
53bd9022c58b
Support of "OrthancPluginRegisterStorageArea2()" from Orthanc SDK 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
194
diff
changeset
|
310 } |
53bd9022c58b
Support of "OrthancPluginRegisterStorageArea2()" from Orthanc SDK 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
194
diff
changeset
|
311 |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
312 virtual bool IsSuccess() const ORTHANC_OVERRIDE |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
313 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
314 return success_; |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
315 } |
195
53bd9022c58b
Support of "OrthancPluginRegisterStorageArea2()" from Orthanc SDK 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
194
diff
changeset
|
316 |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
317 virtual void Assign(const std::string& content) ORTHANC_OVERRIDE |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
318 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
319 if (success_) |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
320 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
321 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
322 } |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
323 else |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
324 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
325 assert(context_ != NULL); |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
326 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
327 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
|
328 OrthancPluginErrorCode_Success) |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
329 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
330 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotEnoughMemory); |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
331 } |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
332 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
333 if (!content.empty()) |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
334 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
335 memcpy(target_->data, content.c_str(), content.size()); |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
336 } |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
337 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
338 success_ = true; |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
339 } |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
340 } |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
341 }; |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
342 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
343 |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
344 try |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
345 { |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
346 if (backend_.get() == NULL) |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
347 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
348 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
349 } |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
350 else |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
351 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
352 Visitor visitor(target); |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
353 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
354 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
355 std::unique_ptr<StorageBackend::IAccessor> accessor(backend_->CreateAccessor()); |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
356 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
|
357 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
358 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
359 return OrthancPluginErrorCode_Success; |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
360 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
361 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
362 ORTHANC_PLUGINS_DATABASE_CATCH; |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
363 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
364 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
365 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
366 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
|
367 const char* uuid, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
368 OrthancPluginContentType type, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
369 uint64_t start) |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
370 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
371 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
|
372 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
373 private: |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
374 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
|
375 bool success_; |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
376 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
377 public: |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
378 Visitor(OrthancPluginMemoryBuffer64* target) : |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
379 target_(target), |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
380 success_(false) |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
381 { |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
382 if (target == NULL) |
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 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
|
385 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
386 } |
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 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
|
389 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
390 return success_; |
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 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
393 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
|
394 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
395 if (success_) |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
396 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
397 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
|
398 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
399 else |
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 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
|
402 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
403 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
|
404 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
405 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
406 if (!content.empty()) |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
407 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
408 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
|
409 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
410 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
411 success_ = true; |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
412 } |
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 }; |
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 try |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
418 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
419 if (backend_.get() == NULL) |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
420 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
421 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
422 } |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
423 else |
194
a51ce147dbe0
refactoring using new class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
424 { |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
425 Visitor visitor(target); |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
426 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
427 { |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
428 std::unique_ptr<StorageBackend::IAccessor> accessor(backend_->CreateAccessor()); |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
429 accessor->ReadRange(visitor, uuid, type, start, target->size); |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
430 } |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
431 |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
432 return OrthancPluginErrorCode_Success; |
194
a51ce147dbe0
refactoring using new class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
433 } |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
434 } |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
435 ORTHANC_PLUGINS_DATABASE_CATCH; |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
436 } |
195
53bd9022c58b
Support of "OrthancPluginRegisterStorageArea2()" from Orthanc SDK 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
194
diff
changeset
|
437 #endif |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
438 |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
439 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
440 static OrthancPluginErrorCode StorageRead(void** data, |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
441 int64_t* size, |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
442 const char* uuid, |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
443 OrthancPluginContentType type) |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
444 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
445 class Visitor : public StorageBackend::IFileContentVisitor |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
446 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
447 private: |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
448 void** data_; |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
449 int64_t* size_; |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
450 bool success_; |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
451 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
452 public: |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
453 Visitor(void** data, |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
454 int64_t* size) : |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
455 data_(data), |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
456 size_(size), |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
457 success_(false) |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
458 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
459 } |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
460 |
252 | 461 ~Visitor() |
462 { | |
463 if (data_ != NULL /* this condition is invalidated by "Release()" */ && | |
464 *data_ != NULL) | |
465 { | |
466 free(*data_); | |
467 } | |
468 } | |
469 | |
470 void Release() | |
471 { | |
472 data_ = NULL; | |
473 } | |
474 | |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
475 virtual bool IsSuccess() const ORTHANC_OVERRIDE |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
476 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
477 return success_; |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
478 } |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
479 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
480 virtual void Assign(const std::string& content) ORTHANC_OVERRIDE |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
481 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
482 if (success_) |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
483 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
484 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
485 } |
252 | 486 else if (data_ == NULL) |
487 { | |
488 // "Release()" has been called | |
489 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
490 } | |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
491 else |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
492 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
493 if (content.empty()) |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
494 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
495 *data_ = NULL; |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
496 *size_ = 0; |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
497 } |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
498 else |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
499 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
500 *size_ = static_cast<int64_t>(content.size()); |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
501 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
502 if (static_cast<size_t>(*size_) != content.size()) |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
503 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
504 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotEnoughMemory, |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
505 "File cannot be stored in a 63bit buffer"); |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
506 } |
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 *data_ = malloc(*size_); |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
509 if (*data_ == NULL) |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
510 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
511 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotEnoughMemory); |
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 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
514 memcpy(*data_, content.c_str(), *size_); |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
515 } |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
516 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
517 success_ = true; |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
518 } |
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 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
522 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
523 try |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
524 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
525 if (backend_.get() == NULL) |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
526 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
527 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
528 } |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
529 else if (data == NULL || |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
530 size == NULL) |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
531 { |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
532 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
533 } |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
534 else |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
535 { |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
536 Visitor visitor(data, size); |
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 { |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
539 std::unique_ptr<StorageBackend::IAccessor> accessor(backend_->CreateAccessor()); |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
540 accessor->ReadWhole(visitor, uuid, type); |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
541 } |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
542 |
252 | 543 visitor.Release(); |
544 | |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
545 return OrthancPluginErrorCode_Success; |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
546 } |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
547 } |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
548 ORTHANC_PLUGINS_DATABASE_CATCH; |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
549 } |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
550 |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
551 |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
552 static OrthancPluginErrorCode StorageRemove(const char* uuid, |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
553 OrthancPluginContentType type) |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
554 { |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
555 try |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
556 { |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
557 if (backend_.get() == NULL) |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
558 { |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
559 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
560 } |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
561 else |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
562 { |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
563 std::unique_ptr<StorageBackend::IAccessor> accessor(backend_->CreateAccessor()); |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
564 accessor->Remove(uuid, type); |
230
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
565 return OrthancPluginErrorCode_Success; |
675f8322eb7c
refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
566 } |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
567 } |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
568 ORTHANC_PLUGINS_DATABASE_CATCH; |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
569 } |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
570 |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
571 |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
572 void StorageBackend::Register(OrthancPluginContext* context, |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
573 StorageBackend* backend) |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
574 { |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
575 if (context == NULL || |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
576 backend == NULL) |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
577 { |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
578 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
579 } |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
580 |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
581 if (context_ != NULL || |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
582 backend_.get() != NULL) |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
583 { |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
584 // This function can only be invoked once in the plugin |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
585 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
586 } |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
587 else |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
588 { |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
589 context_ = context; |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
590 backend_.reset(backend); |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
591 |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
592 bool hasLoadedV2 = false; |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
593 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
594 #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
|
595 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 9, 0) |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
596 if (OrthancPluginCheckVersionAdvanced(context, 1, 9, 0) == 1) |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
597 { |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
598 OrthancPluginStorageReadRange readRange = NULL; |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
599 if (backend_->HasReadRange()) |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
600 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
601 readRange = StorageReadRange; |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
602 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
603 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
604 OrthancPluginRegisterStorageArea2(context_, StorageCreate, StorageReadWhole, readRange, StorageRemove); |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
605 hasLoadedV2 = true; |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
606 } |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
607 # endif |
195
53bd9022c58b
Support of "OrthancPluginRegisterStorageArea2()" from Orthanc SDK 1.9.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
194
diff
changeset
|
608 #endif |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
609 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
610 if (!hasLoadedV2) |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
611 { |
249
7f5ee2b42a86
better performance warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
246
diff
changeset
|
612 LOG(WARNING) << "Performance warning: Your version of the Orthanc SDK doesn't support reading of file ranges"; |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
613 OrthancPluginRegisterStorageArea(context_, StorageCreate, StorageRead, StorageRemove); |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
614 } |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
615 } |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
616 } |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
617 |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
618 |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
619 void StorageBackend::Finalize() |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
620 { |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
621 backend_.reset(NULL); |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
622 context_ = NULL; |
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
623 } |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
624 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
625 |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
626 class StorageBackend::StringVisitor : public StorageBackend::IFileContentVisitor |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
627 { |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
628 private: |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
629 std::string& target_; |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
630 bool success_; |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
631 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
632 public: |
252 | 633 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
|
634 target_(target), |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
635 success_(false) |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
636 { |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
637 } |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
638 |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
639 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
|
640 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
641 return success_; |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
642 } |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
643 |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
644 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
|
645 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
646 if (success_) |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
647 { |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
648 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
649 } |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
650 else |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
651 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
652 target_.assign(content); |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
653 success_ = true; |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
654 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
655 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
656 }; |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
657 |
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
658 |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
659 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
|
660 IAccessor& accessor, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
661 const std::string& uuid, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
662 OrthancPluginContentType type) |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
663 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
664 StringVisitor visitor(target); |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
665 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
|
666 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
667 if (!visitor.IsSuccess()) |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
668 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
669 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
|
670 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
671 } |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
672 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
673 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
674 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
|
675 IAccessor& accessor, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
676 const std::string& uuid, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
677 OrthancPluginContentType type, |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
678 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
|
679 size_t length) |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
680 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
681 StringVisitor visitor(target); |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
682 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
|
683 |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
684 if (!visitor.IsSuccess()) |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
685 { |
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
686 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
|
687 } |
219
dd6cfc250747
removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
688 } |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
689 } |