Mercurial > hg > orthanc
changeset 5216:450ac804d3af db-protobuf
simplifying IDatabaseWrapper::LogChange()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 03 Apr 2023 14:49:33 +0200 |
parents | 8b6da4fdf9fe |
children | eb41e1833cea |
files | OrthancServer/Plugins/Engine/OrthancPluginDatabase.cpp OrthancServer/Plugins/Engine/OrthancPluginDatabaseV3.cpp OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp OrthancServer/Plugins/Include/orthanc/OrthancDatabasePlugin.proto OrthancServer/Sources/Database/IDatabaseWrapper.h OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp |
diffstat | 7 files changed, 42 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/Plugins/Engine/OrthancPluginDatabase.cpp Mon Apr 03 14:17:39 2023 +0200 +++ b/OrthancServer/Plugins/Engine/OrthancPluginDatabase.cpp Mon Apr 03 14:49:33 2023 +0200 @@ -1055,15 +1055,18 @@ } - virtual void LogChange(int64_t internalId, - const ServerIndexChange& change) ORTHANC_OVERRIDE + virtual void LogChange(ChangeType changeType, + ResourceType resourceType, + int64_t internalId, + const std::string& publicId, + const std::string& date) ORTHANC_OVERRIDE { OrthancPluginChange tmp; - tmp.seq = change.GetSeq(); - tmp.changeType = static_cast<int32_t>(change.GetChangeType()); - tmp.resourceType = Plugins::Convert(change.GetResourceType()); - tmp.publicId = change.GetPublicId().c_str(); - tmp.date = change.GetDate().c_str(); + tmp.seq = -1; // Unused (it is attributed by the database engine) + tmp.changeType = static_cast<int32_t>(changeType); + tmp.resourceType = Plugins::Convert(resourceType); + tmp.publicId = publicId.c_str(); + tmp.date = date.c_str(); CheckSuccess(that_.backend_.logChange(that_.payload_, &tmp)); }
--- a/OrthancServer/Plugins/Engine/OrthancPluginDatabaseV3.cpp Mon Apr 03 14:17:39 2023 +0200 +++ b/OrthancServer/Plugins/Engine/OrthancPluginDatabaseV3.cpp Mon Apr 03 14:49:33 2023 +0200 @@ -622,12 +622,15 @@ } - virtual void LogChange(int64_t internalId, - const ServerIndexChange& change) ORTHANC_OVERRIDE + virtual void LogChange(ChangeType changeType, + ResourceType resourceType, + int64_t internalId, + const std::string& /* publicId - unused */, + const std::string& date) ORTHANC_OVERRIDE { - CheckSuccess(that_.backend_.logChange(transaction_, static_cast<int32_t>(change.GetChangeType()), - internalId, Plugins::Convert(change.GetResourceType()), - change.GetDate().c_str())); + CheckSuccess(that_.backend_.logChange(transaction_, static_cast<int32_t>(changeType), + internalId, Plugins::Convert(resourceType), + date.c_str())); CheckNoEvent(); }
--- a/OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp Mon Apr 03 14:17:39 2023 +0200 +++ b/OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp Mon Apr 03 14:49:33 2023 +0200 @@ -662,16 +662,17 @@ } - virtual void LogChange(int64_t internalId, - const ServerIndexChange& change) ORTHANC_OVERRIDE + virtual void LogChange(ChangeType changeType, + ResourceType resourceType, + int64_t internalId, + const std::string& /* publicId - unused */, + const std::string& date) ORTHANC_OVERRIDE { - // TODO => Simplify "IDatabaseWrapper" - DatabasePluginMessages::TransactionRequest request; - request.mutable_log_change()->set_change_type(change.GetChangeType()); + request.mutable_log_change()->set_change_type(changeType); + request.mutable_log_change()->set_resource_type(Convert(resourceType)); request.mutable_log_change()->set_resource_id(internalId); - request.mutable_log_change()->set_resource_type(Convert(change.GetResourceType())); - request.mutable_log_change()->set_date(change.GetDate()); + request.mutable_log_change()->set_date(date); ExecuteTransaction(DatabasePluginMessages::OPERATION_LOG_CHANGE, request); }
--- a/OrthancServer/Plugins/Include/orthanc/OrthancDatabasePlugin.proto Mon Apr 03 14:17:39 2023 +0200 +++ b/OrthancServer/Plugins/Include/orthanc/OrthancDatabasePlugin.proto Mon Apr 03 14:49:33 2023 +0200 @@ -503,8 +503,8 @@ message LogChange { message Request { int32 change_type = 1; - int64 resource_id = 2; - ResourceType resource_type = 3; + ResourceType resource_type = 2; + int64 resource_id = 3; string date = 4; } message Response {
--- a/OrthancServer/Sources/Database/IDatabaseWrapper.h Mon Apr 03 14:17:39 2023 +0200 +++ b/OrthancServer/Sources/Database/IDatabaseWrapper.h Mon Apr 03 14:49:33 2023 +0200 @@ -135,8 +135,11 @@ virtual void ListAvailableAttachments(std::set<FileContentType>& target, int64_t id) = 0; - virtual void LogChange(int64_t internalId, - const ServerIndexChange& change) = 0; + virtual void LogChange(ChangeType changeType, + ResourceType resourceType, + int64_t internalId, + const std::string& publicId, /* only for compatibility with V1 and V2 plugins */ + const std::string& date) = 0; virtual void LogExportedResource(const ExportedResource& resource) = 0;
--- a/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp Mon Apr 03 14:17:39 2023 +0200 +++ b/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp Mon Apr 03 14:49:33 2023 +0200 @@ -756,14 +756,17 @@ } - virtual void LogChange(int64_t internalId, - const ServerIndexChange& change) ORTHANC_OVERRIDE + virtual void LogChange(ChangeType changeType, + ResourceType resourceType, + int64_t internalId, + const std::string& /* publicId - unused */, + const std::string& date) ORTHANC_OVERRIDE { SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO Changes (seq, changeType, internalId, resourceType, date) VALUES(NULL, ?, ?, ?, ?)"); - s.BindInt(0, change.GetChangeType()); + s.BindInt(0, changeType); s.BindInt64(1, internalId); - s.BindInt(2, change.GetResourceType()); - s.BindString(3, change.GetDate()); + s.BindInt(2, resourceType); + s.BindString(3, date); s.Run(); }
--- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp Mon Apr 03 14:17:39 2023 +0200 +++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp Mon Apr 03 14:49:33 2023 +0200 @@ -415,7 +415,7 @@ if (changeType <= ChangeType_INTERNAL_LastLogged) { - transaction_.LogChange(internalId, change); + transaction_.LogChange(changeType, resourceType, internalId, publicId, change.GetDate()); } GetTransactionContext().SignalChange(change);