# HG changeset patch # User Sebastien Jodogne # Date 1442409364 -7200 # Node ID 38e44b11091231d93153c9e558a367d28cf1ba58 # Parent 6becb0871f02ad108de51e4554bc82589f815d20 Implementation of the "UpgradeDatabase" extension diff -r 6becb0871f02 -r 38e44b110912 IndexPlugin/Plugin.cpp --- a/IndexPlugin/Plugin.cpp Wed Sep 02 15:07:07 2015 +0200 +++ b/IndexPlugin/Plugin.cpp Wed Sep 16 15:16:04 2015 +0200 @@ -94,7 +94,7 @@ //pg->ClearAll(); // Reset the database /* Create the database back-end */ - backend_ = new OrthancPlugins::PostgreSQLWrapper(pg.release(), useLock, allowUnlock); + backend_ = new OrthancPlugins::PostgreSQLWrapper(context_, pg.release(), useLock, allowUnlock); /* Register the PostgreSQL index into Orthanc */ OrthancPlugins::DatabaseBackendAdapter::Register(context_, *backend_); diff -r 6becb0871f02 -r 38e44b110912 IndexPlugin/PostgreSQLWrapper.cpp --- a/IndexPlugin/PostgreSQLWrapper.cpp Wed Sep 02 15:07:07 2015 +0200 +++ b/IndexPlugin/PostgreSQLWrapper.cpp Wed Sep 16 15:16:04 2015 +0200 @@ -30,9 +30,11 @@ namespace OrthancPlugins { - PostgreSQLWrapper::PostgreSQLWrapper(PostgreSQLConnection* connection, + PostgreSQLWrapper::PostgreSQLWrapper(OrthancPluginContext* context, + PostgreSQLConnection* connection, bool useLock, bool allowUnlock) : + context_(context), connection_(connection), globalProperties_(*connection, useLock, GlobalProperty_IndexLock) { @@ -1253,4 +1255,17 @@ return true; } } + + + uint32_t PostgreSQLWrapper::GetDatabaseVersion() + { + return 5; + } + + + void PostgreSQLWrapper::UpgradeDatabase(uint32_t targetVersion, + OrthancPluginStorageArea* storageArea) + { + throw PostgreSQLException("Unsupported call to upgrade"); + } } diff -r 6becb0871f02 -r 38e44b110912 IndexPlugin/PostgreSQLWrapper.h --- a/IndexPlugin/PostgreSQLWrapper.h Wed Sep 02 15:07:07 2015 +0200 +++ b/IndexPlugin/PostgreSQLWrapper.h Wed Sep 16 15:16:04 2015 +0200 @@ -35,6 +35,8 @@ class PostgreSQLWrapper : public IDatabaseBackend { private: + OrthancPluginContext* context_; + std::auto_ptr connection_; std::auto_ptr transaction_; GlobalProperties globalProperties_; @@ -103,7 +105,8 @@ void ClearTable(const std::string& tableName); public: - PostgreSQLWrapper(PostgreSQLConnection* connection, // Takes the ownership of the connection + PostgreSQLWrapper(OrthancPluginContext* context, + PostgreSQLConnection* connection, // Takes the ownership of the connection bool useLock, bool allowUnlock); @@ -280,5 +283,10 @@ // For unit tests only! bool GetParentPublicId(std::string& result, int64_t id); + + virtual uint32_t GetDatabaseVersion(); + + virtual void UpgradeDatabase(uint32_t targetVersion, + OrthancPluginStorageArea* storageArea); }; } diff -r 6becb0871f02 -r 38e44b110912 NEWS --- a/NEWS Wed Sep 02 15:07:07 2015 +0200 +++ b/NEWS Wed Sep 16 15:16:04 2015 +0200 @@ -1,7 +1,7 @@ Pending changes in the mainline =============================== -* Implementation of the "GetAllPublicIdsWithLimit" extension +* Implementation of the "GetAllPublicIdsWithLimit" and "UpgradeDatabase" extensions Release 1.2 (2015/08/02) ======================== diff -r 6becb0871f02 -r 38e44b110912 UnitTestsSources/PostgreSQLWrapperTests.cpp --- a/UnitTestsSources/PostgreSQLWrapperTests.cpp Wed Sep 02 15:07:07 2015 +0200 +++ b/UnitTestsSources/PostgreSQLWrapperTests.cpp Wed Sep 16 15:16:04 2015 +0200 @@ -154,7 +154,7 @@ context.Free = ::free; context.InvokeService = InvokeService; - PostgreSQLWrapper db(pg.release(), true, true); + PostgreSQLWrapper db(NULL, pg.release(), true, true); db.RegisterOutput(new DatabaseBackendOutput(&context, NULL)); std::string s; @@ -431,7 +431,7 @@ TEST(PostgreSQLWrapper, Lock) { - PostgreSQLWrapper db1(CreateTestConnection(true), true, false); - PostgreSQLWrapper db2(CreateTestConnection(false), false, false); - ASSERT_THROW(OrthancPlugins::PostgreSQLWrapper db3(CreateTestConnection(false), true, false), std::runtime_error); + PostgreSQLWrapper db1(NULL, CreateTestConnection(true), true, false); + PostgreSQLWrapper db2(NULL, CreateTestConnection(false), false, false); + ASSERT_THROW(OrthancPlugins::PostgreSQLWrapper db3(NULL, CreateTestConnection(false), true, false), std::runtime_error); }