comparison Framework/Plugins/IndexBackend.cpp @ 203:2089d4071408

moving classes out of OrthancPlugins namespace, to OrthancDatabases
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 18 Mar 2021 18:15:34 +0100
parents 42990b2dd51b
children 13a3863df7fa
comparison
equal deleted inserted replaced
202:2def2df94f94 203:2089d4071408
169 } 169 }
170 } 170 }
171 } 171 }
172 172
173 173
174 void IndexBackend::ReadChangesInternal(OrthancPlugins::IDatabaseBackendOutput& output, 174 void IndexBackend::ReadChangesInternal(IDatabaseBackendOutput& output,
175 bool& done, 175 bool& done,
176 DatabaseManager::CachedStatement& statement, 176 DatabaseManager::CachedStatement& statement,
177 const Dictionary& args, 177 const Dictionary& args,
178 uint32_t maxResults) 178 uint32_t maxResults)
179 { 179 {
198 done = (count < maxResults || 198 done = (count < maxResults ||
199 statement.IsDone()); 199 statement.IsDone());
200 } 200 }
201 201
202 202
203 void IndexBackend::ReadExportedResourcesInternal(OrthancPlugins::IDatabaseBackendOutput& output, 203 void IndexBackend::ReadExportedResourcesInternal(IDatabaseBackendOutput& output,
204 bool& done, 204 bool& done,
205 DatabaseManager::CachedStatement& statement, 205 DatabaseManager::CachedStatement& statement,
206 const Dictionary& args, 206 const Dictionary& args,
207 uint32_t maxResults) 207 uint32_t maxResults)
208 { 208 {
255 255
256 statement.Execute(); 256 statement.Execute();
257 } 257 }
258 258
259 259
260 void IndexBackend::SignalDeletedFiles(OrthancPlugins::IDatabaseBackendOutput& output) 260 void IndexBackend::SignalDeletedFiles(IDatabaseBackendOutput& output)
261 { 261 {
262 DatabaseManager::CachedStatement statement( 262 DatabaseManager::CachedStatement statement(
263 STATEMENT_FROM_HERE, manager_, 263 STATEMENT_FROM_HERE, manager_,
264 "SELECT * FROM DeletedFiles"); 264 "SELECT * FROM DeletedFiles");
265 265
283 statement.Next(); 283 statement.Next();
284 } 284 }
285 } 285 }
286 286
287 287
288 void IndexBackend::SignalDeletedResources(OrthancPlugins::IDatabaseBackendOutput& output) 288 void IndexBackend::SignalDeletedResources(IDatabaseBackendOutput& output)
289 { 289 {
290 DatabaseManager::CachedStatement statement( 290 DatabaseManager::CachedStatement statement(
291 STATEMENT_FROM_HERE, manager_, 291 STATEMENT_FROM_HERE, manager_,
292 "SELECT * FROM DeletedResources"); 292 "SELECT * FROM DeletedResources");
293 293
311 manager_(factory) 311 manager_(factory)
312 { 312 {
313 } 313 }
314 314
315 315
316 void IndexBackend::SetOutputFactory(OrthancPlugins::IDatabaseBackendOutput::IFactory* factory) 316 void IndexBackend::SetOutputFactory(IDatabaseBackendOutput::IFactory* factory)
317 { 317 {
318 if (factory == NULL) 318 if (factory == NULL)
319 { 319 {
320 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); 320 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
321 } 321 }
328 outputFactory_.reset(factory); 328 outputFactory_.reset(factory);
329 } 329 }
330 } 330 }
331 331
332 332
333 OrthancPlugins::IDatabaseBackendOutput* IndexBackend::CreateOutput() 333 IDatabaseBackendOutput* IndexBackend::CreateOutput()
334 { 334 {
335 if (outputFactory_.get() == NULL) 335 if (outputFactory_.get() == NULL)
336 { 336 {
337 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); 337 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
338 } 338 }
410 410
411 statement.Execute(); 411 statement.Execute();
412 } 412 }
413 413
414 414
415 void IndexBackend::DeleteAttachment(OrthancPlugins::IDatabaseBackendOutput& output, 415 void IndexBackend::DeleteAttachment(IDatabaseBackendOutput& output,
416 int64_t id, 416 int64_t id,
417 int32_t attachment) 417 int32_t attachment)
418 { 418 {
419 ClearDeletedFiles(); 419 ClearDeletedFiles();
420 420
453 453
454 statement.Execute(args); 454 statement.Execute(args);
455 } 455 }
456 456
457 457
458 void IndexBackend::DeleteResource(OrthancPlugins::IDatabaseBackendOutput& output, 458 void IndexBackend::DeleteResource(IDatabaseBackendOutput& output,
459 int64_t id) 459 int64_t id)
460 { 460 {
461 assert(manager_.GetDialect() != Dialect_MySQL); 461 assert(manager_.GetDialect() != Dialect_MySQL);
462 462
463 ClearDeletedFiles(); 463 ClearDeletedFiles();
566 ReadListOfStrings(target, statement, args); 566 ReadListOfStrings(target, statement, args);
567 } 567 }
568 568
569 569
570 /* Use GetOutput().AnswerChange() */ 570 /* Use GetOutput().AnswerChange() */
571 void IndexBackend::GetChanges(OrthancPlugins::IDatabaseBackendOutput& output, 571 void IndexBackend::GetChanges(IDatabaseBackendOutput& output,
572 bool& done /*out*/, 572 bool& done /*out*/,
573 int64_t since, 573 int64_t since,
574 uint32_t maxResults) 574 uint32_t maxResults)
575 { 575 {
576 DatabaseManager::CachedStatement statement( 576 DatabaseManager::CachedStatement statement(
624 ReadListOfStrings(target, statement, args); 624 ReadListOfStrings(target, statement, args);
625 } 625 }
626 626
627 627
628 /* Use GetOutput().AnswerExportedResource() */ 628 /* Use GetOutput().AnswerExportedResource() */
629 void IndexBackend::GetExportedResources(OrthancPlugins::IDatabaseBackendOutput& output, 629 void IndexBackend::GetExportedResources(IDatabaseBackendOutput& output,
630 bool& done /*out*/, 630 bool& done /*out*/,
631 int64_t since, 631 int64_t since,
632 uint32_t maxResults) 632 uint32_t maxResults)
633 { 633 {
634 DatabaseManager::CachedStatement statement( 634 DatabaseManager::CachedStatement statement(
646 ReadExportedResourcesInternal(output, done, statement, args, maxResults); 646 ReadExportedResourcesInternal(output, done, statement, args, maxResults);
647 } 647 }
648 648
649 649
650 /* Use GetOutput().AnswerChange() */ 650 /* Use GetOutput().AnswerChange() */
651 void IndexBackend::GetLastChange(OrthancPlugins::IDatabaseBackendOutput& output) 651 void IndexBackend::GetLastChange(IDatabaseBackendOutput& output)
652 { 652 {
653 DatabaseManager::CachedStatement statement( 653 DatabaseManager::CachedStatement statement(
654 STATEMENT_FROM_HERE, manager_, 654 STATEMENT_FROM_HERE, manager_,
655 "SELECT * FROM Changes ORDER BY seq DESC LIMIT 1"); 655 "SELECT * FROM Changes ORDER BY seq DESC LIMIT 1");
656 656
662 ReadChangesInternal(output, done, statement, args, 1); 662 ReadChangesInternal(output, done, statement, args, 1);
663 } 663 }
664 664
665 665
666 /* Use GetOutput().AnswerExportedResource() */ 666 /* Use GetOutput().AnswerExportedResource() */
667 void IndexBackend::GetLastExportedResource(OrthancPlugins::IDatabaseBackendOutput& output) 667 void IndexBackend::GetLastExportedResource(IDatabaseBackendOutput& output)
668 { 668 {
669 DatabaseManager::CachedStatement statement( 669 DatabaseManager::CachedStatement statement(
670 STATEMENT_FROM_HERE, manager_, 670 STATEMENT_FROM_HERE, manager_,
671 "SELECT * FROM ExportedResources ORDER BY seq DESC LIMIT 1"); 671 "SELECT * FROM ExportedResources ORDER BY seq DESC LIMIT 1");
672 672
678 ReadExportedResourcesInternal(output, done, statement, args, 1); 678 ReadExportedResourcesInternal(output, done, statement, args, 1);
679 } 679 }
680 680
681 681
682 /* Use GetOutput().AnswerDicomTag() */ 682 /* Use GetOutput().AnswerDicomTag() */
683 void IndexBackend::GetMainDicomTags(OrthancPlugins::IDatabaseBackendOutput& output, 683 void IndexBackend::GetMainDicomTags(IDatabaseBackendOutput& output,
684 int64_t id) 684 int64_t id)
685 { 685 {
686 DatabaseManager::CachedStatement statement( 686 DatabaseManager::CachedStatement statement(
687 STATEMENT_FROM_HERE, manager_, 687 STATEMENT_FROM_HERE, manager_,
688 "SELECT * FROM MainDicomTags WHERE id=${id}"); 688 "SELECT * FROM MainDicomTags WHERE id=${id}");
997 statement.Execute(args); 997 statement.Execute(args);
998 } 998 }
999 999
1000 1000
1001 /* Use GetOutput().AnswerAttachment() */ 1001 /* Use GetOutput().AnswerAttachment() */
1002 bool IndexBackend::LookupAttachment(OrthancPlugins::IDatabaseBackendOutput& output, 1002 bool IndexBackend::LookupAttachment(IDatabaseBackendOutput& output,
1003 int64_t id, 1003 int64_t id,
1004 int32_t contentType) 1004 int32_t contentType)
1005 { 1005 {
1006 DatabaseManager::CachedStatement statement( 1006 DatabaseManager::CachedStatement statement(
1007 STATEMENT_FROM_HERE, manager_, 1007 STATEMENT_FROM_HERE, manager_,
1691 #endif 1691 #endif
1692 1692
1693 1693
1694 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 1694 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
1695 // New primitive since Orthanc 1.5.2 1695 // New primitive since Orthanc 1.5.2
1696 void IndexBackend::LookupResources(OrthancPlugins::IDatabaseBackendOutput& output, 1696 void IndexBackend::LookupResources(IDatabaseBackendOutput& output,
1697 const std::vector<Orthanc::DatabaseConstraint>& lookup, 1697 const std::vector<Orthanc::DatabaseConstraint>& lookup,
1698 OrthancPluginResourceType queryLevel, 1698 OrthancPluginResourceType queryLevel,
1699 uint32_t limit, 1699 uint32_t limit,
1700 bool requestSomeInstance) 1700 bool requestSomeInstance)
1701 { 1701 {
1995 1995
1996 1996
1997 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in 1.3.1 1997 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in 1.3.1
1998 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 4) 1998 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 4)
1999 // New primitive since Orthanc 1.5.4 1999 // New primitive since Orthanc 1.5.4
2000 bool IndexBackend::LookupResourceAndParent(int64_t& id, 2000 bool IndexBackend::LookupResourceAndParent(int64_t& id,
2001 OrthancPluginResourceType& type, 2001 OrthancPluginResourceType& type,
2002 std::string& parentPublicId, 2002 std::string& parentPublicId,
2003 const char* publicId) 2003 const char* publicId)
2004 { 2004 {
2005 DatabaseManager::CachedStatement statement( 2005 DatabaseManager::CachedStatement statement(
2006 STATEMENT_FROM_HERE, manager_, 2006 STATEMENT_FROM_HERE, manager_,
2007 "SELECT resource.internalId, resource.resourceType, parent.publicId " 2007 "SELECT resource.internalId, resource.resourceType, parent.publicId "
2008 "FROM Resources AS resource LEFT JOIN Resources parent ON parent.internalId=resource.parentId " 2008 "FROM Resources AS resource LEFT JOIN Resources parent ON parent.internalId=resource.parentId "
2009 "WHERE resource.publicId=${id}"); 2009 "WHERE resource.publicId=${id}");
2010 2010
2011 statement.SetParameterType("id", ValueType_Utf8String); 2011 statement.SetParameterType("id", ValueType_Utf8String);
2012 2012
2013 Dictionary args; 2013 Dictionary args;
2014 args.SetUtf8Value("id", publicId); 2014 args.SetUtf8Value("id", publicId);
2015 2015
2016 statement.Execute(args); 2016 statement.Execute(args);
2017 2017
2018 if (statement.IsDone()) 2018 if (statement.IsDone())
2019 { 2019 {
2020 return false; 2020 return false;
2021 } 2021 }
2022 else 2022 else
2023 { 2023 {
2024 if (statement.GetResultFieldsCount() != 3) 2024 if (statement.GetResultFieldsCount() != 3)
2025 { 2025 {
2026 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
2027 }
2028
2029 statement.SetResultFieldType(0, ValueType_Integer64);
2030 statement.SetResultFieldType(1, ValueType_Integer64);
2031 statement.SetResultFieldType(2, ValueType_Utf8String);
2032
2033 id = ReadInteger64(statement, 0);
2034 type = static_cast<OrthancPluginResourceType>(ReadInteger32(statement, 1));
2035
2036 const IValue& value = statement.GetResultField(2);
2037
2038 switch (value.GetType())
2039 {
2040 case ValueType_Null:
2041 parentPublicId.clear();
2042 break;
2043
2044 case ValueType_Utf8String:
2045 parentPublicId = dynamic_cast<const Utf8StringValue&>(value).GetContent();
2046 break;
2047
2048 default:
2026 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); 2049 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
2027 } 2050 }
2028 2051
2029 statement.SetResultFieldType(0, ValueType_Integer64); 2052 assert((statement.Next(), statement.IsDone()));
2030 statement.SetResultFieldType(1, ValueType_Integer64); 2053 return true;
2031 statement.SetResultFieldType(2, ValueType_Utf8String); 2054 }
2032 2055 }
2033 id = ReadInteger64(statement, 0);
2034 type = static_cast<OrthancPluginResourceType>(ReadInteger32(statement, 1));
2035
2036 const IValue& value = statement.GetResultField(2);
2037
2038 switch (value.GetType())
2039 {
2040 case ValueType_Null:
2041 parentPublicId.clear();
2042 break;
2043
2044 case ValueType_Utf8String:
2045 parentPublicId = dynamic_cast<const Utf8StringValue&>(value).GetContent();
2046 break;
2047
2048 default:
2049 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
2050 }
2051
2052 assert((statement.Next(), statement.IsDone()));
2053 return true;
2054 }
2055 }
2056 # endif 2056 # endif
2057 #endif 2057 #endif
2058 2058
2059 2059
2060 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in 1.3.1 2060 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in 1.3.1