From f529b94f37e5a4387e2e68f6742972defcce017b Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 24 Oct 2015 15:22:27 +0100 Subject: Wrap up slicer updates and DB connection access --- p2pvr/daemon/dbClient.h | 8 ++++++++ p2pvr/daemon/recordings.cpp | 3 +-- p2pvr/daemon/schedules.cpp | 7 ++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/p2pvr/daemon/dbClient.h b/p2pvr/daemon/dbClient.h index cd846e5..1fc12e8 100644 --- a/p2pvr/daemon/dbClient.h +++ b/p2pvr/daemon/dbClient.h @@ -11,6 +11,7 @@ #include #include #include "p2Helpers.h" +#include class SqlMergeTask; @@ -40,6 +41,13 @@ class DatabaseClient : public virtual CommonObjects { return {db, cmd}; } + template + void Store(const Obj & o, const ExtraArgs & ... ea) const + { + auto db = dataSource("postgres")->getWritable(); + Slicer::SerializeAny(o, db.get(), ea...); + } + template std::pair Select(const std::string & sql, const Args & ... args) const { diff --git a/p2pvr/daemon/recordings.cpp b/p2pvr/daemon/recordings.cpp index 547b3bf..ac8f27a 100644 --- a/p2pvr/daemon/recordings.cpp +++ b/p2pvr/daemon/recordings.cpp @@ -16,8 +16,7 @@ Recordings::NewRecording(const P2PVR::RecordingPtr & r, const Ice::Current &) { Logger()->messagebf(LOG_INFO, "%s: Creating new recording %s at %s", __PRETTY_FUNCTION__, r->Guid, r->StorageAddress); TxHelper tx(this); - auto db = dataSource("postgres")->getWritable(); - Slicer::SerializeAny(r, db.get(), "recordings"); + Store(r, "recordings"); Logger()->messagebf(LOG_INFO, "%s: Created recording Id: %d", __PRETTY_FUNCTION__, r->RecordingId); return r->RecordingId; } diff --git a/p2pvr/daemon/schedules.cpp b/p2pvr/daemon/schedules.cpp index 6a985c3..90a42a9 100644 --- a/p2pvr/daemon/schedules.cpp +++ b/p2pvr/daemon/schedules.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include @@ -334,8 +333,7 @@ Ice::Int Schedules::NewSchedule(const P2PVR::SchedulePtr & s, const Ice::Current & ice) { TxHelper tx(this); - auto db = dataSource("postgres")->getWritable(); - Slicer::SerializeAny(s, db.get(), "schedules"); + Store(s, "schedules"); DoReschedule(ice); return s->ScheduleId; } @@ -344,8 +342,7 @@ void Schedules::UpdateSchedule(const P2PVR::SchedulePtr & s, const Ice::Current & ice) { TxHelper tx(this); - auto db = dataSource("postgres")->getWritable(); - Slicer::SerializeAny(s, db.get(), "schedules"); + Store(s, "schedules"); DoReschedule(ice); } -- cgit v1.2.3