comparison OrthancServer/Sources/ServerToolbox.cpp @ 4591:ff8170d17d90 db-changes

moving all accesses to databases from IDatabaseWrapper to ITransaction
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 15 Mar 2021 15:30:42 +0100
parents 7b99e8bb8246
children 95ffe3b6ef7c
comparison
equal deleted inserted replaced
4590:4a0bf1019335 4591:ff8170d17d90
163 163
164 164
165 namespace ServerToolbox 165 namespace ServerToolbox
166 { 166 {
167 bool FindOneChildInstance(int64_t& result, 167 bool FindOneChildInstance(int64_t& result,
168 IDatabaseWrapper& database, 168 IDatabaseWrapper::ITransaction& transaction,
169 int64_t resource, 169 int64_t resource,
170 ResourceType type) 170 ResourceType type)
171 { 171 {
172 for (;;) 172 for (;;)
173 { 173 {
176 result = resource; 176 result = resource;
177 return true; 177 return true;
178 } 178 }
179 179
180 std::list<int64_t> children; 180 std::list<int64_t> children;
181 database.GetChildrenInternalId(children, resource); 181 transaction.GetChildrenInternalId(children, resource);
182 if (children.empty()) 182 if (children.empty())
183 { 183 {
184 return false; 184 return false;
185 } 185 }
186 186
188 type = GetChildResourceType(type); 188 type = GetChildResourceType(type);
189 } 189 }
190 } 190 }
191 191
192 192
193 void ReconstructMainDicomTags(IDatabaseWrapper& database, 193 void ReconstructMainDicomTags(IDatabaseWrapper::ITransaction& transaction,
194 IStorageArea& storageArea, 194 IStorageArea& storageArea,
195 ResourceType level) 195 ResourceType level)
196 { 196 {
197 // WARNING: The database should be locked with a transaction! 197 // WARNING: The database should be locked with a transaction!
198 198
228 } 228 }
229 229
230 LOG(WARNING) << "Upgrade: Reconstructing the main DICOM tags of all the " << plural << "..."; 230 LOG(WARNING) << "Upgrade: Reconstructing the main DICOM tags of all the " << plural << "...";
231 231
232 std::list<std::string> resources; 232 std::list<std::string> resources;
233 database.GetAllPublicIds(resources, level); 233 transaction.GetAllPublicIds(resources, level);
234 234
235 for (std::list<std::string>::const_iterator 235 for (std::list<std::string>::const_iterator
236 it = resources.begin(); it != resources.end(); ++it) 236 it = resources.begin(); it != resources.end(); ++it)
237 { 237 {
238 // Locate the resource and one of its child instances 238 // Locate the resource and one of its child instances
239 int64_t resource, instance; 239 int64_t resource, instance;
240 ResourceType tmp; 240 ResourceType tmp;
241 241
242 if (!database.LookupResource(resource, tmp, *it) || 242 if (!transaction.LookupResource(resource, tmp, *it) ||
243 tmp != level || 243 tmp != level ||
244 !FindOneChildInstance(instance, database, resource, level)) 244 !FindOneChildInstance(instance, transaction, resource, level))
245 { 245 {
246 throw OrthancException(ErrorCode_InternalError, 246 throw OrthancException(ErrorCode_InternalError,
247 "Cannot find an instance for " + 247 "Cannot find an instance for " +
248 std::string(EnumerationToString(level)) + 248 std::string(EnumerationToString(level)) +
249 " with identifier " + *it); 249 " with identifier " + *it);
250 } 250 }
251 251
252 // Get the DICOM file attached to some instances in the resource 252 // Get the DICOM file attached to some instances in the resource
253 FileInfo attachment; 253 FileInfo attachment;
254 if (!database.LookupAttachment(attachment, instance, FileContentType_Dicom)) 254 if (!transaction.LookupAttachment(attachment, instance, FileContentType_Dicom))
255 { 255 {
256 throw OrthancException(ErrorCode_InternalError, 256 throw OrthancException(ErrorCode_InternalError,
257 "Cannot retrieve the DICOM file associated with instance " + 257 "Cannot retrieve the DICOM file associated with instance " +
258 database.GetPublicId(instance)); 258 transaction.GetPublicId(instance));
259 } 259 }
260 260
261 try 261 try
262 { 262 {
263 // Read and parse the content of the DICOM file 263 // Read and parse the content of the DICOM file
270 270
271 // Update the tags of this resource 271 // Update the tags of this resource
272 DicomMap dicomSummary; 272 DicomMap dicomSummary;
273 OrthancConfiguration::DefaultExtractDicomSummary(dicomSummary, dicom); 273 OrthancConfiguration::DefaultExtractDicomSummary(dicomSummary, dicom);
274 274
275 database.ClearMainDicomTags(resource); 275 transaction.ClearMainDicomTags(resource);
276 276
277 ResourcesContent tags; 277 ResourcesContent tags;
278 tags.AddResource(resource, level, dicomSummary); 278 tags.AddResource(resource, level, dicomSummary);
279 database.SetResourcesContent(tags); 279 transaction.SetResourcesContent(tags);
280 } 280 }
281 catch (OrthancException&) 281 catch (OrthancException&)
282 { 282 {
283 LOG(ERROR) << "Cannot decode the DICOM file with UUID " << attachment.GetUuid() 283 LOG(ERROR) << "Cannot decode the DICOM file with UUID " << attachment.GetUuid()
284 << " associated with instance " << database.GetPublicId(instance); 284 << " associated with instance " << transaction.GetPublicId(instance);
285 throw; 285 throw;
286 } 286 }
287 } 287 }
288 } 288 }
289 289