summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--p2pvr/daemon/recordings.cpp10
-rw-r--r--p2pvr/daemon/recordings.h2
-rw-r--r--p2pvr/daemon/schedules.cpp27
-rw-r--r--p2pvr/daemon/schedules.h3
-rw-r--r--p2pvr/daemon/sql/Recordings_insert.sql2
-rw-r--r--p2pvr/daemon/sql/Recordings_insertNewId.sql2
-rw-r--r--p2pvr/daemon/sql/Schedules_insert.sql2
-rw-r--r--p2pvr/daemon/sql/Schedules_insertNewId.sql1
-rw-r--r--p2pvr/daemon/sql/Schedules_update.sql10
-rw-r--r--p2pvr/daemon/unittests/mockScheduler.cpp7
-rw-r--r--p2pvr/daemon/unittests/mockScheduler.h3
-rw-r--r--p2pvr/daemon/unittests/testRecordings.cpp5
-rw-r--r--p2pvr/daemon/unittests/testSched.cpp12
-rw-r--r--p2pvr/ice/p2pvr.ice6
14 files changed, 43 insertions, 49 deletions
diff --git a/p2pvr/daemon/recordings.cpp b/p2pvr/daemon/recordings.cpp
index 4a3e6d2..547b3bf 100644
--- a/p2pvr/daemon/recordings.cpp
+++ b/p2pvr/daemon/recordings.cpp
@@ -5,21 +5,19 @@
#include <logger.h>
#include <slicer/slicer.h>
#include <slicer/db/sqlSelectDeserializer.h>
+#include <slicer/db/sqlInsertSerializer.h>
-ResourceString(Recording_Insert, sql_Recordings_insert);
-ResourceString(Recording_InsertNewId, sql_Recordings_insertNewId);
ResourceString(Recording_Delete, sql_Recordings_delete);
ResourceString(Recording_GetStorage, sql_Recordings_getStorage);
ResourceString(Recording_GetAll, sql_Recordings_getAll);
-int
+Ice::Int
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 insert = Modify(Recording_Insert, r->StorageAddress, r->Guid, r->ScheduleId, r->EventUid);
- insert.second->execute();
- r->RecordingId = SelectScalar<int>(Recording_InsertNewId);
+ auto db = dataSource<RdbmsDataSource>("postgres")->getWritable();
+ Slicer::SerializeAny<Slicer::SqlFetchIdInsertSerializer>(r, db.get(), "recordings");
Logger()->messagebf(LOG_INFO, "%s: Created recording Id: %d", __PRETTY_FUNCTION__, r->RecordingId);
return r->RecordingId;
}
diff --git a/p2pvr/daemon/recordings.h b/p2pvr/daemon/recordings.h
index 0f18a36..fc7863a 100644
--- a/p2pvr/daemon/recordings.h
+++ b/p2pvr/daemon/recordings.h
@@ -7,7 +7,7 @@
class Recordings : public DatabaseClient, public P2PVR::Recordings {
public:
- int NewRecording(const P2PVR::RecordingPtr & rec, const Ice::Current &);
+ Ice::Int NewRecording(const P2PVR::RecordingPtr & rec, const Ice::Current &);
void DeleteRecording(int recordingId, const Ice::Current &);
P2PVR::RecordingList GetRecordings(const Ice::Current &);
};
diff --git a/p2pvr/daemon/schedules.cpp b/p2pvr/daemon/schedules.cpp
index 19d277f..6a985c3 100644
--- a/p2pvr/daemon/schedules.cpp
+++ b/p2pvr/daemon/schedules.cpp
@@ -12,14 +12,13 @@
#include <boost/date_time/posix_time/posix_time.hpp>
#include <factory.impl.h>
#include <slicer/db/sqlSelectDeserializer.h>
+#include <slicer/db/sqlInsertSerializer.h>
+#include <slicer/db/sqlUpdateSerializer.h>
#include <slicer/slicer.h>
#include <p2pvr-int.h>
#include <privateExecContext.h>
ResourceString(Schedules_getCandidates, sql_Schedules_getCandidates);
-ResourceString(Schedules_insert, sql_Schedules_insert);
-ResourceString(Schedules_insertNewId, sql_Schedules_insertNewId);
-ResourceString(Schedules_update, sql_Schedules_update);
ResourceString(Schedules_delete, sql_Schedules_delete);
ResourceString(Schedules_selectAll, sql_Schedules_selectAll);
ResourceString(Schedules_selectById, sql_Schedules_selectById);
@@ -331,20 +330,24 @@ Schedules::GetScheduledToRecord(const Ice::Current &)
*Select(Schedules_scheduledToRecord).second);
}
-int
-Schedules::UpdateSchedule(const P2PVR::SchedulePtr & s, const Ice::Current & ice)
+Ice::Int
+Schedules::NewSchedule(const P2PVR::SchedulePtr & s, const Ice::Current & ice)
{
TxHelper tx(this);
- if (s->ScheduleId == 0) {
- Modify(Schedules_insert, s->ServiceId, s->EventUid, s->Title, s->Search, s->Priority, s->Early, s->Late, s->Repeats).second->execute();
- s->ScheduleId = SelectScalar<int>(Schedules_insertNewId);
- }
- else {
- Modify(Schedules_update, s->ServiceId, s->EventUid, s->Title, s->Search, s->Priority, s->Early, s->Late, s->Repeats, s->ScheduleId).second->execute();
- }
+ auto db = dataSource<RdbmsDataSource>("postgres")->getWritable();
+ Slicer::SerializeAny<Slicer::SqlFetchIdInsertSerializer>(s, db.get(), "schedules");
DoReschedule(ice);
return s->ScheduleId;
}
+void
+Schedules::UpdateSchedule(const P2PVR::SchedulePtr & s, const Ice::Current & ice)
+{
+ TxHelper tx(this);
+ auto db = dataSource<RdbmsDataSource>("postgres")->getWritable();
+ Slicer::SerializeAny<Slicer::SqlUpdateSerializer>(s, db.get(), "schedules");
+ DoReschedule(ice);
+}
+
INSTANTIATEFACTORY(EpisodeGroup, const Episodes &);
diff --git a/p2pvr/daemon/schedules.h b/p2pvr/daemon/schedules.h
index 07f2c23..2669449 100644
--- a/p2pvr/daemon/schedules.h
+++ b/p2pvr/daemon/schedules.h
@@ -67,7 +67,8 @@ class Schedules : public P2PVR::Schedules, public DatabaseClient {
P2PVR::SchedulePtr GetSchedule(int id, const Ice::Current &);
P2PVR::ScheduleList GetSchedules(const Ice::Current &);
P2PVR::ScheduledToRecordList GetScheduledToRecord(const Ice::Current &);
- int UpdateSchedule(const P2PVR::SchedulePtr &, const Ice::Current &);
+ Ice::Int NewSchedule(const P2PVR::SchedulePtr &, const Ice::Current &);
+ void UpdateSchedule(const P2PVR::SchedulePtr &, const Ice::Current &);
void DoReschedule(const Ice::Current &);
INITOPTIONS;
diff --git a/p2pvr/daemon/sql/Recordings_insert.sql b/p2pvr/daemon/sql/Recordings_insert.sql
deleted file mode 100644
index ba0b9e2..0000000
--- a/p2pvr/daemon/sql/Recordings_insert.sql
+++ /dev/null
@@ -1,2 +0,0 @@
-INSERT INTO recordings(storageAddress, guid, scheduleId, eventUid)
-VALUES(?, ?, ?, ?)
diff --git a/p2pvr/daemon/sql/Recordings_insertNewId.sql b/p2pvr/daemon/sql/Recordings_insertNewId.sql
deleted file mode 100644
index 0583b49..0000000
--- a/p2pvr/daemon/sql/Recordings_insertNewId.sql
+++ /dev/null
@@ -1,2 +0,0 @@
-SELECT currval('recordings_recordingid_seq');
-
diff --git a/p2pvr/daemon/sql/Schedules_insert.sql b/p2pvr/daemon/sql/Schedules_insert.sql
deleted file mode 100644
index 70c95bd..0000000
--- a/p2pvr/daemon/sql/Schedules_insert.sql
+++ /dev/null
@@ -1,2 +0,0 @@
-INSERT INTO schedules(serviceId, eventUid, title, search, priority, early, late, repeats)
-VALUES(?, ?, ?, ?, ?, ?, ?, ?)
diff --git a/p2pvr/daemon/sql/Schedules_insertNewId.sql b/p2pvr/daemon/sql/Schedules_insertNewId.sql
deleted file mode 100644
index f66acd5..0000000
--- a/p2pvr/daemon/sql/Schedules_insertNewId.sql
+++ /dev/null
@@ -1 +0,0 @@
-SELECT currval('schedules_scheduleid_seq');
diff --git a/p2pvr/daemon/sql/Schedules_update.sql b/p2pvr/daemon/sql/Schedules_update.sql
deleted file mode 100644
index cf3ce49..0000000
--- a/p2pvr/daemon/sql/Schedules_update.sql
+++ /dev/null
@@ -1,10 +0,0 @@
-UPDATE schedules SET
- serviceId = ?,
- eventUid = ?,
- title = ?,
- search = ?,
- priority = ?,
- early = ?,
- late = ?,
- repeats = ?
-WHERE scheduleId = ?
diff --git a/p2pvr/daemon/unittests/mockScheduler.cpp b/p2pvr/daemon/unittests/mockScheduler.cpp
index 2677df7..193630d 100644
--- a/p2pvr/daemon/unittests/mockScheduler.cpp
+++ b/p2pvr/daemon/unittests/mockScheduler.cpp
@@ -29,8 +29,13 @@ MockScheduler::GetScheduledToRecord(const::Ice::Current &)
}
Ice::Int
+MockScheduler::NewSchedule(const::P2PVR::SchedulePtr &, const::Ice::Current &)
+{
+ return 1;
+}
+
+void
MockScheduler::UpdateSchedule(const::P2PVR::SchedulePtr &, const::Ice::Current &)
{
- return 0;
}
diff --git a/p2pvr/daemon/unittests/mockScheduler.h b/p2pvr/daemon/unittests/mockScheduler.h
index 9176bb6..e90567b 100644
--- a/p2pvr/daemon/unittests/mockScheduler.h
+++ b/p2pvr/daemon/unittests/mockScheduler.h
@@ -10,7 +10,8 @@ class MockScheduler : public P2PVR::Schedules {
P2PVR::SchedulePtr GetSchedule(::Ice::Int, const ::Ice::Current&) override;
P2PVR::ScheduleList GetSchedules(const ::Ice::Current&) override;
P2PVR::ScheduledToRecordList GetScheduledToRecord(const ::Ice::Current&) override;
- Ice::Int UpdateSchedule(const ::P2PVR::SchedulePtr&, const ::Ice::Current&) override;
+ Ice::Int NewSchedule(const ::P2PVR::SchedulePtr&, const ::Ice::Current&) override;
+ void UpdateSchedule(const ::P2PVR::SchedulePtr&, const ::Ice::Current&) override;
};
#endif
diff --git a/p2pvr/daemon/unittests/testRecordings.cpp b/p2pvr/daemon/unittests/testRecordings.cpp
index ff8f676..7415cb1 100644
--- a/p2pvr/daemon/unittests/testRecordings.cpp
+++ b/p2pvr/daemon/unittests/testRecordings.cpp
@@ -68,9 +68,10 @@ BOOST_AUTO_TEST_CASE( recordings_addAndDelete )
auto guid = boost::lexical_cast<std::string>(boost::uuids::random_generator()());
auto rec = P2PVR::RecordingPtr(new P2PVR::Recording(0, "", guid, 0, event->EventUid));
- auto id = r->NewRecording(rec);
+ rec->RecordingId = r->NewRecording(rec);
+ BOOST_REQUIRE_EQUAL(218, rec->RecordingId);
r->GetRecordings();
- r->DeleteRecording(id);
+ r->DeleteRecording(rec->RecordingId);
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/p2pvr/daemon/unittests/testSched.cpp b/p2pvr/daemon/unittests/testSched.cpp
index 9afdaad..45414aa 100644
--- a/p2pvr/daemon/unittests/testSched.cpp
+++ b/p2pvr/daemon/unittests/testSched.cpp
@@ -79,11 +79,10 @@ BOOST_AUTO_TEST_CASE( sc_crud )
P2PVR::SchedulePtr schedule = new P2PVR::Schedule();
schedule->Search = "Top Gear";
- auto id = sc->UpdateSchedule(schedule);
- BOOST_REQUIRE(id > 0);
- schedule->ScheduleId = id;
+ schedule->ScheduleId = sc->NewSchedule(schedule);
+ BOOST_REQUIRE_EQUAL(187, schedule->ScheduleId);
- auto fetched = sc->GetSchedule(id);
+ auto fetched = sc->GetSchedule(schedule->ScheduleId);
BOOST_REQUIRE_EQUAL(schedule->ScheduleId, fetched->ScheduleId);
BOOST_REQUIRE_EQUAL(*schedule->Search, *fetched->Search);
BOOST_REQUIRE_EQUAL(schedule->Priority, fetched->Priority);
@@ -94,10 +93,9 @@ BOOST_AUTO_TEST_CASE( sc_crud )
schedule->Search = "Top Gear Special";
schedule->Early.Minutes = 5;
schedule->Late.Minutes = 15;
- auto updatedId = sc->UpdateSchedule(schedule);
+ sc->UpdateSchedule(schedule);
- fetched = sc->GetSchedule(id);
- BOOST_REQUIRE_EQUAL(updatedId, id);
+ fetched = sc->GetSchedule(schedule->ScheduleId);
BOOST_REQUIRE_EQUAL(schedule->ScheduleId, fetched->ScheduleId);
BOOST_REQUIRE_EQUAL(*schedule->Search, *fetched->Search);
BOOST_REQUIRE_EQUAL(schedule->Priority, fetched->Priority);
diff --git a/p2pvr/ice/p2pvr.ice b/p2pvr/ice/p2pvr.ice
index 8f746d1..0c9cce3 100644
--- a/p2pvr/ice/p2pvr.ice
+++ b/p2pvr/ice/p2pvr.ice
@@ -8,6 +8,7 @@
module P2PVR {
["project2:type"]
class Event extends DVBSI::Event {
+ ["slicer:db:auto","slicer:db:pkey"]
int EventUid;
bool Current = true;
};
@@ -19,6 +20,7 @@ module P2PVR {
// Something that we have recorded.
["project2:type"]
class Recording {
+ ["slicer:db:auto","slicer:db:pkey"]
int RecordingId;
string StorageAddress;
string Guid;
@@ -30,6 +32,7 @@ module P2PVR {
// Something that defines what we would like to record.
["project2:type"]
class Schedule {
+ ["slicer:db:auto","slicer:db:pkey"]
int ScheduleId = 0;
optional(1) int ServiceId;
optional(2) int EventUid;
@@ -96,7 +99,8 @@ module P2PVR {
idempotent ScheduleList GetSchedules();
["project2:rows"]
idempotent ScheduledToRecordList GetScheduledToRecord();
- idempotent int UpdateSchedule(Schedule newSchedule);
+ idempotent int NewSchedule(Schedule newSchedule);
+ idempotent void UpdateSchedule(Schedule newSchedule);
["project2:task"]
idempotent void DoReschedule();
};