Commit 724599b0 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Remove global DBConnection typedef

parent 911c31d9
......@@ -25,13 +25,7 @@
namespace medialibrary
{
namespace sqlite
{
class Connection;
}
class MediaLibrary;
using DBConnection = sqlite::Connection*;
using MediaLibraryPtr = const MediaLibrary*;
}
......@@ -331,7 +331,7 @@ bool Album::removeArtist(Artist* artist)
return sqlite::Tools::executeDelete( m_ml->getConn(), req, m_id, artist->id() );
}
bool Album::createTable(DBConnection dbConnection )
bool Album::createTable( sqlite::Connection* dbConnection )
{
const std::string req = "CREATE TABLE IF NOT EXISTS " +
policy::AlbumTable::Name +
......@@ -370,7 +370,7 @@ bool Album::createTable(DBConnection dbConnection )
sqlite::Tools::executeRequest( dbConnection, indexReq );
}
bool Album::createTriggers(DBConnection dbConnection)
bool Album::createTriggers( sqlite::Connection* dbConnection )
{
static const std::string triggerReq = "CREATE TRIGGER IF NOT EXISTS is_album_present AFTER UPDATE OF "
"is_present ON " + policy::AlbumTrackTable::Name +
......
......@@ -98,8 +98,8 @@ class Album : public IAlbum, public DatabaseHelpers<Album, policy::AlbumTable>
bool addArtist( std::shared_ptr<Artist> artist );
bool removeArtist( Artist* artist );
static bool createTable( DBConnection dbConnection );
static bool createTriggers( DBConnection dbConnection );
static bool createTable( sqlite::Connection* dbConnection );
static bool createTriggers( sqlite::Connection* dbConnection );
static std::shared_ptr<Album> create( MediaLibraryPtr ml, const std::string& title, const std::string& artworkMrl );
static std::shared_ptr<Album> createUnknownAlbum( MediaLibraryPtr ml, const Artist* artist );
///
......
......@@ -98,7 +98,7 @@ bool AlbumTrack::setArtist( std::shared_ptr<Artist> artist )
return true;
}
bool AlbumTrack::createTable( DBConnection dbConnection )
bool AlbumTrack::createTable( sqlite::Connection* dbConnection )
{
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::AlbumTrackTable::Name + "("
"id_track INTEGER PRIMARY KEY AUTOINCREMENT,"
......
......@@ -68,14 +68,14 @@ class AlbumTrack : public IAlbumTrack, public DatabaseHelpers<AlbumTrack, policy
virtual std::shared_ptr<IAlbum> album() override;
virtual std::shared_ptr<IMedia> media() override;
static bool createTable( DBConnection dbConnection );
static bool createTable( sqlite::Connection* dbConnection );
static std::shared_ptr<AlbumTrack> create(MediaLibraryPtr ml, int64_t albumId,
std::shared_ptr<Media> media, unsigned int trackNb,
unsigned int discNumber, int64_t artistId, int64_t genreId,
int64_t duration );
static AlbumTrackPtr fromMedia( MediaLibraryPtr ml, int64_t mediaId );
static std::vector<MediaPtr> fromGenre( MediaLibraryPtr ml, int64_t genreId, SortingCriteria sort, bool desc );
static std::vector<MediaPtr> search(DBConnection dbConn, const std::string& title );
static std::vector<MediaPtr> search( sqlite::Connection* dbConn, const std::string& title );
private:
MediaLibraryPtr m_ml;
......
......@@ -189,7 +189,7 @@ bool Artist::setMusicBrainzId( const std::string& mbId )
return true;
}
bool Artist::createTable( DBConnection dbConnection )
bool Artist::createTable( sqlite::Connection* dbConnection )
{
const std::string req = "CREATE TABLE IF NOT EXISTS " +
policy::ArtistTable::Name +
......@@ -220,7 +220,7 @@ bool Artist::createTable( DBConnection dbConnection )
sqlite::Tools::executeRequest( dbConnection, reqFts );
}
bool Artist::createTriggers(DBConnection dbConnection)
bool Artist::createTriggers( sqlite::Connection* dbConnection )
{
static const std::string triggerReq = "CREATE TRIGGER IF NOT EXISTS has_album_present AFTER UPDATE OF "
"is_present ON " + policy::AlbumTable::Name +
......@@ -261,7 +261,7 @@ bool Artist::createTriggers(DBConnection dbConnection)
sqlite::Tools::executeRequest( dbConnection, ftsDeleteTrigger );
}
bool Artist::createDefaultArtists( DBConnection dbConnection )
bool Artist::createDefaultArtists( sqlite::Connection* dbConnection )
{
// Don't rely on Artist::create, since we want to insert or do nothing here.
// This will skip the cache for those new entities, but they will be inserted soon enough anyway.
......
......@@ -63,9 +63,9 @@ public:
virtual const std::string& musicBrainzId() const override;
bool setMusicBrainzId( const std::string& musicBrainzId );
static bool createTable( DBConnection dbConnection );
static bool createTriggers( DBConnection dbConnection );
static bool createDefaultArtists( DBConnection dbConnection );
static bool createTable( sqlite::Connection* dbConnection );
static bool createTriggers( sqlite::Connection* dbConnection );
static bool createDefaultArtists( sqlite::Connection* dbConnection );
static std::shared_ptr<Artist> create( MediaLibraryPtr ml, const std::string& name );
static std::vector<ArtistPtr> search( MediaLibraryPtr ml, const std::string& name );
static std::vector<ArtistPtr> listAll( MediaLibraryPtr ml, SortingCriteria sort, bool desc );
......
......@@ -97,7 +97,7 @@ const std::string& AudioTrack::description() const
return m_description;
}
bool AudioTrack::createTable( DBConnection dbConnection )
bool AudioTrack::createTable( sqlite::Connection* dbConnection )
{
//FIXME: Index on media_id ? Unless it's already implied by the foreign key
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::AudioTrackTable::Name
......
......@@ -58,7 +58,7 @@ class AudioTrack : public IAudioTrack, public DatabaseHelpers<AudioTrack, policy
virtual const std::string& language() const override;
virtual const std::string& description() const override;
static bool createTable( DBConnection dbConnection );
static bool createTable( sqlite::Connection* dbConnection );
static std::shared_ptr<AudioTrack> create( MediaLibraryPtr ml, const std::string& codec,
unsigned int bitrate, unsigned int sampleRate, unsigned int nbChannels,
const std::string& language, const std::string& desc, int64_t mediaId );
......
......@@ -100,7 +100,7 @@ std::shared_ptr<Device> Device::create( MediaLibraryPtr ml, const std::string& u
return self;
}
bool Device::createTable(DBConnection connection)
bool Device::createTable( sqlite::Connection* connection )
{
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::DeviceTable::Name + "("
"id_device INTEGER PRIMARY KEY AUTOINCREMENT,"
......
......@@ -59,7 +59,7 @@ public:
const std::string& scheme() const;
static std::shared_ptr<Device> create( MediaLibraryPtr ml, const std::string& uuid, const std::string& scheme, bool isRemovable );
static bool createTable( DBConnection connection );
static bool createTable( sqlite::Connection* connection );
static std::shared_ptr<Device> fromUuid( MediaLibraryPtr ml, const std::string& uuid );
private:
......
......@@ -190,7 +190,7 @@ int64_t File::folderId()
return m_folderId;
}
bool File::createTable( DBConnection dbConnection )
bool File::createTable( sqlite::Connection* dbConnection )
{
std::string req = "CREATE TABLE IF NOT EXISTS " + policy::FileTable::Name + "("
"id_file INTEGER PRIMARY KEY AUTOINCREMENT,"
......
......@@ -77,7 +77,7 @@ public:
bool destroy();
int64_t folderId();
static bool createTable( DBConnection dbConnection );
static bool createTable( sqlite::Connection* dbConnection );
static std::shared_ptr<File> createFromMedia( MediaLibraryPtr ml, int64_t mediaId, Type type,
const fs::IFile& file, int64_t folderId, bool isRemovable );
static std::shared_ptr<File> createFromMedia( MediaLibraryPtr ml, int64_t mediaId, Type type,
......
......@@ -70,7 +70,7 @@ Folder::Folder(MediaLibraryPtr ml, const std::string& path, int64_t parent, int6
{
}
bool Folder::createTable( DBConnection connection)
bool Folder::createTable( sqlite::Connection* connection)
{
std::string req = "CREATE TABLE IF NOT EXISTS " + policy::FolderTable::Name +
"("
......
......@@ -60,7 +60,7 @@ public:
Folder( MediaLibraryPtr ml, sqlite::Row& row );
Folder(MediaLibraryPtr ml, const std::string& path, int64_t parent , int64_t deviceId , bool isRemovable );
static bool createTable( DBConnection connection );
static bool createTable( sqlite::Connection* connection );
static std::shared_ptr<Folder> create( MediaLibraryPtr ml, const std::string& mrl, int64_t parentId, Device& device, fs::IDevice& deviceFs );
static bool blacklist( MediaLibraryPtr ml, const std::string& mrl );
static std::vector<std::shared_ptr<Folder>> fetchRootFolders( MediaLibraryPtr ml );
......
......@@ -97,7 +97,7 @@ std::vector<AlbumPtr> Genre::albums( SortingCriteria sort, bool desc ) const
return Album::fromGenre( m_ml, m_id, sort, desc );
}
bool Genre::createTable( DBConnection dbConn )
bool Genre::createTable( sqlite::Connection* dbConn )
{
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::GenreTable::Name +
"("
......@@ -126,7 +126,7 @@ bool Genre::createTable( DBConnection dbConn )
sqlite::Tools::executeRequest( dbConn, vtableDeleteTrigger );
}
bool Genre::createTriggers( DBConnection dbConn )
bool Genre::createTriggers( sqlite::Connection* dbConn )
{
const std::string onGenreChanged = "CREATE TRIGGER IF NOT EXISTS on_track_genre_changed AFTER UPDATE OF "
" genre_id ON " + policy::AlbumTrackTable::Name +
......
......@@ -54,8 +54,8 @@ public:
virtual std::vector<MediaPtr> tracks(SortingCriteria sort, bool desc) const override;
virtual std::vector<AlbumPtr> albums( SortingCriteria sort, bool desc ) const override;
static bool createTable( DBConnection dbConn );
static bool createTriggers( DBConnection dbConn );
static bool createTable( sqlite::Connection* dbConn );
static bool createTriggers( sqlite::Connection* dbConn );
static std::shared_ptr<Genre> create( MediaLibraryPtr ml, const std::string& name );
static std::shared_ptr<Genre> fromName( MediaLibraryPtr ml, const std::string& name );
static std::vector<GenrePtr> search( MediaLibraryPtr ml, const std::string& name );
......
......@@ -49,7 +49,7 @@ History::History( MediaLibraryPtr ml, sqlite::Row& row )
row >> m_date;
}
bool History::createTable( DBConnection dbConnection )
bool History::createTable( sqlite::Connection* dbConnection )
{
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::HistoryTable::Name +
"("
......@@ -70,7 +70,7 @@ bool History::createTable( DBConnection dbConnection )
sqlite::Tools::executeRequest( dbConnection, triggerReq );
}
bool History::insert( DBConnection dbConn, int64_t mediaId )
bool History::insert( sqlite::Connection* dbConn, int64_t mediaId )
{
static const std::string req = "INSERT OR REPLACE INTO " + policy::HistoryTable::Name +
"(id_media, insertion_date) VALUES(?, strftime('%s', 'now'))";
......
......@@ -49,8 +49,8 @@ class History : public IHistoryEntry, public DatabaseHelpers<History, policy::Hi
{
public:
History( MediaLibraryPtr ml, sqlite::Row& row );
static bool createTable( DBConnection dbConnection );
static bool insert( DBConnection dbConn, int64_t mediaId );
static bool createTable( sqlite::Connection* dbConnection );
static bool insert( sqlite::Connection* dbConn, int64_t mediaId );
static std::vector<HistoryPtr> fetch( MediaLibraryPtr ml );
static bool clearStreams( MediaLibraryPtr ml );
......
......@@ -80,7 +80,7 @@ LabelPtr Label::create( MediaLibraryPtr ml, const std::string& name )
return self;
}
bool Label::createTable( DBConnection dbConnection )
bool Label::createTable( sqlite::Connection* dbConnection )
{
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::LabelTable::Name + "("
"id_label INTEGER PRIMARY KEY AUTOINCREMENT, "
......
......@@ -57,7 +57,7 @@ class Label : public ILabel, public DatabaseHelpers<Label, policy::LabelTable>
virtual std::vector<MediaPtr> files() override;
static LabelPtr create( MediaLibraryPtr ml, const std::string& name );
static bool createTable( DBConnection dbConnection );
static bool createTable( sqlite::Connection* dbConnection );
private:
MediaLibraryPtr m_ml;
......
......@@ -513,7 +513,7 @@ void Media::setTitleBuffered( const std::string &title )
m_changed = true;
}
bool Media::createTable( DBConnection connection )
bool Media::createTable( sqlite::Connection* connection )
{
std::string req = "CREATE TABLE IF NOT EXISTS " + policy::MediaTable::Name + "("
"id_media INTEGER PRIMARY KEY AUTOINCREMENT,"
......@@ -549,7 +549,7 @@ bool Media::createTable( DBConnection connection )
sqlite::Tools::executeRequest( connection, metadataReq );
}
bool Media::createTriggers( DBConnection connection )
bool Media::createTriggers( sqlite::Connection* connection )
{
static const std::string triggerReq = "CREATE TRIGGER IF NOT EXISTS has_files_present AFTER UPDATE OF "
"is_present ON " + policy::FileTable::Name +
......
......@@ -86,8 +86,8 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
Media( MediaLibraryPtr ml, const std::string &title, Type type);
static std::shared_ptr<Media> create( MediaLibraryPtr ml, Type type, const std::string& fileName );
static bool createTable( DBConnection connection );
static bool createTriggers( DBConnection connection );
static bool createTable( sqlite::Connection* connection );
static bool createTriggers( sqlite::Connection* connection );
virtual int64_t id() const override;
virtual Type type() override;
......
......@@ -898,7 +898,7 @@ void MediaLibrary::onParserIdleChanged( bool idle )
}
}
DBConnection MediaLibrary::getConn() const
sqlite::Connection* MediaLibrary::getConn() const
{
return m_dbConnection.get();
}
......
......@@ -137,7 +137,7 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
void onDiscovererIdleChanged( bool idle );
void onParserIdleChanged( bool idle );
DBConnection getConn() const;
sqlite::Connection* getConn() const;
IMediaLibraryCb* getCb() const;
std::shared_ptr<ModificationNotifier> getNotifier() const;
......
......@@ -116,7 +116,7 @@ std::vector<MediaPtr> Movie::files()
return Media::fetchAll<IMedia>( m_ml, req, m_id );
}
bool Movie::createTable( DBConnection dbConnection )
bool Movie::createTable( sqlite::Connection* dbConnection )
{
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::MovieTable::Name
+ "("
......
......@@ -58,7 +58,7 @@ class Movie : public IMovie, public DatabaseHelpers<Movie, policy::MovieTable>
bool setImdbId(const std::string& imdbId);
virtual std::vector<MediaPtr> files() override;
static bool createTable( DBConnection dbConnection );
static bool createTable( sqlite::Connection* dbConnection );
static std::shared_ptr<Movie> create( MediaLibraryPtr ml, int64_t mediaId, const std::string& title );
static MoviePtr fromMedia( MediaLibraryPtr ml, int64_t mediaId );
......
......@@ -178,7 +178,7 @@ bool Playlist::remove( int64_t mediaId )
return sqlite::Tools::executeDelete( m_ml->getConn(), req, m_id, mediaId );
}
bool Playlist::createTable( DBConnection dbConn )
bool Playlist::createTable( sqlite::Connection* dbConn )
{
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::PlaylistTable::Name + "("
+ policy::PlaylistTable::PrimaryKeyColumn + " INTEGER PRIMARY KEY AUTOINCREMENT,"
......@@ -209,7 +209,7 @@ bool Playlist::createTable( DBConnection dbConn )
sqlite::Tools::executeRequest( dbConn, vtableReq );
}
bool Playlist::createTriggers( DBConnection dbConn )
bool Playlist::createTriggers( sqlite::Connection* dbConn )
{
static const std::string req = "CREATE TRIGGER IF NOT EXISTS update_playlist_order AFTER UPDATE OF position"
" ON PlaylistMediaRelation"
......
......@@ -67,8 +67,8 @@ public:
std::shared_ptr<File> addFile( const fs::IFile& fileFs, int64_t parentFolderId,
bool isFolderFsRemovable );
static bool createTable( DBConnection dbConn );
static bool createTriggers( DBConnection dbConn );
static bool createTable( sqlite::Connection* dbConn );
static bool createTriggers( sqlite::Connection* dbConn );
static std::vector<PlaylistPtr> search( MediaLibraryPtr ml, const std::string& name );
static std::vector<PlaylistPtr> listAll( MediaLibraryPtr ml, SortingCriteria sort, bool desc );
......
......@@ -143,7 +143,7 @@ std::vector<ShowEpisodePtr> Show::episodes()
return ShowEpisode::fetchAll<IShowEpisode>( m_ml, req, m_id );
}
bool Show::createTable( DBConnection dbConnection )
bool Show::createTable( sqlite::Connection* dbConnection )
{
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::ShowTable::Name + "("
"id_show INTEGER PRIMARY KEY AUTOINCREMENT,"
......
......@@ -65,7 +65,7 @@ class Show : public IShow, public DatabaseHelpers<Show, policy::ShowTable>
std::shared_ptr<ShowEpisode> addEpisode( Media& media, const std::string& title, unsigned int episodeNumber );
virtual std::vector<ShowEpisodePtr> episodes() override;
static bool createTable( DBConnection dbConnection );
static bool createTable( sqlite::Connection* dbConnection );
static std::shared_ptr<Show> create( MediaLibraryPtr ml, const std::string& name );
protected:
......
......@@ -152,7 +152,7 @@ std::vector<MediaPtr> ShowEpisode::files()
return Media::fetchAll<IMedia>( m_ml, req, m_id );
}
bool ShowEpisode::createTable( DBConnection dbConnection )
bool ShowEpisode::createTable( sqlite::Connection* dbConnection )
{
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::ShowEpisodeTable::Name
+ "("
......
......@@ -66,7 +66,7 @@ class ShowEpisode : public IShowEpisode, public DatabaseHelpers<ShowEpisode, pol
virtual ShowPtr show() override;
virtual std::vector<MediaPtr> files() override;
static bool createTable( DBConnection dbConnection );
static bool createTable( sqlite::Connection* dbConnection );
static std::shared_ptr<ShowEpisode> create( MediaLibraryPtr ml, int64_t mediaId, const std::string& title, unsigned int episodeNumber, int64_t showId );
static ShowEpisodePtr fromMedia( MediaLibraryPtr ml, int64_t mediaId );
......
......@@ -106,7 +106,7 @@ std::shared_ptr<VideoTrack> VideoTrack::create( MediaLibraryPtr ml, const std::s
return track;
}
bool VideoTrack::createTable( DBConnection dbConnection )
bool VideoTrack::createTable( sqlite::Connection* dbConnection )
{
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::VideoTrackTable::Name
+ "(" +
......
......@@ -59,7 +59,7 @@ class VideoTrack : public IVideoTrack, public DatabaseHelpers<VideoTrack, policy
virtual const std::string& language() const override;
virtual const std::string& description() const override;
static bool createTable( DBConnection dbConnection );
static bool createTable( sqlite::Connection* dbConnection );
static std::shared_ptr<VideoTrack> create( MediaLibraryPtr ml, const std::string& codec,
unsigned int width, unsigned int height, float fps, int64_t mediaId,
const std::string& language, const std::string& description );
......
......@@ -276,7 +276,7 @@ class Tools
}
template <typename... Args>
static bool executeRequest( DBConnection dbConnection, const std::string& req, Args&&... args )
static bool executeRequest( sqlite::Connection* dbConnection, const std::string& req, Args&&... args )
{
Connection::WriteContext ctx;
if (Transaction::transactionInProgress() == false)
......@@ -285,7 +285,7 @@ class Tools
}
template <typename... Args>
static bool executeDelete( DBConnection dbConnection, const std::string& req, Args&&... args )
static bool executeDelete( sqlite::Connection* dbConnection, const std::string& req, Args&&... args )
{
Connection::WriteContext ctx;
if (Transaction::transactionInProgress() == false)
......@@ -296,7 +296,7 @@ class Tools
}
template <typename... Args>
static bool executeUpdate( DBConnection dbConnection, const std::string& req, Args&&... args )
static bool executeUpdate( sqlite::Connection* dbConnection, const std::string& req, Args&&... args )
{
// The code would be exactly the same, do not freak out because it calls executeDelete :)
return executeDelete( dbConnection, req, std::forward<Args>( args )... );
......@@ -307,7 +307,7 @@ class Tools
* Returns 0 (which is an invalid sqlite primary key) when insertion fails.
*/
template <typename... Args>
static int64_t executeInsert( DBConnection dbConnection, const std::string& req, Args&&... args )
static int64_t executeInsert( sqlite::Connection* dbConnection, const std::string& req, Args&&... args )
{
Connection::WriteContext ctx;
if (Transaction::transactionInProgress() == false)
......@@ -345,7 +345,7 @@ class Tools
private:
template <typename... Args>
static bool executeRequestLocked( DBConnection dbConnection, const std::string& req, Args&&... args )
static bool executeRequestLocked( sqlite::Connection* dbConnection, const std::string& req, Args&&... args )
{
auto chrono = std::chrono::steady_clock::now();
Statement stmt( dbConnection->getConn(), req );
......
......@@ -36,7 +36,7 @@ namespace sqlite
thread_local Transaction* Transaction::CurrentTransaction = nullptr;
Transaction::Transaction(DBConnection dbConn)
Transaction::Transaction( sqlite::Connection* dbConn)
: m_dbConn( dbConn )
, m_ctx( dbConn->acquireWriteContext() )
{
......
......@@ -37,7 +37,7 @@ namespace sqlite
class Transaction
{
public:
Transaction( DBConnection dbConn );
Transaction( sqlite::Connection* dbConn );
Transaction( const Transaction& ) = delete;
Transaction( Transaction&& ) = delete;
Transaction& operator=( const Transaction& ) = delete;
......@@ -49,7 +49,7 @@ public:
~Transaction();
private:
DBConnection m_dbConn;
sqlite::Connection* m_dbConn;
Connection::WriteContext m_ctx;
std::vector<std::function<void()>> m_failureHandlers;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment