# HG changeset patch # User Sebastien Jodogne # Date 1417796573 -3600 # Node ID 90d2f320862de90db34134cdeab78f7d63461438 # Parent 62c35e4b67db008a9b4341520d7653a252c26bc6 refactoring diff -r 62c35e4b67db -r 90d2f320862d OrthancServer/DatabaseWrapper.cpp --- a/OrthancServer/DatabaseWrapper.cpp Fri Dec 05 17:12:35 2014 +0100 +++ b/OrthancServer/DatabaseWrapper.cpp Fri Dec 05 17:22:53 2014 +0100 @@ -336,16 +336,17 @@ s.Run(); } - void DatabaseWrapper::GetChildren(Json::Value& childrenPublicIds, + + void DatabaseWrapper::GetChildren(std::list& childrenPublicIds, int64_t id) { SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT publicId FROM Resources WHERE parentId=?"); s.BindInt64(0, id); - childrenPublicIds = Json::arrayValue; + childrenPublicIds.clear(); while (s.Step()) { - childrenPublicIds.append(s.ColumnString(0)); + childrenPublicIds.push_back(s.ColumnString(0)); } } @@ -788,16 +789,16 @@ return static_cast(s.ColumnInt64(0)); } - void DatabaseWrapper::GetAllPublicIds(Json::Value& target, + void DatabaseWrapper::GetAllPublicIds(std::list& target, ResourceType resourceType) { SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT publicId FROM Resources WHERE resourceType=?"); s.BindInt(0, resourceType); - target = Json::arrayValue; + target.clear(); while (s.Step()) { - target.append(s.ColumnString(0)); + target.push_back(s.ColumnString(0)); } } diff -r 62c35e4b67db -r 90d2f320862d OrthancServer/DatabaseWrapper.h --- a/OrthancServer/DatabaseWrapper.h Fri Dec 05 17:12:35 2014 +0100 +++ b/OrthancServer/DatabaseWrapper.h Fri Dec 05 17:22:53 2014 +0100 @@ -96,9 +96,6 @@ void AttachChild(int64_t parent, int64_t child); - void GetChildren(Json::Value& childrenPublicIds, - int64_t id); - void DeleteResource(int64_t id); void SetMetadata(int64_t id, @@ -134,9 +131,6 @@ void GetMainDicomTags(DicomMap& map, int64_t id); - bool GetParentPublicId(std::string& result, - int64_t id); - void GetChildrenPublicId(std::list& result, int64_t id); @@ -168,16 +162,13 @@ void GetLastExportedResource(Json::Value& target); - // For unit testing only! - int64_t GetTableRecordCount(const std::string& table); - uint64_t GetTotalCompressedSize(); uint64_t GetTotalUncompressedSize(); uint64_t GetResourceCount(ResourceType resourceType); - void GetAllPublicIds(Json::Value& target, + void GetAllPublicIds(std::list& target, ResourceType resourceType); bool SelectPatientToRecycle(int64_t& internalId); @@ -223,5 +214,21 @@ void GetAllMetadata(std::map& result, int64_t id); + + + + + /** + * The methods declared below are for unit testing only! + **/ + + void GetChildren(std::list& childrenPublicIds, + int64_t id); + + int64_t GetTableRecordCount(const std::string& table); + + bool GetParentPublicId(std::string& result, + int64_t id); + }; } diff -r 62c35e4b67db -r 90d2f320862d OrthancServer/ServerIndex.cpp --- a/OrthancServer/ServerIndex.cpp Fri Dec 05 17:12:35 2014 +0100 +++ b/OrthancServer/ServerIndex.cpp Fri Dec 05 17:22:53 2014 +0100 @@ -1022,8 +1022,19 @@ void ServerIndex::GetAllUuids(Json::Value& target, ResourceType resourceType) { - boost::mutex::scoped_lock lock(mutex_); - db_->GetAllPublicIds(target, resourceType); + std::list lst; + + { + boost::mutex::scoped_lock lock(mutex_); + db_->GetAllPublicIds(lst, resourceType); + } + + target = Json::arrayValue; + for (std::list::const_iterator + it = lst.begin(); it != lst.end(); it++) + { + target.append(*it); + } } diff -r 62c35e4b67db -r 90d2f320862d UnitTestsSources/ServerIndexTests.cpp --- a/UnitTestsSources/ServerIndexTests.cpp Fri Dec 05 17:12:35 2014 +0100 +++ b/UnitTestsSources/ServerIndexTests.cpp Fri Dec 05 17:22:53 2014 +0100 @@ -156,15 +156,15 @@ ASSERT_EQ(ResourceType_Study, index_->GetResourceType(a[6])); { - Json::Value t; + std::list t; index_->GetAllPublicIds(t, ResourceType_Patient); ASSERT_EQ(1u, t.size()); - ASSERT_EQ("a", t[0u].asString()); + ASSERT_EQ("a", t.front()); index_->GetAllPublicIds(t, ResourceType_Series); ASSERT_EQ(1u, t.size()); - ASSERT_EQ("c", t[0u].asString()); + ASSERT_EQ("c", t.front()); index_->GetAllPublicIds(t, ResourceType_Study); ASSERT_EQ(2u, t.size()); @@ -353,25 +353,25 @@ index_->AttachChild(a[5], a[7]); { - Json::Value j; + std::list j; index_->GetChildren(j, a[0]); ASSERT_EQ(2u, j.size()); - ASSERT_TRUE((j[0u] == "b" && j[1u] == "f") || - (j[1u] == "b" && j[0u] == "f")); + ASSERT_TRUE((j.front() == "b" && j.back() == "f") || + (j.back() == "b" && j.front() == "f")); index_->GetChildren(j, a[1]); ASSERT_EQ(2u, j.size()); - ASSERT_TRUE((j[0u] == "c" && j[1u] == "g") || - (j[1u] == "c" && j[0u] == "g")); + ASSERT_TRUE((j.front() == "c" && j.back() == "g") || + (j.back() == "c" && j.front() == "g")); index_->GetChildren(j, a[2]); ASSERT_EQ(2u, j.size()); - ASSERT_TRUE((j[0u] == "d" && j[1u] == "e") || - (j[1u] == "d" && j[0u] == "e")); + ASSERT_TRUE((j.front() == "d" && j.back() == "e") || + (j.back() == "d" && j.front() == "e")); index_->GetChildren(j, a[3]); ASSERT_EQ(0u, j.size()); index_->GetChildren(j, a[4]); ASSERT_EQ(0u, j.size()); - index_->GetChildren(j, a[5]); ASSERT_EQ(1u, j.size()); ASSERT_EQ("h", j[0u].asString()); + index_->GetChildren(j, a[5]); ASSERT_EQ(1u, j.size()); ASSERT_EQ("h", j.front()); index_->GetChildren(j, a[6]); ASSERT_EQ(0u, j.size()); index_->GetChildren(j, a[7]); ASSERT_EQ(0u, j.size()); }