From d8fc9e8e6fb3063ba394618ecbfe11d6f505e47f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 15 Dec 2016 14:48:50 +0000 Subject: Make EntityWhereFilter a template --- .../service/maintenance/ebuildMetaProcessor.cpp | 2 +- .../service/maintenance/ebuildMetaProcessor.h | 2 +- .../service/maintenance/useGroupProcessor.cpp | 2 +- .../service/utils/entityWhereFilter.cpp | 29 +++++++++++++++++----- gentoobrowse-api/service/utils/entityWhereFilter.h | 5 ++-- 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp index c88dc22..c19fda0 100644 --- a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp +++ b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp @@ -220,7 +220,7 @@ namespace Gentoo { if (newest) { DB::TablePatch t; // HOMEPAGE - U::EntityWhereFilter pwf("packageId", packageId); + U::EntityWhereFilter pwf("packageId", packageId); U::SplitEbuildProps sep_homepage("packageId", packageId, "url", ecp.get("HOMEPAGE")); t.dest = "gentoobrowse.package_urls"; t.srcExpr = &sep_homepage; diff --git a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h index eb41418..93edf72 100644 --- a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h +++ b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h @@ -32,7 +32,7 @@ namespace Gentoo { DB::ModifyCommandPtr depInsert; DB::ModifyCommandPtr useInsert; DB::ModifyCommandPtr archInsert; - Utils::EntityWhereFilter ebuildIds; + Utils::EntityWhereFilter ebuildIds; std::set catsDeleteFrom; }; } diff --git a/gentoobrowse-api/service/maintenance/useGroupProcessor.cpp b/gentoobrowse-api/service/maintenance/useGroupProcessor.cpp index ab0f87c..9f9705e 100644 --- a/gentoobrowse-api/service/maintenance/useGroupProcessor.cpp +++ b/gentoobrowse-api/service/maintenance/useGroupProcessor.cpp @@ -43,7 +43,7 @@ namespace Gentoo { { DB::TablePatch p; p.dest = "gentoobrowse.use_group"; - U::EntityWhereFilter gwf("useGroupId", useGroupId); + U::EntityWhereFilter gwf("useGroupId", useGroupId); p.src = Utils::Database::emptyClone(dbc, "gentoobrowse.use_group"); p.pk = { "useGroupId", "use" }; p.cols = { "useGroupId", "use", "description" }; diff --git a/gentoobrowse-api/service/utils/entityWhereFilter.cpp b/gentoobrowse-api/service/utils/entityWhereFilter.cpp index be80971..2588edd 100644 --- a/gentoobrowse-api/service/utils/entityWhereFilter.cpp +++ b/gentoobrowse-api/service/utils/entityWhereFilter.cpp @@ -3,28 +3,32 @@ namespace Gentoo { namespace Utils { - EntityWhereFilter::EntityWhereFilter(const std::string & en) : + template + EntityWhereFilter::EntityWhereFilter(const std::string & en) : entityColName(en) { } - EntityWhereFilter::EntityWhereFilter(const std::string & en, int64_t e) : + template + EntityWhereFilter::EntityWhereFilter(const std::string & en, const T & e) : entityColName(en) { entityIds.insert(e); } - EntityWhereFilter::EntityWhereFilter(const std::string & en, const EntityIds & e) : + template + EntityWhereFilter::EntityWhereFilter(const std::string & en, const EntityIds & e) : entityIds(e), entityColName(en) { } + template void - EntityWhereFilter::writeSql(AdHoc::Buffer & sql) + EntityWhereFilter::writeSql(AdHoc::Buffer & sql) { sql.appendbf("a.%s IN (", entityColName); - for (EntityIds::const_iterator ei = entityIds.begin(); ei != entityIds.end(); ++ei) { + for (auto ei = entityIds.begin(); ei != entityIds.end(); ++ei) { if (ei != entityIds.begin()) { sql.append(", ?"); } @@ -35,13 +39,26 @@ namespace Gentoo { sql.append(")"); } + template<> void - EntityWhereFilter::bindParams(DB::Command * c, unsigned int & offset) + EntityWhereFilter::bindParams(DB::Command * c, unsigned int & offset) { for (const auto & entityId : entityIds) { c->bindParamI(offset++, entityId); } } + + template<> + void + EntityWhereFilter::bindParams(DB::Command * c, unsigned int & offset) + { + for (const auto & entityId : entityIds) { + c->bindParamS(offset++, entityId); + } + } + + template class EntityWhereFilter; + template class EntityWhereFilter; } } diff --git a/gentoobrowse-api/service/utils/entityWhereFilter.h b/gentoobrowse-api/service/utils/entityWhereFilter.h index a637288..94e286d 100644 --- a/gentoobrowse-api/service/utils/entityWhereFilter.h +++ b/gentoobrowse-api/service/utils/entityWhereFilter.h @@ -6,12 +6,13 @@ namespace Gentoo { namespace Utils { + template class EntityWhereFilter : public DB::SqlWriter { public: - typedef std::set EntityIds; + typedef std::set EntityIds; EntityWhereFilter(const std::string & en); - EntityWhereFilter(const std::string & en, int64_t e); + EntityWhereFilter(const std::string & en, const T & e); EntityWhereFilter(const std::string & en, const EntityIds & e); void writeSql(AdHoc::Buffer & sql) override; -- cgit v1.2.3