[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [amarok] src: Refactoring preparation for StorageManager
From:       Ralf Engels <ralf-engels () gmx ! de>
Date:       2015-01-17 18:12:18
Message-ID: E1YCXr8-000431-Nx () scm ! kde ! org
[Download RAW message or body]

Git commit 044300b17d20a8cdd4337c9c43ea45ad39cdd757 by Ralf Engels.
Committed on 20/12/2014 at 22:24.
Pushed by rengels into branch 'master'.

Refactoring preparation for StorageManager

This commit is a preparation for the StorageManager functionality.
- remove useless sqlDatabasePriority
- add newStorage signal to CollectionFactory
- ensure that plugins are initialized in a correct order and
  the one with the storage goes first

M  +22   -6    src/PluginManager.cpp
M  +0    -2    src/core-impl/collections/db/sql/SqlCollectionFactory.cpp
M  +0    -7    src/core-impl/collections/db/sql/mysql-shared/MySqlStorage.cpp
M  +0    -6    src/core-impl/collections/db/sql/mysql-shared/MySqlStorage.h
M  +4    -0    src/core-impl/collections/db/sql/mysqlecollection/MySqlEmbeddedCollection.cpp
 M  +4    -0    src/core-impl/collections/db/sql/mysqlservercollection/MySqlServerCollection.cpp
 M  +4    -23   src/core-impl/collections/support/CollectionManager.cpp
M  +11   -0    src/core/collections/Collection.h
M  +1    -3    src/core/collections/support/SqlStorage.h

http://commits.kde.org/amarok/044300b17d20a8cdd4337c9c43ea45ad39cdd757

diff --git a/src/PluginManager.cpp b/src/PluginManager.cpp
index 7aa290f..a931456 100644
--- a/src/PluginManager.cpp
+++ b/src/PluginManager.cpp
@@ -131,8 +131,19 @@ Plugins::PluginManager::checkPluginEnabledStates()
         PluginFactory *factory = createFactory( pluginInfo );
         if( factory )
         {
-            m_factoriesByType[ type ] << factory;
-            allFactories << factory;
+            // the collection with the storage needs to go first.
+            QString pluginName = pluginInfo.pluginName();
+            if( pluginName == \
QLatin1String("amarok_collection-mysqlservercollection") || +                \
pluginName == QLatin1String("amarok_collection-mysqlecollection") ) +            {
+                m_factoriesByType[ type ].prepend( factory );
+                allFactories.prepend( factory );
+            }
+            else
+            {
+                m_factoriesByType[ type ] << factory;
+                allFactories << factory;
+            }
         }
     }
 
@@ -157,10 +168,14 @@ Plugins::PluginManager::checkPluginEnabledStates()
     // init all new factories
     // do this after they were added to the sub-manager so that they
     // have a chance to connect to signals
-    foreach( PluginFactory* factory, allFactories )
-    {
+    //
+    // we need to init by type and the storages need to go first
+    foreach( PluginFactory* factory, m_factoriesByType[ Collection ] )
+        factory->init();
+    foreach( PluginFactory* factory, m_factoriesByType[ Service ] )
+        factory->init();
+    foreach( PluginFactory* factory, m_factoriesByType[ Importer ] )
         factory->init();
-    }
 }
 
 
@@ -170,7 +185,8 @@ Plugins::PluginManager::isPluginEnabled( const KPluginInfo \
&pluginInfo ) const  const QString pluginName = pluginInfo.pluginName();
 
     // the sql collection is a core collection. It cannot be switched off
-    // and should be first.
+    // and needs to be first to be initialized since it's storage needs
+    // to be created before everything else
     const bool useMySqlServer = Amarok::config( "MySQL" ).readEntry( "UseServer", \
                false );
     if( pluginName == QLatin1String("amarok_collection-mysqlservercollection") )
     {
diff --git a/src/core-impl/collections/db/sql/SqlCollectionFactory.cpp \
b/src/core-impl/collections/db/sql/SqlCollectionFactory.cpp index b5ff584..36e595f \
                100644
--- a/src/core-impl/collections/db/sql/SqlCollectionFactory.cpp
+++ b/src/core-impl/collections/db/sql/SqlCollectionFactory.cpp
@@ -19,8 +19,6 @@
 #include "core-impl/collections/db/MountPointManager.h"
 #include "core-impl/collections/db/sql/SqlCollection.h"
 
-#include <KLocale>
-
 Collections::SqlCollectionFactory::SqlCollectionFactory()
 {
 }
diff --git a/src/core-impl/collections/db/sql/mysql-shared/MySqlStorage.cpp \
b/src/core-impl/collections/db/sql/mysql-shared/MySqlStorage.cpp index \
                1543725..1031c15 100644
--- a/src/core-impl/collections/db/sql/mysql-shared/MySqlStorage.cpp
+++ b/src/core-impl/collections/db/sql/mysql-shared/MySqlStorage.cpp
@@ -90,7 +90,6 @@ MySqlStorage::MySqlStorage()
     , m_db( 0 )
     , m_mutex( QMutex::Recursive )
     , m_debugIdent( "MySQL-none" )
-    , m_priority( 1 )
 {
     //Relevant code must be implemented in subclasses
 }
@@ -223,12 +222,6 @@ MySqlStorage::randomFunc() const
     return "RAND()";
 }
 
-int
-MySqlStorage::sqlDatabasePriority() const
-{
-    return m_priority;
-}
-
 QString
 MySqlStorage::boolTrue() const
 {
diff --git a/src/core-impl/collections/db/sql/mysql-shared/MySqlStorage.h \
b/src/core-impl/collections/db/sql/mysql-shared/MySqlStorage.h index c951ee1..c0a6ade \
                100644
--- a/src/core-impl/collections/db/sql/mysql-shared/MySqlStorage.h
+++ b/src/core-impl/collections/db/sql/mysql-shared/MySqlStorage.h
@@ -56,9 +56,6 @@ class MySqlStorage: public SqlStorage
         virtual QString longTextColumnType() const;
 
         virtual QString type() const = 0;
-        virtual int sqlDatabasePriority() const;
-
-        void setDatabasePriority( int priority ) { m_priority = priority; }
 
         /** Returns a list of the last sql errors.
             The list might not include every one error if the number
@@ -81,9 +78,6 @@ class MySqlStorage: public SqlStorage
 
         QString m_debugIdent;
         QStringList m_lastErrors;
-
-    private:
-        int m_priority;
 };
 
 #endif
diff --git a/src/core-impl/collections/db/sql/mysqlecollection/MySqlEmbeddedCollection.cpp \
b/src/core-impl/collections/db/sql/mysqlecollection/MySqlEmbeddedCollection.cpp index \
                957eaf7..b9872a8 100644
--- a/src/core-impl/collections/db/sql/mysqlecollection/MySqlEmbeddedCollection.cpp
+++ b/src/core-impl/collections/db/sql/mysqlecollection/MySqlEmbeddedCollection.cpp
@@ -30,11 +30,15 @@ AMAROK_EXPORT_COLLECTION( MySqlEmbeddedCollectionFactory, \
mysqlecollection )  void
 MySqlEmbeddedCollectionFactory::init()
 {
+    if( m_initialized )
+        return;
+
     SqlCollectionFactory fac;
     SqlStorage *storage = new MySqlEmbeddedStorage();
     SqlCollection *collection = fac.createSqlCollection( storage );
     m_initialized = true;
 
+    emit newStorage( storage );
     emit newCollection( collection );
 }
 
diff --git a/src/core-impl/collections/db/sql/mysqlservercollection/MySqlServerCollection.cpp \
b/src/core-impl/collections/db/sql/mysqlservercollection/MySqlServerCollection.cpp \
                index b44ef64..3763e0f 100644
--- a/src/core-impl/collections/db/sql/mysqlservercollection/MySqlServerCollection.cpp
                
+++ b/src/core-impl/collections/db/sql/mysqlservercollection/MySqlServerCollection.cpp
 @@ -37,11 +37,15 @@ AMAROK_EXPORT_COLLECTION( MySqlServerCollectionFactory, \
mysqlservercollection )  void
 MySqlServerCollectionFactory::init()
 {
+    if( m_initialized )
+        return;
+
     SqlCollectionFactory fac;
     SqlStorage *storage = new MySqlServerStorage();
     SqlCollection *collection = fac.createSqlCollection( storage );
     m_initialized = true;
 
+    emit newStorage( storage );
     emit newCollection( collection );
 }
 
diff --git a/src/core-impl/collections/support/CollectionManager.cpp \
b/src/core-impl/collections/support/CollectionManager.cpp index 3da0984..65a8fd3 \
                100644
--- a/src/core-impl/collections/support/CollectionManager.cpp
+++ b/src/core-impl/collections/support/CollectionManager.cpp
@@ -49,7 +49,6 @@ public:
         , m_sqlStorage( 0 )
     {}
 
-    virtual int sqlDatabasePriority() const { return ( m_sqlStorage ? \
                m_sqlStorage->sqlDatabasePriority() : 0 ); }
     virtual QString type() const  { return ( m_sqlStorage ? m_sqlStorage->type() : \
                "SqlStorageWrapper" ); }
     virtual QString escape( const QString &text ) const  { return ( m_sqlStorage ? \
                m_sqlStorage->escape( text ) : text ); }
     virtual QStringList query( const QString &query )  { return ( m_sqlStorage ? \
m_sqlStorage->query( query ) : QStringList() ); } @@ -337,21 +336,9 @@ \
CollectionManager::slotNewCollection( Collections::Collection* newCollection )  {
                 //let's cheat a bit and assume that sqlStorage and the \
primaryCollection are always the same  //it is true for now anyway
-                if( d->sqlDatabase )
-                {
-                    if( d->sqlDatabase->sqlDatabasePriority() < \
                sqlStorage->sqlDatabasePriority() )
-                    {
-                        d->sqlDatabase = sqlStorage;
-                        d->primaryCollection = newCollection;
-                        d->sqlStorageWrapper->setSqlStorage( sqlStorage );
-                    }
-                }
-                else
-                {
-                    d->sqlDatabase = sqlStorage;
-                    d->primaryCollection = newCollection;
-                    d->sqlStorageWrapper->setSqlStorage( sqlStorage );
-                }
+                d->sqlDatabase = sqlStorage;
+                d->primaryCollection = newCollection;
+                d->sqlStorageWrapper->setSqlStorage( sqlStorage );
             }
             else
             {
@@ -398,13 +385,7 @@ CollectionManager::slotRemoveCollection()
                         SqlStorage *sqlDb = variant.value<SqlStorage*>();
                         if( sqlDb )
                         {
-                            if( newSqlDatabase )
-                            {
-                                if( newSqlDatabase->sqlDatabasePriority() < \
                sqlDb->sqlDatabasePriority() )
-                                    newSqlDatabase = sqlDb;
-                            }
-                            else
-                                newSqlDatabase = sqlDb;
+                            newSqlDatabase = sqlDb;
                         }
                     }
                     d->sqlDatabase = newSqlDatabase;
diff --git a/src/core/collections/Collection.h b/src/core/collections/Collection.h
index c7091db..7770ec6 100644
--- a/src/core/collections/Collection.h
+++ b/src/core/collections/Collection.h
@@ -21,6 +21,7 @@
 #include "core/amarokcore_export.h"
 #include "core/interfaces/MetaCapability.h"
 #include "core/support/PluginFactory.h"
+#include "core/storage/SqlStorage.h"
 
 #include <QObject>
 
@@ -56,6 +57,16 @@ namespace Collections
         signals:
             void newCollection( Collections::Collection *newCollection );
 
+            /** Emitted whenever the factory produces a new storage.
+             *
+             *  This should usually happen only once before the creation
+             *  of the first primary (local) collection.
+             *
+             *  This function will disapper as soon as we have dedictated
+             *  StorageFactories.
+             */
+            void newStorage( SqlStorage *newStorage );
+
     };
 
     /** A TrackProvider is a class that can lookup urls and return Track objects.
diff --git a/src/core/collections/support/SqlStorage.h \
b/src/core/collections/support/SqlStorage.h index 68e9eb4..e8a78ac 100644
--- a/src/core/collections/support/SqlStorage.h
+++ b/src/core/collections/support/SqlStorage.h
@@ -30,9 +30,7 @@ class SqlStorage
 {
 public:
     SqlStorage() {}
-    virtual ~SqlStorage() {} 
-
-    virtual int sqlDatabasePriority() const = 0;
+    virtual ~SqlStorage() {}
 
     virtual QString type() const = 0;
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic