Reducing scope of transactions

This commit is contained in:
epoupon
2015-10-08 12:44:28 +02:00
parent 6775431182
commit 0aa0aaab1a
6 changed files with 118 additions and 78 deletions
+8
View File
@@ -77,6 +77,14 @@ Track::create(Wt::Dbo::Session& session, const boost::filesystem::path& p)
return session.add(new Track(p) );
}
std::vector<boost::filesystem::path>
Track::getAllPaths(Wt::Dbo::Session& session)
{
Wt::Dbo::Transaction transaction(session);
Wt::Dbo::collection<std::string> res = session.query<std::string>("SELECT file_path from track");
return std::vector<boost::filesystem::path>(res.begin(), res.end());
}
std::vector< Genre::pointer >
Track::getGenres(void) const
{
+2 -2
View File
@@ -52,8 +52,7 @@ class Genre
static pointer getByName(Wt::Dbo::Session& session, const std::string& name);
static pointer getNone(Wt::Dbo::Session& session);
static std::vector<pointer> getByFilter(Wt::Dbo::Session& session, SearchFilter filter, int offset = -1, int size = -1);
static Wt::Dbo::collection<pointer> getAll(Wt::Dbo::Session& session);
static Wt::Dbo::collection<Genre::pointer> getAll(Wt::Dbo::Session& session);
// MVC models for the user interface
// Genre ID, name, track count
typedef boost::tuple<id_type, std::string, int> UIQueryResult;
@@ -106,6 +105,7 @@ class Track
static pointer getByMBID(Wt::Dbo::Session& session, const std::string& MBID);
static std::vector<pointer> getByFilter(Wt::Dbo::Session& session, SearchFilter filter, int offset = -1, int size = -1);
static Wt::Dbo::collection< pointer > getAll(Wt::Dbo::Session& session);
static std::vector<boost::filesystem::path> getAllPaths(Wt::Dbo::Session& session);
// Utility fonctions
// MVC models for the user interface
+8
View File
@@ -48,4 +48,12 @@ Video::getByPath(Wt::Dbo::Session& session, const boost::filesystem::path& p)
return session.find<Video>().where("path = ?").bind(p.string());
}
std::vector<boost::filesystem::path>
Video::getAllPaths(Wt::Dbo::Session& session)
{
Wt::Dbo::Transaction transaction(session);
Wt::Dbo::collection<std::string> res = session.query<std::string>("SELECT path from video");
return std::vector<boost::filesystem::path>(res.begin(), res.end());
}
} // namespace Video
+1 -1
View File
@@ -43,7 +43,7 @@ class Video
// Find utilities
static pointer getByPath(Wt::Dbo::Session& session, const boost::filesystem::path& p);
static Wt::Dbo::collection< pointer > getAll(Wt::Dbo::Session& session);
static Wt::Dbo::collection< pointer > getByParentPath(Wt::Dbo::Session& session, const boost::filesystem::path& p);
static std::vector<boost::filesystem::path> getAllPaths(Wt::Dbo::Session& session);
// Create utility
static pointer create(Wt::Dbo::Session& session, const boost::filesystem::path& p);