Mercurial > hg > orthanc-databases
changeset 606:d4c373c74c0b find-refactoring
recovered build up to 1.9.2 SDK
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 16 Dec 2024 12:31:52 +0100 |
parents | 09fe1b384a20 |
children | 3d853c8f5a9e 46aff94cdcb6 |
files | Framework/Common/StatementId.cpp Framework/Plugins/IDatabaseBackend.h Framework/Plugins/ISqlLookupFormatter.cpp Framework/Plugins/IndexBackend.cpp Framework/Plugins/IndexBackend.h MySQL/Plugins/IndexPlugin.cpp Odbc/Plugins/IndexPlugin.cpp PostgreSQL/Plugins/IndexPlugin.cpp PostgreSQL/Plugins/PostgreSQLIndex.cpp SQLite/Plugins/IndexPlugin.cpp SQLite/Plugins/SQLiteIndex.h |
diffstat | 11 files changed, 86 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/Common/StatementId.cpp Mon Dec 16 11:39:00 2024 +0100 +++ b/Framework/Common/StatementId.cpp Mon Dec 16 12:31:52 2024 +0100 @@ -26,6 +26,8 @@ #include <string.h> #include <Toolbox.h> +#include <boost/lexical_cast.hpp> + namespace OrthancDatabases { bool StatementId::operator< (const StatementId& other) const
--- a/Framework/Plugins/IDatabaseBackend.h Mon Dec 16 11:39:00 2024 +0100 +++ b/Framework/Plugins/IDatabaseBackend.h Mon Dec 16 12:31:52 2024 +0100 @@ -398,11 +398,10 @@ virtual void ExecuteCount(Orthanc::DatabasePluginMessages::TransactionResponse& response, DatabaseManager& manager, const Orthanc::DatabasePluginMessages::Find_Request& request) = 0; +#endif virtual bool HasPerformDbHousekeeping() = 0; virtual void PerformDbHousekeeping(DatabaseManager& manager) = 0; - -#endif }; }
--- a/Framework/Plugins/ISqlLookupFormatter.cpp Mon Dec 16 11:39:00 2024 +0100 +++ b/Framework/Plugins/ISqlLookupFormatter.cpp Mon Dec 16 12:31:52 2024 +0100 @@ -35,8 +35,9 @@ #include <OrthancException.h> #include <Toolbox.h> +#include <boost/algorithm/string/join.hpp> +#include <boost/lexical_cast.hpp> #include <cassert> -#include <boost/lexical_cast.hpp> #include <list> @@ -64,6 +65,7 @@ } +#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5) static std::string FormatLevel(const char* prefix, Orthanc::ResourceType level) { switch (level) @@ -84,6 +86,8 @@ throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); } } +#endif + static bool FormatComparison(std::string& target, ISqlLookupFormatter& formatter, @@ -261,6 +265,7 @@ } +#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5) static bool FormatComparison(std::string& target, ISqlLookupFormatter& formatter, const Orthanc::DatabasePluginMessages::DatabaseMetadataConstraint& constraint, @@ -313,6 +318,8 @@ escapeBrackets); } +#endif + static bool FormatComparison(std::string& target, ISqlLookupFormatter& formatter, @@ -374,6 +381,8 @@ boost::lexical_cast<std::string>(constraint.GetTag().GetElement())); } + +#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5) static void FormatJoin(std::string& target, const Orthanc::DatabasePluginMessages::DatabaseMetadataConstraint& constraint, Orthanc::ResourceType level, @@ -396,7 +405,10 @@ ".internalId AND " + tag + ".type = " + boost::lexical_cast<std::string>(constraint.metadata()); } +#endif + +#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5) static void FormatJoinForOrdering(std::string& target, uint32_t tagGroup, uint32_t tagElement, @@ -450,7 +462,10 @@ " LEFT JOIN " + tagTable + " " + orderArg + " ON " + orderArg + ".id = " + orderArg + "grandgrandparent.internalId AND " + tagFilter; } } +#endif + +#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5) static void FormatJoinForOrdering(std::string& target, int32_t metadata, size_t index, @@ -462,6 +477,7 @@ ".internalId AND " + arg + ".type = " + boost::lexical_cast<std::string>(metadata); } +#endif static std::string Join(const std::list<std::string>& values, @@ -560,8 +576,7 @@ } } - std::string values; - Orthanc::Toolbox::JoinStrings(values, comparisonValues, ", "); + std::string values = boost::algorithm::join(comparisonValues, ", "); if (constraint.IsCaseSensitive()) { @@ -923,8 +938,7 @@ orderByFields.push_back(orderByField); } - std::string orderByFieldsString; - Orthanc::Toolbox::JoinStrings(orderByFieldsString, orderByFields, ", "); + std::string orderByFieldsString = boost::algorithm::join(orderByFields, ", "); if (formatter.SupportsNullsLast()) {
--- a/Framework/Plugins/IndexBackend.cpp Mon Dec 16 11:39:00 2024 +0100 +++ b/Framework/Plugins/IndexBackend.cpp Mon Dec 16 12:31:52 2024 +0100 @@ -36,6 +36,8 @@ #include <OrthancException.h> #include <Toolbox.h> +#include <boost/algorithm/string/join.hpp> + namespace OrthancDatabases { @@ -60,6 +62,8 @@ return s; } + +#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5) static std::string JoinChanges(const std::set<uint32_t>& changeTypes) { std::set<std::string> changeTypesString; @@ -73,7 +77,9 @@ return joinedChangesTypes; } - +#endif + + template <typename T> static void ReadListOfIntegers(std::list<T>& target, DatabaseManager::CachedStatement& statement, @@ -663,8 +669,7 @@ std::string filtersString; if (filters.size() > 0) { - Orthanc::Toolbox::JoinStrings(filtersString, filters, " AND "); - filtersString = "WHERE " + filtersString; + filtersString = "WHERE " + boost::algorithm::join(filters, " AND "); } std::string sql; @@ -1361,7 +1366,11 @@ bool IndexBackend::HasMeasureLatency() { +#if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 12, 2) return true; +#else + return false; +#endif } @@ -3075,6 +3084,7 @@ uint64_t IndexBackend::MeasureLatency(DatabaseManager& manager) { +#if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 12, 2) // execute 11x the simplest statement and return the median value std::vector<uint64_t> measures; @@ -3092,6 +3102,9 @@ std::sort(measures.begin(), measures.end()); return measures[measures.size() / 2]; +#else + throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); +#endif } @@ -4258,17 +4271,5 @@ statement->Next(); } } - - bool IndexBackend::HasPerformDbHousekeeping() - { - return false; - } - - void IndexBackend::PerformDbHousekeeping(DatabaseManager& manager) - { - throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); - } - #endif - }
--- a/Framework/Plugins/IndexBackend.h Mon Dec 16 11:39:00 2024 +0100 +++ b/Framework/Plugins/IndexBackend.h Mon Dec 16 12:31:52 2024 +0100 @@ -439,7 +439,7 @@ virtual uint64_t MeasureLatency(DatabaseManager& manager) ORTHANC_OVERRIDE; #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5) - // New primitive since Orthanc 1.12.5 + // New primitives since Orthanc 1.12.5 virtual bool HasExtendedChanges() const ORTHANC_OVERRIDE { return true; @@ -454,12 +454,17 @@ virtual void ExecuteCount(Orthanc::DatabasePluginMessages::TransactionResponse& response, DatabaseManager& manager, const Orthanc::DatabasePluginMessages::Find_Request& request) ORTHANC_OVERRIDE; - - virtual bool HasPerformDbHousekeeping() ORTHANC_OVERRIDE; - - virtual void PerformDbHousekeeping(DatabaseManager& manager) ORTHANC_OVERRIDE; #endif + virtual bool HasPerformDbHousekeeping() ORTHANC_OVERRIDE + { + return false; + } + + virtual void PerformDbHousekeeping(DatabaseManager& manager) ORTHANC_OVERRIDE + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); + } /** * "maxDatabaseRetries" is to handle
--- a/MySQL/Plugins/IndexPlugin.cpp Mon Dec 16 11:39:00 2024 +0100 +++ b/MySQL/Plugins/IndexPlugin.cpp Mon Dec 16 12:31:52 2024 +0100 @@ -29,7 +29,9 @@ #include <Logging.h> #include <Toolbox.h> -#include <google/protobuf/any.h> +#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 0) +# include <google/protobuf/any.h> +#endif #define ORTHANC_PLUGIN_NAME "mysql-index" @@ -37,7 +39,9 @@ { ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) { +#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 0) GOOGLE_PROTOBUF_VERIFY_VERSION; +#endif if (!OrthancDatabases::InitializePlugin(context, ORTHANC_PLUGIN_NAME, "MySQL", true)) { @@ -107,7 +111,10 @@ OrthancDatabases::MySQLDatabase::GlobalFinalization(); Orthanc::HttpClient::GlobalFinalize(); Orthanc::Toolbox::FinalizeOpenSsl(); + +#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 0) google::protobuf::ShutdownProtobufLibrary(); +#endif }
--- a/Odbc/Plugins/IndexPlugin.cpp Mon Dec 16 11:39:00 2024 +0100 +++ b/Odbc/Plugins/IndexPlugin.cpp Mon Dec 16 12:31:52 2024 +0100 @@ -45,7 +45,9 @@ #endif -#include <google/protobuf/any.h> +#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 0) +# include <google/protobuf/any.h> +#endif static const char* const KEY_ODBC = "Odbc"; @@ -60,7 +62,9 @@ ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) { +#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 0) GOOGLE_PROTOBUF_VERIFY_VERSION; +#endif if (!OrthancDatabases::InitializePlugin(context, ORTHANC_PLUGIN_NAME, "ODBC", true)) { @@ -146,7 +150,10 @@ { LOG(WARNING) << "ODBC index is finalizing"; OrthancDatabases::IndexBackend::Finalize(); + +#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 0) google::protobuf::ShutdownProtobufLibrary(); +#endif }
--- a/PostgreSQL/Plugins/IndexPlugin.cpp Mon Dec 16 11:39:00 2024 +0100 +++ b/PostgreSQL/Plugins/IndexPlugin.cpp Mon Dec 16 12:31:52 2024 +0100 @@ -27,7 +27,9 @@ #include <Logging.h> #include <Toolbox.h> -#include <google/protobuf/any.h> +#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 0) +# include <google/protobuf/any.h> +#endif #define ORTHANC_PLUGIN_NAME "postgresql-index" @@ -36,7 +38,9 @@ { ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) { +#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 0) GOOGLE_PROTOBUF_VERIFY_VERSION; +#endif if (!OrthancDatabases::InitializePlugin(context, ORTHANC_PLUGIN_NAME, "PostgreSQL", true)) { @@ -102,7 +106,10 @@ LOG(WARNING) << "PostgreSQL index is finalizing"; OrthancDatabases::IndexBackend::Finalize(); Orthanc::Toolbox::FinalizeOpenSsl(); + +#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 0) google::protobuf::ShutdownProtobufLibrary(); +#endif }
--- a/PostgreSQL/Plugins/PostgreSQLIndex.cpp Mon Dec 16 11:39:00 2024 +0100 +++ b/PostgreSQL/Plugins/PostgreSQLIndex.cpp Mon Dec 16 12:31:52 2024 +0100 @@ -36,6 +36,8 @@ #include <Logging.h> #include <OrthancException.h> +#include <boost/algorithm/string/join.hpp> + namespace Orthanc { @@ -638,15 +640,10 @@ revisions.push_back("0"); } - std::string joinedResourceIds; - std::string joinedMetadataTypes; - std::string joinedMetadataValues; - std::string joinedRevisions; - - Orthanc::Toolbox::JoinStrings(joinedResourceIds, resourceIds, ","); - Orthanc::Toolbox::JoinStrings(joinedMetadataTypes, metadataTypes, ","); - Orthanc::Toolbox::JoinStrings(joinedMetadataValues, metadataValues, ","); - Orthanc::Toolbox::JoinStrings(joinedRevisions, revisions, ","); + std::string joinedResourceIds = boost::algorithm::join(resourceIds, ","); + std::string joinedMetadataTypes = boost::algorithm::join(metadataTypes, ","); + std::string joinedMetadataValues = boost::algorithm::join(metadataValues, ","); + std::string joinedRevisions = boost::algorithm::join(revisions, ","); std::string sql = std::string("SELECT InsertOrUpdateMetadata(ARRAY[") + joinedResourceIds + "], ARRAY[" +
--- a/SQLite/Plugins/IndexPlugin.cpp Mon Dec 16 11:39:00 2024 +0100 +++ b/SQLite/Plugins/IndexPlugin.cpp Mon Dec 16 12:31:52 2024 +0100 @@ -26,7 +26,9 @@ #include <Logging.h> -#include <google/protobuf/any.h> +#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 0) +# include <google/protobuf/any.h> +#endif #define ORTHANC_PLUGIN_NAME "sqlite-index" @@ -35,7 +37,9 @@ { ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) { +#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 0) GOOGLE_PROTOBUF_VERIFY_VERSION; +#endif if (!OrthancDatabases::InitializePlugin(context, ORTHANC_PLUGIN_NAME, "SQLite", true)) { @@ -92,7 +96,10 @@ { LOG(WARNING) << "SQLite index is finalizing"; OrthancDatabases::IndexBackend::Finalize(); + +#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 0) google::protobuf::ShutdownProtobufLibrary(); +#endif }
--- a/SQLite/Plugins/SQLiteIndex.h Mon Dec 16 11:39:00 2024 +0100 +++ b/SQLite/Plugins/SQLiteIndex.h Mon Dec 16 12:31:52 2024 +0100 @@ -84,11 +84,9 @@ const Orthanc::DatabasePluginMessages::Find_Request& request) ORTHANC_OVERRIDE; #endif -#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5) virtual bool HasChildCountTable() const ORTHANC_OVERRIDE { return false; } -#endif }; }