comparison MySQL/Plugins/MySQLIndex.cpp @ 569:f18e46d7dbf8 attach-custom-data

merged find-refactoring -> attach-custom-data
author Alain Mazy <am@orthanc.team>
date Tue, 24 Sep 2024 15:04:21 +0200
parents cd9521e04249 451125122692
children
comparison
equal deleted inserted replaced
368:82f73188b58d 569:f18e46d7dbf8
1 /** 1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store 2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium 4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium 5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
6 * 8 *
7 * This program is free software: you can redistribute it and/or 9 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License 10 * modify it under the terms of the GNU Affero General Public License
9 * as published by the Free Software Foundation, either version 3 of 11 * as published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version. 12 * the License, or (at your option) any later version.
60 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database, 62 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database,
61 "Need to fix the MySQL permissions for \"CREATE TRIGGER\""); 63 "Need to fix the MySQL permissions for \"CREATE TRIGGER\"");
62 } 64 }
63 65
64 66
65 void MySQLIndex::ConfigureDatabase(DatabaseManager& manager) 67 void MySQLIndex::ConfigureDatabase(DatabaseManager& manager,
68 bool hasIdentifierTags,
69 const std::list<IdentifierTag>& identifierTags)
66 { 70 {
67 uint32_t expectedVersion = 6; 71 uint32_t expectedVersion = 6;
68 72
69 if (GetContext()) // "GetContext()" can possibly be NULL in the unit tests 73 if (GetContext()) // "GetContext()" can possibly be NULL in the unit tests
70 { 74 {
232 236
233 // Reconfiguration of "Metadata" from TEXT type (up to 64KB) 237 // Reconfiguration of "Metadata" from TEXT type (up to 64KB)
234 // to the LONGTEXT type (up to 4GB). This might be important 238 // to the LONGTEXT type (up to 4GB). This might be important
235 // for applications such as the Osimis Web viewer that stores 239 // for applications such as the Osimis Web viewer that stores
236 // large amount of metadata. 240 // large amount of metadata.
237 // http://book.orthanc-server.com/faq/features.html#central-registry-of-metadata-and-attachments 241 // https://orthanc.uclouvain.be/book/faq/features.html#central-registry-of-metadata-and-attachments
238 t.GetDatabaseTransaction().ExecuteMultiLines("ALTER TABLE Metadata MODIFY value LONGTEXT"); 242 t.GetDatabaseTransaction().ExecuteMultiLines("ALTER TABLE Metadata MODIFY value LONGTEXT");
239 243
240 revision = 4; 244 revision = 4;
241 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision); 245 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision);
242 246
292 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision); 296 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision);
293 297
294 t.Commit(); 298 t.Commit();
295 } 299 }
296 300
297 if (revision == 6) 301 if (revision == 6)
302 {
303 // Added new table "Labels" since release 5.0 to deal with
304 // labels that were introduced in Orthanc 1.12.0
305 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite);
306
307 t.GetDatabaseTransaction().ExecuteMultiLines(
308 "CREATE TABLE Labels(id BIGINT NOT NULL,"
309 "label VARCHAR(64) NOT NULL,"
310 "PRIMARY KEY(id, label),"
311 "CONSTRAINT Labels1 FOREIGN KEY (id) REFERENCES Resources(internalId) ON DELETE CASCADE);"
312 "CREATE INDEX LabelsIndex1 ON Labels(id);"
313 "CREATE INDEX LabelsIndex2 ON Labels(label);");
314
315 revision = 7;
316 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision);
317
318 t.Commit();
319 }
320
321 if (revision == 7)
322 {
323 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite);
324
325 // Install the "CreateInstance" extension
326 std::string query;
327
328 Orthanc::EmbeddedResources::GetFileResource
329 (query, Orthanc::EmbeddedResources::MYSQL_DELETE_RESOURCES);
330
331 // Need to escape arobases: Don't use "t.GetDatabaseTransaction().ExecuteMultiLines()" here
332 db.ExecuteMultiLines(query, true);
333
334 revision = 8;
335 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision);
336
337 t.Commit();
338 }
339
340 if (revision == 8)
298 { 341 {
299 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite); 342 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite);
300 343
301 // Install revision and customData extension 344 // Install revision and customData extension
302 std::string query; 345 std::string query;
305 (query, Orthanc::EmbeddedResources::MYSQL_INSTALL_REVISION_AND_CUSTOM_DATA); 348 (query, Orthanc::EmbeddedResources::MYSQL_INSTALL_REVISION_AND_CUSTOM_DATA);
306 349
307 // Need to escape arobases: Don't use "t.GetDatabaseTransaction().ExecuteMultiLines()" here 350 // Need to escape arobases: Don't use "t.GetDatabaseTransaction().ExecuteMultiLines()" here
308 db.ExecuteMultiLines(query, true); 351 db.ExecuteMultiLines(query, true);
309 352
310 revision = 7; 353 revision = 9;
311 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision); 354 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision);
312 355
313 t.Commit(); 356 t.Commit();
314 } 357 }
315 358
316 if (revision != 7) 359 if (revision != 9)
317 { 360 {
318 LOG(ERROR) << "MySQL plugin is incompatible with database schema revision: " << revision; 361 LOG(ERROR) << "MySQL plugin is incompatible with database schema revision: " << revision;
319 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); 362 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database);
320 } 363 }
321 } 364 }
465 Dictionary args; 508 Dictionary args;
466 args.SetIntegerValue("id", id); 509 args.SetIntegerValue("id", id);
467 lookupResourcesToDelete.Execute(args); 510 lookupResourcesToDelete.Execute(args);
468 } 511 }
469 512
470 { 513 // {
471 DatabaseManager::CachedStatement deleteHierarchy( 514 // DatabaseManager::CachedStatement deleteHierarchy(
515 // STATEMENT_FROM_HERE, manager,
516 // "DELETE FROM Resources WHERE internalId IN (SELECT internalId FROM DeletedResources)");
517 // deleteHierarchy.Execute();
518 // }
519
520
521 {
522 DatabaseManager::CachedStatement deleteResources(
472 STATEMENT_FROM_HERE, manager, 523 STATEMENT_FROM_HERE, manager,
473 "DELETE FROM Resources WHERE internalId IN (SELECT internalId FROM DeletedResources)"); 524 "CALL DeleteResources(${id})");
474 deleteHierarchy.Execute(); 525
526 deleteResources.SetParameterType("id", ValueType_Integer64);
527
528 Dictionary args;
529 args.SetIntegerValue("id", id);
530
531 deleteResources.Execute(args);
475 } 532 }
476 533
477 SignalDeletedResources(output, manager); 534 SignalDeletedResources(output, manager);
478 SignalDeletedFiles(output, manager); 535 SignalDeletedFiles(output, manager);
479 } 536 }
552 result.seriesId = statement.ReadInteger64(6); 609 result.seriesId = statement.ReadInteger64(6);
553 } 610 }
554 } 611 }
555 } 612 }
556 #endif 613 #endif
614
615
616 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)
617 bool MySQLIndex::HasFindSupport() const
618 {
619 // TODO-FIND
620 return false;
621 }
622 #endif
623
624
625 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)
626 void MySQLIndex::ExecuteFind(Orthanc::DatabasePluginMessages::TransactionResponse& response,
627 DatabaseManager& manager,
628 const Orthanc::DatabasePluginMessages::Find_Request& request)
629 {
630 // TODO-FIND
631 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
632 }
633 #endif
557 } 634 }