Commit 117d49c0 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Don't manually set m_ml when creating entities

parent 00b6f548
...@@ -47,8 +47,9 @@ Album::Album(MediaLibraryPtr ml, sqlite::Row& row) ...@@ -47,8 +47,9 @@ Album::Album(MediaLibraryPtr ml, sqlite::Row& row)
>> m_isPresent; >> m_isPresent;
} }
Album::Album(const std::string& title ) Album::Album( MediaLibraryPtr ml, const std::string& title )
: m_id( 0 ) : m_ml( ml )
, m_id( 0 )
, m_title( title ) , m_title( title )
, m_artistId( 0 ) , m_artistId( 0 )
, m_releaseYear( ~0u ) , m_releaseYear( ~0u )
...@@ -57,8 +58,9 @@ Album::Album(const std::string& title ) ...@@ -57,8 +58,9 @@ Album::Album(const std::string& title )
{ {
} }
Album::Album( const Artist* artist ) Album::Album( MediaLibraryPtr ml, const Artist* artist )
: m_id( 0 ) : m_ml( ml )
, m_id( 0 )
, m_artistId( artist->id() ) , m_artistId( artist->id() )
, m_releaseYear( ~0u ) , m_releaseYear( ~0u )
, m_nbTracks( 0 ) , m_nbTracks( 0 )
...@@ -319,23 +321,21 @@ bool Album::createTriggers(DBConnection dbConnection) ...@@ -319,23 +321,21 @@ bool Album::createTriggers(DBConnection dbConnection)
std::shared_ptr<Album> Album::create( MediaLibraryPtr ml, const std::string& title ) std::shared_ptr<Album> Album::create( MediaLibraryPtr ml, const std::string& title )
{ {
auto album = std::make_shared<Album>( title ); auto album = std::make_shared<Album>( ml, title );
static const std::string req = "INSERT INTO " + policy::AlbumTable::Name + static const std::string req = "INSERT INTO " + policy::AlbumTable::Name +
"(id_album, title) VALUES(NULL, ?)"; "(id_album, title) VALUES(NULL, ?)";
if ( insert( ml, album, req, title ) == false ) if ( insert( ml, album, req, title ) == false )
return nullptr; return nullptr;
album->m_ml = ml;
return album; return album;
} }
std::shared_ptr<Album> Album::createUnknownAlbum( MediaLibraryPtr ml, const Artist* artist ) std::shared_ptr<Album> Album::createUnknownAlbum( MediaLibraryPtr ml, const Artist* artist )
{ {
auto album = std::make_shared<Album>( artist ); auto album = std::make_shared<Album>( ml, artist );
static const std::string req = "INSERT INTO " + policy::AlbumTable::Name + static const std::string req = "INSERT INTO " + policy::AlbumTable::Name +
"(id_album, artist_id) VALUES(NULL, ?)"; "(id_album, artist_id) VALUES(NULL, ?)";
if ( insert( ml, album, req, artist->id() ) == false ) if ( insert( ml, album, req, artist->id() ) == false )
return nullptr; return nullptr;
album->m_ml = ml;
return album; return album;
} }
......
...@@ -52,8 +52,8 @@ class Album : public IAlbum, public DatabaseHelpers<Album, policy::AlbumTable> ...@@ -52,8 +52,8 @@ class Album : public IAlbum, public DatabaseHelpers<Album, policy::AlbumTable>
{ {
public: public:
Album( MediaLibraryPtr ml, sqlite::Row& row ); Album( MediaLibraryPtr ml, sqlite::Row& row );
Album( const std::string& title ); Album( MediaLibraryPtr ml, const std::string& title );
Album( const Artist* artist ); Album( MediaLibraryPtr ml, const Artist* artist );
virtual unsigned int id() const override; virtual unsigned int id() const override;
virtual const std::string& title() const override; virtual const std::string& title() const override;
......
...@@ -46,8 +46,9 @@ AlbumTrack::AlbumTrack( MediaLibraryPtr ml, sqlite::Row& row ) ...@@ -46,8 +46,9 @@ AlbumTrack::AlbumTrack( MediaLibraryPtr ml, sqlite::Row& row )
>> m_isPresent; >> m_isPresent;
} }
AlbumTrack::AlbumTrack( unsigned int mediaId, unsigned int trackNumber, unsigned int albumId, unsigned int discNumber ) AlbumTrack::AlbumTrack( MediaLibraryPtr ml, unsigned int mediaId, unsigned int trackNumber, unsigned int albumId, unsigned int discNumber )
: m_id( 0 ) : m_ml( ml )
, m_id( 0 )
, m_mediaId( mediaId ) , m_mediaId( mediaId )
, m_trackNumber( trackNumber ) , m_trackNumber( trackNumber )
, m_albumId( albumId ) , m_albumId( albumId )
...@@ -119,12 +120,11 @@ bool AlbumTrack::createTable( DBConnection dbConnection ) ...@@ -119,12 +120,11 @@ bool AlbumTrack::createTable( DBConnection dbConnection )
std::shared_ptr<AlbumTrack> AlbumTrack::create( MediaLibraryPtr ml, unsigned int albumId, const Media& media, unsigned int trackNb, unsigned int discNumber ) std::shared_ptr<AlbumTrack> AlbumTrack::create( MediaLibraryPtr ml, unsigned int albumId, const Media& media, unsigned int trackNb, unsigned int discNumber )
{ {
auto self = std::make_shared<AlbumTrack>( media.id(), trackNb, albumId, discNumber ); auto self = std::make_shared<AlbumTrack>( ml, media.id(), trackNb, albumId, discNumber );
static const std::string req = "INSERT INTO " + policy::AlbumTrackTable::Name static const std::string req = "INSERT INTO " + policy::AlbumTrackTable::Name
+ "(media_id, track_number, album_id, disc_number) VALUES(?, ?, ?, ?)"; + "(media_id, track_number, album_id, disc_number) VALUES(?, ?, ?, ?)";
if ( insert( ml, self, req, media.id(), trackNb, albumId, discNumber ) == false ) if ( insert( ml, self, req, media.id(), trackNb, albumId, discNumber ) == false )
return nullptr; return nullptr;
self->m_ml = ml;
return self; return self;
} }
......
...@@ -52,7 +52,7 @@ class AlbumTrack : public IAlbumTrack, public DatabaseHelpers<AlbumTrack, policy ...@@ -52,7 +52,7 @@ class AlbumTrack : public IAlbumTrack, public DatabaseHelpers<AlbumTrack, policy
{ {
public: public:
AlbumTrack( MediaLibraryPtr ml, sqlite::Row& row ); AlbumTrack( MediaLibraryPtr ml, sqlite::Row& row );
AlbumTrack( unsigned int mediaId, unsigned int trackNumber, unsigned int albumId , unsigned int discNumber); AlbumTrack( MediaLibraryPtr ml, unsigned int mediaId, unsigned int trackNumber, unsigned int albumId , unsigned int discNumber);
virtual unsigned int id() const override; virtual unsigned int id() const override;
virtual ArtistPtr artist() const override; virtual ArtistPtr artist() const override;
......
...@@ -44,8 +44,9 @@ Artist::Artist( MediaLibraryPtr ml, sqlite::Row& row ) ...@@ -44,8 +44,9 @@ Artist::Artist( MediaLibraryPtr ml, sqlite::Row& row )
>> m_isPresent; >> m_isPresent;
} }
Artist::Artist( const std::string& name ) Artist::Artist( MediaLibraryPtr ml, const std::string& name )
: m_id( 0 ) : m_ml( ml )
, m_id( 0 )
, m_name( name ) , m_name( name )
, m_nbAlbums( 0 ) , m_nbAlbums( 0 )
, m_isPresent( true ) , m_isPresent( true )
...@@ -238,12 +239,11 @@ bool Artist::createDefaultArtists( DBConnection dbConnection ) ...@@ -238,12 +239,11 @@ bool Artist::createDefaultArtists( DBConnection dbConnection )
std::shared_ptr<Artist> Artist::create( MediaLibraryPtr ml, const std::string &name ) std::shared_ptr<Artist> Artist::create( MediaLibraryPtr ml, const std::string &name )
{ {
auto artist = std::make_shared<Artist>( name ); auto artist = std::make_shared<Artist>( ml, name );
static const std::string req = "INSERT INTO " + policy::ArtistTable::Name + static const std::string req = "INSERT INTO " + policy::ArtistTable::Name +
"(id_artist, name) VALUES(NULL, ?)"; "(id_artist, name) VALUES(NULL, ?)";
if ( insert( ml, artist, req, name ) == false ) if ( insert( ml, artist, req, name ) == false )
return nullptr; return nullptr;
artist->m_ml = ml;
return artist; return artist;
} }
......
...@@ -43,8 +43,8 @@ struct ArtistTable ...@@ -43,8 +43,8 @@ struct ArtistTable
class Artist : public IArtist, public DatabaseHelpers<Artist, policy::ArtistTable> class Artist : public IArtist, public DatabaseHelpers<Artist, policy::ArtistTable>
{ {
public: public:
Artist(MediaLibraryPtr ml, sqlite::Row& row ); Artist( MediaLibraryPtr ml, sqlite::Row& row );
Artist( const std::string& name ); Artist( MediaLibraryPtr ml, const std::string& name );
virtual unsigned int id() const override; virtual unsigned int id() const override;
virtual const std::string &name() const override; virtual const std::string &name() const override;
......
...@@ -41,10 +41,11 @@ AudioTrack::AudioTrack( MediaLibraryPtr ml, sqlite::Row& row ) ...@@ -41,10 +41,11 @@ AudioTrack::AudioTrack( MediaLibraryPtr ml, sqlite::Row& row )
>> m_mediaId; >> m_mediaId;
} }
AudioTrack::AudioTrack( const std::string& codec, unsigned int bitrate , unsigned int sampleRate, AudioTrack::AudioTrack( MediaLibraryPtr ml, const std::string& codec, unsigned int bitrate, unsigned int sampleRate,
unsigned int nbChannels, const std::string& language, const std::string& desc, unsigned int nbChannels, const std::string& language, const std::string& desc,
unsigned int mediaId ) unsigned int mediaId )
: m_id( 0 ) : m_ml( ml )
, m_id( 0 )
, m_codec( codec ) , m_codec( codec )
, m_bitrate( bitrate ) , m_bitrate( bitrate )
, m_sampleRate( sampleRate ) , m_sampleRate( sampleRate )
...@@ -115,9 +116,8 @@ std::shared_ptr<AudioTrack> AudioTrack::create( MediaLibraryPtr ml, const std::s ...@@ -115,9 +116,8 @@ std::shared_ptr<AudioTrack> AudioTrack::create( MediaLibraryPtr ml, const std::s
{ {
static const std::string req = "INSERT INTO " + policy::AudioTrackTable::Name static const std::string req = "INSERT INTO " + policy::AudioTrackTable::Name
+ "(codec, bitrate, samplerate, nb_channels, language, description, media_id) VALUES(?, ?, ?, ?, ?, ?, ?)"; + "(codec, bitrate, samplerate, nb_channels, language, description, media_id) VALUES(?, ?, ?, ?, ?, ?, ?)";
auto track = std::make_shared<AudioTrack>( codec, bitrate, sampleRate, nbChannels, language, desc, mediaId ); auto track = std::make_shared<AudioTrack>( ml, codec, bitrate, sampleRate, nbChannels, language, desc, mediaId );
if ( insert( ml, track, req, codec, bitrate, sampleRate, nbChannels, language, desc, mediaId ) == false ) if ( insert( ml, track, req, codec, bitrate, sampleRate, nbChannels, language, desc, mediaId ) == false )
return nullptr; return nullptr;
track->m_ml = ml;
return track; return track;
} }
...@@ -43,7 +43,7 @@ class AudioTrack : public IAudioTrack, public DatabaseHelpers<AudioTrack, policy ...@@ -43,7 +43,7 @@ class AudioTrack : public IAudioTrack, public DatabaseHelpers<AudioTrack, policy
{ {
public: public:
AudioTrack(MediaLibraryPtr ml, sqlite::Row& row ); AudioTrack(MediaLibraryPtr ml, sqlite::Row& row );
AudioTrack(const std::string& codec, unsigned int bitrate, unsigned int sampleRate, unsigned int nbChannels, const std::string& language, const std::string& desc , unsigned int mediaId); AudioTrack( MediaLibraryPtr ml, const std::string& codec, unsigned int bitrate, unsigned int sampleRate, unsigned int nbChannels, const std::string& language, const std::string& desc , unsigned int mediaId);
virtual unsigned int id() const override; virtual unsigned int id() const override;
virtual const std::string&codec() const override; virtual const std::string&codec() const override;
...@@ -59,7 +59,7 @@ class AudioTrack : public IAudioTrack, public DatabaseHelpers<AudioTrack, policy ...@@ -59,7 +59,7 @@ class AudioTrack : public IAudioTrack, public DatabaseHelpers<AudioTrack, policy
const std::string& language, const std::string& desc, unsigned int mediaId ); const std::string& language, const std::string& desc, unsigned int mediaId );
private: private:
MediaLibraryPtr m_ml; MediaLibraryPtr m_ml;
unsigned int m_id; unsigned int m_id;
std::string m_codec; std::string m_codec;
unsigned int m_bitrate; unsigned int m_bitrate;
......
...@@ -26,7 +26,7 @@ const std::string policy::DeviceTable::Name = "Device"; ...@@ -26,7 +26,7 @@ const std::string policy::DeviceTable::Name = "Device";
const std::string policy::DeviceTable::PrimaryKeyColumn = "id_device"; const std::string policy::DeviceTable::PrimaryKeyColumn = "id_device";
unsigned int Device::* const policy::DeviceTable::PrimaryKey = &Device::m_id; unsigned int Device::* const policy::DeviceTable::PrimaryKey = &Device::m_id;
Device::Device(MediaLibraryPtr ml, sqlite::Row& row ) Device::Device( MediaLibraryPtr ml, sqlite::Row& row )
: m_ml( ml ) : m_ml( ml )
{ {
row >> m_id row >> m_id
...@@ -37,8 +37,9 @@ Device::Device(MediaLibraryPtr ml, sqlite::Row& row ) ...@@ -37,8 +37,9 @@ Device::Device(MediaLibraryPtr ml, sqlite::Row& row )
//only be here for sqlite triggering purposes //only be here for sqlite triggering purposes
} }
Device::Device( const std::string& uuid, bool isRemovable ) Device::Device( MediaLibraryPtr ml, const std::string& uuid, bool isRemovable )
: m_uuid( uuid ) : m_ml( ml )
, m_uuid( uuid )
, m_isRemovable( isRemovable ) , m_isRemovable( isRemovable )
// Assume we can't add an absent device // Assume we can't add an absent device
, m_isPresent( true ) , m_isPresent( true )
...@@ -78,10 +79,9 @@ std::shared_ptr<Device> Device::create( MediaLibraryPtr ml, const std::string& u ...@@ -78,10 +79,9 @@ std::shared_ptr<Device> Device::create( MediaLibraryPtr ml, const std::string& u
{ {
static const std::string req = "INSERT INTO " + policy::DeviceTable::Name static const std::string req = "INSERT INTO " + policy::DeviceTable::Name
+ "(uuid, is_removable, is_present) VALUES(?, ?, ?)"; + "(uuid, is_removable, is_present) VALUES(?, ?, ?)";
auto self = std::make_shared<Device>( uuid, isRemovable ); auto self = std::make_shared<Device>( ml, uuid, isRemovable );
if ( insert( ml, self, req, uuid, isRemovable, self->isPresent() ) == false ) if ( insert( ml, self, req, uuid, isRemovable, self->isPresent() ) == false )
return nullptr; return nullptr;
self->m_ml = ml;
return self; return self;
} }
......
...@@ -40,7 +40,7 @@ struct DeviceTable ...@@ -40,7 +40,7 @@ struct DeviceTable
class Device : public DatabaseHelpers<Device, policy::DeviceTable> class Device : public DatabaseHelpers<Device, policy::DeviceTable>
{ {
public: public:
Device( const std::string& uuid, bool isRemovable ); Device( MediaLibraryPtr ml, const std::string& uuid, bool isRemovable );
Device( MediaLibraryPtr ml, sqlite::Row& row ); Device( MediaLibraryPtr ml, sqlite::Row& row );
unsigned int id() const; unsigned int id() const;
const std::string& uuid() const; const std::string& uuid() const;
......
...@@ -43,8 +43,9 @@ File::File( MediaLibraryPtr ml, sqlite::Row& row ) ...@@ -43,8 +43,9 @@ File::File( MediaLibraryPtr ml, sqlite::Row& row )
>> m_isRemovable; >> m_isRemovable;
} }
File::File( unsigned int mediaId, Type type, const fs::IFile& file, unsigned int folderId, bool isRemovable ) File::File( MediaLibraryPtr ml, unsigned int mediaId, Type type, const fs::IFile& file, unsigned int folderId, bool isRemovable )
: m_id( 0 ) : m_ml( ml )
, m_id( 0 )
, m_mediaId( mediaId ) , m_mediaId( mediaId )
, m_mrl( isRemovable == true ? file.name() : file.fullPath() ) , m_mrl( isRemovable == true ? file.name() : file.fullPath() )
, m_type( type ) , m_type( type )
...@@ -148,14 +149,13 @@ bool File::createTable( DBConnection dbConnection ) ...@@ -148,14 +149,13 @@ bool File::createTable( DBConnection dbConnection )
std::shared_ptr<File> File::create( MediaLibraryPtr ml, unsigned int mediaId, Type type, const fs::IFile& fileFs, unsigned int folderId, bool isRemovable ) std::shared_ptr<File> File::create( MediaLibraryPtr ml, unsigned int mediaId, Type type, const fs::IFile& fileFs, unsigned int folderId, bool isRemovable )
{ {
auto self = std::make_shared<File>( mediaId, type, fileFs, folderId, isRemovable ); auto self = std::make_shared<File>( ml, mediaId, type, fileFs, folderId, isRemovable );
static const std::string req = "INSERT INTO " + policy::FileTable::Name + static const std::string req = "INSERT INTO " + policy::FileTable::Name +
"(media_id, mrl, type, folder_id, last_modification_date, is_removable) VALUES(?, ?, ?, ?, ?, ?)"; "(media_id, mrl, type, folder_id, last_modification_date, is_removable) VALUES(?, ?, ?, ?, ?, ?)";
if ( insert( ml, self, req, mediaId, self->m_mrl, type, sqlite::ForeignKey( folderId ), if ( insert( ml, self, req, mediaId, self->m_mrl, type, sqlite::ForeignKey( folderId ),
self->m_lastModificationDate, isRemovable ) == false ) self->m_lastModificationDate, isRemovable ) == false )
return nullptr; return nullptr;
self->m_ml = ml;
self->m_fullPath = fileFs.fullPath(); self->m_fullPath = fileFs.fullPath();
return self; return self;
} }
...@@ -45,7 +45,7 @@ class File : public IFile, public DatabaseHelpers<File, policy::FileTable> ...@@ -45,7 +45,7 @@ class File : public IFile, public DatabaseHelpers<File, policy::FileTable>
{ {
public: public:
File( MediaLibraryPtr ml, sqlite::Row& row ); File( MediaLibraryPtr ml, sqlite::Row& row );
File( unsigned int mediaId, Type type, const fs::IFile& file, unsigned int folderId, bool isRemovable ); File(MediaLibraryPtr ml, unsigned int mediaId, Type type, const fs::IFile& file, unsigned int folderId, bool isRemovable );
virtual unsigned int id() const override; virtual unsigned int id() const override;
virtual const std::string& mrl() const override; virtual const std::string& mrl() const override;
virtual Type type() const override; virtual Type type() const override;
......
...@@ -53,8 +53,9 @@ Folder::Folder( MediaLibraryPtr ml, sqlite::Row& row ) ...@@ -53,8 +53,9 @@ Folder::Folder( MediaLibraryPtr ml, sqlite::Row& row )
>> m_isRemovable; >> m_isRemovable;
} }
Folder::Folder( const std::string& path, unsigned int parent, unsigned int deviceId, bool isRemovable ) Folder::Folder(MediaLibraryPtr ml, const std::string& path, unsigned int parent, unsigned int deviceId, bool isRemovable )
: m_id( 0 ) : m_ml( ml )
, m_id( 0 )
, m_path( path ) , m_path( path )
, m_parent( parent ) , m_parent( parent )
, m_isBlacklisted( false ) , m_isBlacklisted( false )
...@@ -97,12 +98,11 @@ std::shared_ptr<Folder> Folder::create( MediaLibraryPtr ml, const std::string& f ...@@ -97,12 +98,11 @@ std::shared_ptr<Folder> Folder::create( MediaLibraryPtr ml, const std::string& f
path = utils::file::removePath( fullPath, deviceFs.mountpoint() ); path = utils::file::removePath( fullPath, deviceFs.mountpoint() );
else else
path = fullPath; path = fullPath;
auto self = std::make_shared<Folder>( path, parentId, device.id(), device.isRemovable() ); auto self = std::make_shared<Folder>( ml, path, parentId, device.id(), device.isRemovable() );
static const std::string req = "INSERT INTO " + policy::FolderTable::Name + static const std::string req = "INSERT INTO " + policy::FolderTable::Name +
"(path, parent_id, device_id, is_removable) VALUES(?, ?, ?, ?)"; "(path, parent_id, device_id, is_removable) VALUES(?, ?, ?, ?)";
if ( insert( ml, self, req, path, sqlite::ForeignKey( parentId ), device.id(), device.isRemovable() ) == false ) if ( insert( ml, self, req, path, sqlite::ForeignKey( parentId ), device.id(), device.isRemovable() ) == false )
return nullptr; return nullptr;
self->m_ml = ml;
if ( device.isRemovable() == true ) if ( device.isRemovable() == true )
{ {
self->m_deviceMountpoint = deviceFs.mountpoint(); self->m_deviceMountpoint = deviceFs.mountpoint();
......
...@@ -54,8 +54,8 @@ struct FolderTable ...@@ -54,8 +54,8 @@ struct FolderTable
class Folder : public DatabaseHelpers<Folder, policy::FolderTable> class Folder : public DatabaseHelpers<Folder, policy::FolderTable>
{ {
public: public:
Folder(MediaLibraryPtr ml, sqlite::Row& row ); Folder( MediaLibraryPtr ml, sqlite::Row& row );
Folder( const std::string& path, unsigned int parent , unsigned int deviceId , bool isRemovable ); Folder( MediaLibraryPtr ml, const std::string& path, unsigned int parent , unsigned int deviceId , bool isRemovable );
static bool createTable( DBConnection connection ); static bool createTable( DBConnection connection );
static std::shared_ptr<Folder> create( MediaLibraryPtr ml, const std::string& path, unsigned int parentId, Device& device, fs::IDevice& deviceFs ); static std::shared_ptr<Folder> create( MediaLibraryPtr ml, const std::string& path, unsigned int parentId, Device& device, fs::IDevice& deviceFs );
......
...@@ -40,8 +40,9 @@ Genre::Genre( MediaLibraryPtr ml, sqlite::Row& row ) ...@@ -40,8 +40,9 @@ Genre::Genre( MediaLibraryPtr ml, sqlite::Row& row )
>> m_name; >> m_name;
} }
Genre::Genre( const std::string& name ) Genre::Genre( MediaLibraryPtr ml, const std::string& name )
: m_name( name ) : m_ml( ml )
, m_name( name )
{ {
} }
...@@ -108,10 +109,9 @@ std::shared_ptr<Genre> Genre::create( MediaLibraryPtr ml, const std::string& nam ...@@ -108,10 +109,9 @@ std::shared_ptr<Genre> Genre::create( MediaLibraryPtr ml, const std::string& nam
{ {
static const std::string req = "INSERT INTO " + policy::GenreTable::Name + "(name)" static const std::string req = "INSERT INTO " + policy::GenreTable::Name + "(name)"
"VALUES(?)"; "VALUES(?)";
auto self = std::make_shared<Genre>( name ); auto self = std::make_shared<Genre>( ml, name );
if ( insert( ml, self, req, name ) == false ) if ( insert( ml, self, req, name ) == false )
return nullptr; return nullptr;
self->m_ml = ml;
return self; return self;
} }
......
...@@ -42,7 +42,7 @@ class Genre : public IGenre, public DatabaseHelpers<Genre, policy::GenreTable> ...@@ -42,7 +42,7 @@ class Genre : public IGenre, public DatabaseHelpers<Genre, policy::GenreTable>
{ {
public: public:
Genre( MediaLibraryPtr ml, sqlite::Row& row ); Genre( MediaLibraryPtr ml, sqlite::Row& row );
Genre( const std::string& name ); Genre( MediaLibraryPtr ml, const std::string& name );
virtual unsigned int id() const; virtual unsigned int id() const;
virtual const std::string& name() const override; virtual const std::string& name() const override;
virtual std::vector<ArtistPtr> artists() const override; virtual std::vector<ArtistPtr> artists() const override;
......
...@@ -45,7 +45,7 @@ struct HistoryTable ...@@ -45,7 +45,7 @@ struct HistoryTable
class History : public IHistoryEntry, public DatabaseHelpers<History, policy::HistoryTable> class History : public IHistoryEntry, public DatabaseHelpers<History, policy::HistoryTable>
{ {
public: public:
History(MediaLibraryPtr ml, sqlite::Row& row ); History( MediaLibraryPtr ml, sqlite::Row& row );
static bool createTable( DBConnection dbConnection ); static bool createTable( DBConnection dbConnection );
static bool insert( DBConnection dbConn, const std::string& mrl ); static bool insert( DBConnection dbConn, const std::string& mrl );
static std::vector<std::shared_ptr<IHistoryEntry>> fetch( MediaLibraryPtr ml ); static std::vector<std::shared_ptr<IHistoryEntry>> fetch( MediaLibraryPtr ml );
......
...@@ -39,8 +39,9 @@ Label::Label(MediaLibraryPtr ml, sqlite::Row& row ) ...@@ -39,8 +39,9 @@ Label::Label(MediaLibraryPtr ml, sqlite::Row& row )
>> m_name; >> m_name;
} }
Label::Label( const std::string& name ) Label::Label( MediaLibraryPtr ml, const std::string& name )
: m_id( 0 ) : m_ml( ml )
, m_id( 0 )
, m_name( name ) , m_name( name )
{ {
} }
...@@ -65,11 +66,10 @@ std::vector<MediaPtr> Label::files() ...@@ -65,11 +66,10 @@ std::vector<MediaPtr> Label::files()
LabelPtr Label::create( MediaLibraryPtr ml, const std::string& name ) LabelPtr Label::create( MediaLibraryPtr ml, const std::string& name )
{ {
auto self = std::make_shared<Label>( name ); auto self = std::make_shared<Label>( ml, name );
const char* req = "INSERT INTO Label VALUES(NULL, ?)"; const char* req = "INSERT INTO Label VALUES(NULL, ?)";
if ( insert( ml, self, req, self->m_name ) == false ) if ( insert( ml, self, req, self->m_name ) == false )
return nullptr; return nullptr;
self->m_ml = ml;
return self; return self;
} }
......
...@@ -46,7 +46,7 @@ class Label : public ILabel, public DatabaseHelpers<Label, policy::LabelTable> ...@@ -46,7 +46,7 @@ class Label : public ILabel, public DatabaseHelpers<Label, policy::LabelTable>
{ {
public: public:
Label( MediaLibraryPtr ml, sqlite::Row& row ); Label( MediaLibraryPtr ml, sqlite::Row& row );
Label( const std::string& name ); Label( MediaLibraryPtr ml, const std::string& name );
public: public:
virtual unsigned int id() const override; virtual unsigned int id() const override;
......
...@@ -67,8 +67,9 @@ Media::Media( MediaLibraryPtr ml, sqlite::Row& row ) ...@@ -67,8 +67,9 @@ Media::Media( MediaLibraryPtr ml, sqlite::Row& row )
>> m_isPresent; >> m_isPresent;
} }
Media::Media( const std::string& title, Type type ) Media::Media( MediaLibraryPtr ml, const std::string& title, Type type )
: m_id( 0 ) : m_ml( ml )
, m_id( 0 )
, m_type( type ) , m_type( type )
, m_subType( SubType::Unknown ) , m_subType( SubType::Unknown )
, m_duration( -1 ) , m_duration( -1 )
...@@ -85,13 +86,12 @@ Media::Media( const std::string& title, Type type ) ...@@ -85,13 +86,12 @@ Media::Media( const std::string& title, Type type )
std::shared_ptr<Media> Media::create( MediaLibraryPtr ml, Type type, const fs::IFile& file ) std::shared_ptr<Media> Media::create( MediaLibraryPtr ml, Type type, const fs::IFile& file )
{ {
auto self = std::make_shared<Media>( file.name(), type ); auto self = std::make_shared<Media>( ml, file.name(), type );
static const std::string req = "INSERT INTO " + policy::MediaTable::Name + static const std::string req = "INSERT INTO " + policy::MediaTable::Name +
"(type, insertion_date, title) VALUES(?, ?, ?)"; "(type, insertion_date, title) VALUES(?, ?, ?)";
if ( insert( ml, self, req, type, self->m_insertionDate, self->m_title ) == false ) if ( insert( ml, self, req, type, self->m_insertionDate, self->m_title ) == false )
return nullptr; return nullptr;
self->m_ml = ml;
return self; return self;
} }
......
...@@ -56,8 +56,8 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable> ...@@ -56,8 +56,8 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
// ::new (pv) T(std::forward(args)...) // ::new (pv) T(std::forward(args)...)
// shall be well-formed, and private constructor would prevent that. // shall be well-formed, and private constructor would prevent that.
// There might be a way with a user-defined allocator, but we'll see that later... // There might be a way with a user-defined allocator, but we'll see that later...
Media(MediaLibraryPtr ml , sqlite::Row& row ); Media( MediaLibraryPtr ml , sqlite::Row& row );
Media( const std::string &title, Type type); Media( MediaLibraryPtr ml, const std::string &title, Type type);
static std::shared_ptr<Media> create( MediaLibraryPtr ml, Type type, const fs::IFile& file ); static std::shared_ptr<Media> create( MediaLibraryPtr ml, Type type, const fs::IFile& file );
static bool createTable( DBConnection connection ); static bool createTable( DBConnection connection );
......
...@@ -40,8 +40,9 @@ Movie::Movie(MediaLibraryPtr ml, sqlite::Row& row ) ...@@ -40,8 +40,9 @@ Movie::Movie(MediaLibraryPtr ml, sqlite::Row& row )
>> m_imdbId; >> m_imdbId;
} }
Movie::Movie( unsigned int mediaId, const std::string& title ) Movie::Movie( MediaLibraryPtr ml, unsigned int mediaId, const std::string& title )