summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2016-12-15 14:48:50 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2016-12-15 14:48:50 +0000
commitbbdcfe2ca28af774607dfeff96577b7948a20b10 (patch)
tree8715ae4ac01b6d15819eecfd635312a65b09c617
parentAdd multi-phase maintenance update cycles (diff)
downloadgentoobrowse-api-bbdcfe2ca28af774607dfeff96577b7948a20b10.tar.bz2
gentoobrowse-api-bbdcfe2ca28af774607dfeff96577b7948a20b10.tar.xz
gentoobrowse-api-bbdcfe2ca28af774607dfeff96577b7948a20b10.zip
Make EntityWhereFilter a template
-rw-r--r--gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp2
-rw-r--r--gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h2
-rw-r--r--gentoobrowse-api/service/maintenance/useGroupProcessor.cpp2
-rw-r--r--gentoobrowse-api/service/utils/entityWhereFilter.cpp29
-rw-r--r--gentoobrowse-api/service/utils/entityWhereFilter.h5
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<int64_t> 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<int64_t> ebuildIds;
std::set<std::string> 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<int64_t> 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<typename T>
+ EntityWhereFilter<T>::EntityWhereFilter(const std::string & en) :
entityColName(en)
{
}
- EntityWhereFilter::EntityWhereFilter(const std::string & en, int64_t e) :
+ template<typename T>
+ EntityWhereFilter<T>::EntityWhereFilter(const std::string & en, const T & e) :
entityColName(en)
{
entityIds.insert(e);
}
- EntityWhereFilter::EntityWhereFilter(const std::string & en, const EntityIds & e) :
+ template<typename T>
+ EntityWhereFilter<T>::EntityWhereFilter(const std::string & en, const EntityIds & e) :
entityIds(e),
entityColName(en)
{
}
+ template<typename T>
void
- EntityWhereFilter::writeSql(AdHoc::Buffer & sql)
+ EntityWhereFilter<T>::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<int64_t>::bindParams(DB::Command * c, unsigned int & offset)
{
for (const auto & entityId : entityIds) {
c->bindParamI(offset++, entityId);
}
}
+
+ template<>
+ void
+ EntityWhereFilter<std::string>::bindParams(DB::Command * c, unsigned int & offset)
+ {
+ for (const auto & entityId : entityIds) {
+ c->bindParamS(offset++, entityId);
+ }
+ }
+
+ template class EntityWhereFilter<int64_t>;
+ template class EntityWhereFilter<std::string>;
}
}
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<typename T>
class EntityWhereFilter : public DB::SqlWriter {
public:
- typedef std::set<int64_t> EntityIds;
+ typedef std::set<T> 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;