Mercurial > hg > orthanc-databases
changeset 586:3b1070dcab2f find-refactoring
fix
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Mon, 04 Nov 2024 22:52:58 +0100 |
parents | 65e39e76c2b6 |
children | 9b93aa085073 |
files | Framework/Plugins/IndexUnitTests.h MySQL/Plugins/IndexPlugin.cpp MySQL/Plugins/MySQLIndex.cpp MySQL/Plugins/MySQLIndex.h MySQL/UnitTests/UnitTestsMain.cpp Odbc/Plugins/IndexPlugin.cpp Odbc/Plugins/OdbcIndex.cpp Odbc/Plugins/OdbcIndex.h |
diffstat | 8 files changed, 33 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/Plugins/IndexUnitTests.h Mon Nov 04 18:38:32 2024 +0100 +++ b/Framework/Plugins/IndexUnitTests.h Mon Nov 04 22:52:58 2024 +0100 @@ -230,13 +230,13 @@ ImplicitTransaction::SetErrorOnDoubleExecution(true); #if ORTHANC_ENABLE_POSTGRESQL == 1 - PostgreSQLIndex db(&context, globalParameters_); + PostgreSQLIndex db(&context, globalParameters_, false); db.SetClearAll(true); #elif ORTHANC_ENABLE_MYSQL == 1 - MySQLIndex db(&context, globalParameters_); + MySQLIndex db(&context, globalParameters_, false); db.SetClearAll(true); #elif ORTHANC_ENABLE_ODBC == 1 - OdbcIndex db(&context, connectionString_); + OdbcIndex db(&context, connectionString_, false); #elif ORTHANC_ENABLE_SQLITE == 1 // Must be the last one SQLiteIndex db(&context); // Open in memory #else
--- a/MySQL/Plugins/IndexPlugin.cpp Mon Nov 04 18:38:32 2024 +0100 +++ b/MySQL/Plugins/IndexPlugin.cpp Mon Nov 04 22:52:58 2024 +0100 @@ -67,13 +67,20 @@ return 0; } + bool readOnly = configuration.GetBooleanValue("ReadOnly", false); + + if (readOnly) + { + LOG(WARNING) << "READ-ONLY SYSTEM: the Database plugin is working in read-only mode"; + } + try { const size_t countConnections = mysql.GetUnsignedIntegerValue("IndexConnectionsCount", 1); OrthancDatabases::MySQLParameters parameters(mysql, configuration); OrthancDatabases::IndexBackend::Register( - new OrthancDatabases::MySQLIndex(context, parameters), countConnections, + new OrthancDatabases::MySQLIndex(context, parameters, readOnly), countConnections, parameters.GetMaxConnectionRetries()); } catch (Orthanc::OrthancException& e)
--- a/MySQL/Plugins/MySQLIndex.cpp Mon Nov 04 18:38:32 2024 +0100 +++ b/MySQL/Plugins/MySQLIndex.cpp Mon Nov 04 22:52:58 2024 +0100 @@ -39,8 +39,9 @@ namespace OrthancDatabases { MySQLIndex::MySQLIndex(OrthancPluginContext* context, - const MySQLParameters& parameters) : - IndexBackend(context), + const MySQLParameters& parameters, + bool readOnly) : + IndexBackend(context, readOnly), parameters_(parameters), clearAll_(false) {
--- a/MySQL/Plugins/MySQLIndex.h Mon Nov 04 18:38:32 2024 +0100 +++ b/MySQL/Plugins/MySQLIndex.h Mon Nov 04 22:52:58 2024 +0100 @@ -36,7 +36,8 @@ public: MySQLIndex(OrthancPluginContext* context, - const MySQLParameters& parameters); + const MySQLParameters& parameters, + bool readOnly); void SetClearAll(bool clear) {
--- a/MySQL/UnitTests/UnitTestsMain.cpp Mon Nov 04 18:38:32 2024 +0100 +++ b/MySQL/UnitTests/UnitTestsMain.cpp Mon Nov 04 22:52:58 2024 +0100 @@ -49,7 +49,7 @@ OrthancDatabases::MySQLParameters lock = globalParameters_; lock.SetLock(true); - OrthancDatabases::MySQLIndex db1(NULL, noLock); + OrthancDatabases::MySQLIndex db1(NULL, noLock, false); db1.SetClearAll(true); std::list<OrthancDatabases::IdentifierTag> identifierTags; @@ -57,15 +57,15 @@ std::unique_ptr<OrthancDatabases::DatabaseManager> manager1(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db1, false, identifierTags)); { - OrthancDatabases::MySQLIndex db2(NULL, lock); + OrthancDatabases::MySQLIndex db2(NULL, lock, false); std::unique_ptr<OrthancDatabases::DatabaseManager> manager2(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db2, false, identifierTags)); - OrthancDatabases::MySQLIndex db3(NULL, lock); + OrthancDatabases::MySQLIndex db3(NULL, lock, false); ASSERT_THROW(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db3, false, identifierTags), Orthanc::OrthancException); } - OrthancDatabases::MySQLIndex db4(NULL, lock); + OrthancDatabases::MySQLIndex db4(NULL, lock, false); std::unique_ptr<OrthancDatabases::DatabaseManager> manager4(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db4, false, identifierTags)); }
--- a/Odbc/Plugins/IndexPlugin.cpp Mon Nov 04 18:38:32 2024 +0100 +++ b/Odbc/Plugins/IndexPlugin.cpp Mon Nov 04 22:52:58 2024 +0100 @@ -113,7 +113,14 @@ "No connection string provided for the ODBC index"); } - std::unique_ptr<OrthancDatabases::OdbcIndex> index(new OrthancDatabases::OdbcIndex(context, connectionString)); + bool readOnly = configuration.GetBooleanValue("ReadOnly", false); + + if (readOnly) + { + LOG(WARNING) << "READ-ONLY SYSTEM: the Database plugin is working in read-only mode"; + } + + std::unique_ptr<OrthancDatabases::OdbcIndex> index(new OrthancDatabases::OdbcIndex(context, connectionString, readOnly)); index->SetMaxConnectionRetries(maxConnectionRetries); index->SetConnectionRetryInterval(connectionRetryInterval);
--- a/Odbc/Plugins/OdbcIndex.cpp Mon Nov 04 18:38:32 2024 +0100 +++ b/Odbc/Plugins/OdbcIndex.cpp Mon Nov 04 22:52:58 2024 +0100 @@ -135,8 +135,9 @@ OdbcIndex::OdbcIndex(OrthancPluginContext* context, - const std::string& connectionString) : - IndexBackend(context), + const std::string& connectionString, + bool readOnly) : + IndexBackend(context, readOnly), maxConnectionRetries_(10), connectionRetryInterval_(5), connectionString_(connectionString)
--- a/Odbc/Plugins/OdbcIndex.h Mon Nov 04 18:38:32 2024 +0100 +++ b/Odbc/Plugins/OdbcIndex.h Mon Nov 04 22:52:58 2024 +0100 @@ -36,7 +36,8 @@ public: OdbcIndex(OrthancPluginContext* context, - const std::string& connectionString); + const std::string& connectionString, + bool readOnly); unsigned int GetMaxConnectionRetries() const {