diff options
| author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-10-24 14:58:54 +0100 | 
|---|---|---|
| committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-10-24 14:58:54 +0100 | 
| commit | 175596644e6f23231878845bd4ed56b1165f49f5 (patch) | |
| tree | 5b93b7a836a564add8265f8db35189ff36da4ac8 /p2pvr/daemon | |
| parent | Use Slicer-DB to replace our own sqlSelectDeserializer (diff) | |
| download | p2pvr-175596644e6f23231878845bd4ed56b1165f49f5.tar.bz2 p2pvr-175596644e6f23231878845bd4ed56b1165f49f5.tar.xz p2pvr-175596644e6f23231878845bd4ed56b1165f49f5.zip  | |
Use slicer for inserts and updates
Diffstat (limited to 'p2pvr/daemon')
| -rw-r--r-- | p2pvr/daemon/recordings.cpp | 10 | ||||
| -rw-r--r-- | p2pvr/daemon/recordings.h | 2 | ||||
| -rw-r--r-- | p2pvr/daemon/schedules.cpp | 27 | ||||
| -rw-r--r-- | p2pvr/daemon/schedules.h | 3 | ||||
| -rw-r--r-- | p2pvr/daemon/sql/Recordings_insert.sql | 2 | ||||
| -rw-r--r-- | p2pvr/daemon/sql/Recordings_insertNewId.sql | 2 | ||||
| -rw-r--r-- | p2pvr/daemon/sql/Schedules_insert.sql | 2 | ||||
| -rw-r--r-- | p2pvr/daemon/sql/Schedules_insertNewId.sql | 1 | ||||
| -rw-r--r-- | p2pvr/daemon/sql/Schedules_update.sql | 10 | ||||
| -rw-r--r-- | p2pvr/daemon/unittests/mockScheduler.cpp | 7 | ||||
| -rw-r--r-- | p2pvr/daemon/unittests/mockScheduler.h | 3 | ||||
| -rw-r--r-- | p2pvr/daemon/unittests/testRecordings.cpp | 5 | ||||
| -rw-r--r-- | p2pvr/daemon/unittests/testSched.cpp | 12 | 
13 files changed, 38 insertions, 48 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);  | 
