Mercurial > hg > orthanc-postgresql
changeset 58:38e44b110912
Implementation of the "UpgradeDatabase" extension
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 16 Sep 2015 15:16:04 +0200 |
parents | 6becb0871f02 |
children | 30733c4198e1 |
files | IndexPlugin/Plugin.cpp IndexPlugin/PostgreSQLWrapper.cpp IndexPlugin/PostgreSQLWrapper.h NEWS UnitTestsSources/PostgreSQLWrapperTests.cpp |
diffstat | 5 files changed, 31 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- 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_);
--- 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"); + } }
--- 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<PostgreSQLConnection> connection_; std::auto_ptr<PostgreSQLTransaction> 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); }; }
--- 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) ========================
--- 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); }