Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
VideoLAN
medialibrary
Commits
2126ce58
Commit
2126ce58
authored
Jan 04, 2016
by
Hugo Beauzée-Luyssen
Browse files
MediaLibrary: Split tables creation in a separate method
parent
73433d60
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/MediaLibrary.cpp
View file @
2126ce58
...
...
@@ -111,21 +111,11 @@ void MediaLibrary::setFsFactory(std::shared_ptr<factory::IFileSystem> fsFactory)
m_fsFactory
=
fsFactory
;
}
bool
MediaLibrary
::
initialize
(
const
std
::
string
&
dbPath
,
const
std
::
string
&
snapshotPath
,
IMediaLibraryCb
*
mlCallback
)
{
if
(
m_fsFactory
==
nullptr
)
m_fsFactory
.
reset
(
new
factory
::
FileSystemFactory
);
Folder
::
setFileSystemFactory
(
m_fsFactory
);
m_snapshotPath
=
snapshotPath
;
m_callback
=
mlCallback
;
m_dbConnection
.
reset
(
new
SqliteConnection
(
dbPath
)
);
bool
MediaLibrary
::
createAllTables
()
{
auto
t
=
m_dbConnection
->
newTransaction
();
// We need to create the tables in order of triggers creation
// Device is the "root of all evil". When a device is modified,
// we will trigger an update on folder, which will trigger
// an update on files, and so on.
if
(
(
Device
::
createTable
(
m_dbConnection
.
get
()
)
&&
auto
res
=
Device
::
createTable
(
m_dbConnection
.
get
()
)
&&
Folder
::
createTable
(
m_dbConnection
.
get
()
)
&&
Media
::
createTable
(
m_dbConnection
.
get
()
)
&&
Label
::
createTable
(
m_dbConnection
.
get
()
)
&&
...
...
@@ -140,7 +130,27 @@ bool MediaLibrary::initialize( const std::string& dbPath, const std::string& sna
Artist
::
createTable
(
m_dbConnection
.
get
()
)
&&
Artist
::
createDefaultArtists
(
m_dbConnection
.
get
()
)
&&
Artist
::
createTriggers
(
m_dbConnection
.
get
()
)
&&
Settings
::
createTable
(
m_dbConnection
.
get
()
)
)
==
false
)
Settings
::
createTable
(
m_dbConnection
.
get
()
);
if
(
res
==
false
)
return
false
;
t
->
commit
();
return
true
;
}
bool
MediaLibrary
::
initialize
(
const
std
::
string
&
dbPath
,
const
std
::
string
&
snapshotPath
,
IMediaLibraryCb
*
mlCallback
)
{
if
(
m_fsFactory
==
nullptr
)
m_fsFactory
.
reset
(
new
factory
::
FileSystemFactory
);
Folder
::
setFileSystemFactory
(
m_fsFactory
);
m_snapshotPath
=
snapshotPath
;
m_callback
=
mlCallback
;
m_dbConnection
.
reset
(
new
SqliteConnection
(
dbPath
)
);
// We need to create the tables in order of triggers creation
// Device is the "root of all evil". When a device is modified,
// we will trigger an update on folder, which will trigger
// an update on files, and so on.
if
(
createAllTables
()
==
false
)
{
LOG_ERROR
(
"Failed to create database structure"
);
return
false
;
...
...
@@ -150,7 +160,6 @@ bool MediaLibrary::initialize( const std::string& dbPath, const std::string& sna
// We only have one version so far, so a mismatching version is an error
if
(
m_settings
.
dbModelVersion
()
!=
DbModelVersion
)
return
false
;
t
->
commit
();
startDiscoverer
();
startParser
();
return
true
;
...
...
src/MediaLibrary.h
View file @
2126ce58
...
...
@@ -100,6 +100,7 @@ class MediaLibrary : public IMediaLibrary
void
addMetadataService
(
std
::
unique_ptr
<
IMetadataService
>
service
);
virtual
void
startParser
();
virtual
void
startDiscoverer
();
bool
createAllTables
();
protected:
std
::
unique_ptr
<
SqliteConnection
>
m_dbConnection
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment