[tracker/wip/carlosg/domain-ontologies: 46/55] libtracker-data: Make TrackerDBManager a non-singleton



commit 08ca512c8053b37af17b4f05680f0d71873f7de0
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Jun 9 03:44:21 2017 +0200

    libtracker-data: Make TrackerDBManager a non-singleton
    
    It's turned into a singleton pointer in tracker-data-manager.c atm,
    but now multiple DB managers pointing to different locations are
    possible.

 src/libtracker-data/libtracker-data.vapi        |    2 +-
 src/libtracker-data/tracker-data-backup.c       |   10 +-
 src/libtracker-data/tracker-data-manager.c      |   99 ++--
 src/libtracker-data/tracker-data-manager.h      |    3 +
 src/libtracker-data/tracker-data-query.c        |    4 +-
 src/libtracker-data/tracker-data-update.c       |   29 +-
 src/libtracker-data/tracker-db-backup.c         |    4 +-
 src/libtracker-data/tracker-db-manager.c        |  874 +++++++----------------
 src/libtracker-data/tracker-db-manager.h        |   69 +-
 src/libtracker-data/tracker-sparql-pattern.vala |    4 +-
 src/libtracker-data/tracker-sparql-query.vala   |    2 +-
 src/libtracker-direct/tracker-direct.vala       |    4 +-
 src/tracker-store/tracker-statistics.vala       |    2 +-
 src/tracker-store/tracker-store.vala            |    4 +-
 src/tracker/tracker-reset.c                     |   32 +-
 src/tracker/tracker-sql.c                       |    2 +-
 16 files changed, 415 insertions(+), 729 deletions(-)
---
diff --git a/src/libtracker-data/libtracker-data.vapi b/src/libtracker-data/libtracker-data.vapi
index 2e55d3a..007ffc2 100644
--- a/src/libtracker-data/libtracker-data.vapi
+++ b/src/libtracker-data/libtracker-data.vapi
@@ -86,7 +86,6 @@ namespace Tracker {
 
        [CCode (cheader_filename = "libtracker-data/tracker-db-manager.h")]
        namespace DBManager {
-               public unowned DBInterface get_db_interface ();
                public void lock ();
                public bool trylock ();
                public void unlock ();
@@ -233,6 +232,7 @@ namespace Tracker {
                public bool init (DBManagerFlags flags, GLib.File cache_location, GLib.File data_location, 
GLib.File ontology_location, out bool first_time, bool journal_check, bool restoring_backup, uint 
select_cache_size, uint update_cache_size, BusyCallback? busy_callback, string? busy_status) throws 
DBInterfaceError, DBJournalError;
                public void shutdown ();
                 public unowned Ontologies get_ontologies ();
+               public unowned DBInterface get_db_interface ();
        }
 
        [CCode (cheader_filename = "libtracker-data/tracker-db-interface-sqlite.h")]
diff --git a/src/libtracker-data/tracker-data-backup.c b/src/libtracker-data/tracker-data-backup.c
index c9899df..f291ecb 100644
--- a/src/libtracker-data/tracker-data-backup.c
+++ b/src/libtracker-data/tracker-data-backup.c
@@ -553,6 +553,7 @@ tracker_data_backup_restore (GFile                *journal,
 {
        BackupSaveInfo *info;
        GError *internal_error = NULL;
+       TrackerDBManager *db_manager = NULL;
 
        if (!cache_location || !data_location || !ontology_location) {
                g_set_error (error,
@@ -562,11 +563,12 @@ tracker_data_backup_restore (GFile                *journal,
                return;
        }
 
+       db_manager = tracker_data_manager_get_db_manager ();
        info = g_new0 (BackupSaveInfo, 1);
 #ifndef DISABLE_JOURNAL
        info->destination = g_file_get_child (data_location, TRACKER_DB_JOURNAL_FILENAME);
 #else
-       info->destination = g_file_new_for_path (tracker_db_manager_get_file (TRACKER_DB_METADATA));
+       info->destination = g_file_new_for_path (tracker_db_manager_get_file (db_manager));
 #endif /* DISABLE_JOURNAL */
 
        info->journal = g_object_ref (journal);
@@ -586,7 +588,7 @@ tracker_data_backup_restore (GFile                *journal,
                gint exit_status;
 #endif /* DISABLE_JOURNAL */
 
-               flags = tracker_db_manager_get_flags (&select_cache_size, &update_cache_size);
+               flags = tracker_db_manager_get_flags (db_manager, &select_cache_size, &update_cache_size);
 
                tracker_data_manager_shutdown ();
 
@@ -653,12 +655,12 @@ tracker_data_backup_restore (GFile                *journal,
                             &info->error);
 #endif /* DISABLE_JOURNAL */
 
-               tracker_db_manager_init_locations (cache_location, data_location);
+               tracker_db_manager_ensure_locations (db_manager, cache_location, data_location);
 
                /* Re-set the DB version file, so that its mtime changes. The mtime of this
                 * file will change only when the whole DB is recreated (after a hard reset
                 * or after a backup restoration). */
-               tracker_db_manager_create_version_file ();
+               tracker_db_manager_create_version_file (db_manager);
 
 #ifndef DISABLE_JOURNAL
                journal_writer = tracker_db_journal_new (data_location, FALSE, &n_error);
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 985b89e..8fcfd15 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -77,6 +77,7 @@ static TrackerDBJournal *journal_writer = NULL;
 static TrackerDBJournal *ontology_writer = NULL;
 #endif
 
+static TrackerDBManager *db_manager = NULL;
 static TrackerOntologies *ontologies = NULL;
 
 typedef struct {
@@ -127,7 +128,7 @@ handle_unsupported_ontology_change (const gchar  *ontology_path,
 {
 #ifndef DISABLE_JOURNAL
        /* force reindex on restart */
-       tracker_db_manager_remove_version_file ();
+       tracker_db_manager_remove_version_file (db_manager);
 #endif /* DISABLE_JOURNAL */
 
        g_set_error (error, TRACKER_DATA_ONTOLOGY_ERROR,
@@ -538,7 +539,7 @@ fix_indexed (TrackerProperty  *property,
        const gchar *service_name;
        const gchar *field_name;
 
-       iface = tracker_db_manager_get_db_interface ();
+       iface = tracker_db_manager_get_db_interface (db_manager);
 
        class = tracker_property_get_domain (property);
        field_name = tracker_property_get_name (property);
@@ -2439,7 +2440,7 @@ db_get_static_data (TrackerDBInterface  *iface,
                        tracker_property_set_is_inverse_functional_property (property, 
is_inverse_functional_property);
 
                        /* super properties are only used in updates, never for queries */
-                       if ((tracker_db_manager_get_flags (NULL, NULL) & TRACKER_DB_MANAGER_READONLY) == 0) {
+                       if ((tracker_db_manager_get_flags (db_manager, NULL, NULL) & 
TRACKER_DB_MANAGER_READONLY) == 0) {
                                property_add_super_properties_from_db (iface, property);
                        }
 
@@ -3362,7 +3363,7 @@ tracker_data_ontology_import_into_db (gboolean   in_update,
        TrackerProperty **properties;
        guint i, n_props, n_classes;
 
-       iface = tracker_db_manager_get_db_interface ();
+       iface = tracker_db_manager_get_db_interface (db_manager);
 
        classes = tracker_ontologies_get_classes (ontologies, &n_classes);
        properties = tracker_ontologies_get_properties (ontologies, &n_props);
@@ -3491,7 +3492,7 @@ get_new_service_id (TrackerDBInterface *iface)
        /* Don't intermix this thing with tracker_data_update_get_new_service_id,
         * if you use this, know what you are doing! */
 
-       iface = tracker_db_manager_get_db_interface ();
+       iface = tracker_db_manager_get_db_interface (db_manager);
 
        stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
                                                      "SELECT MAX(ID) AS A FROM Resource WHERE ID <= %d", 
TRACKER_ONTOLOGIES_MAX_ID);
@@ -3577,7 +3578,7 @@ tracker_data_manager_reload (TrackerBusyCallback   busy_callback,
 
        g_info ("Reloading data manager...");
        /* Shutdown data manager... */
-       flags = tracker_db_manager_get_flags (&select_cache_size, &update_cache_size);
+       flags = tracker_db_manager_get_flags (db_manager, &select_cache_size, &update_cache_size);
        reloading = TRUE;
        tracker_data_manager_shutdown ();
 
@@ -3703,7 +3704,7 @@ rebuild_fts_tokens (TrackerDBInterface *iface)
        g_debug ("FTS tokens rebuilt");
 
        /* Update the stamp file */
-       tracker_db_manager_tokenizer_update ();
+       tracker_db_manager_tokenizer_update (db_manager);
 }
 #endif
 
@@ -3813,18 +3814,19 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
        read_journal = FALSE;
 #endif
 
-       if (!tracker_db_manager_init (flags,
-                                     cache_location,
-                                     data_location,
-                                     &is_first_time_index,
-                                     restoring_backup,
-                                     FALSE,
-                                     select_cache_size,
-                                     update_cache_size,
-                                     busy_callback,
-                                     busy_user_data,
-                                     busy_operation,
-                                     &internal_error)) {
+       db_manager = tracker_db_manager_new (flags,
+                                            cache_location,
+                                            data_location,
+                                            &is_first_time_index,
+                                            restoring_backup,
+                                            FALSE,
+                                            select_cache_size,
+                                            update_cache_size,
+                                            busy_callback,
+                                            busy_user_data,
+                                            busy_operation,
+                                            &internal_error);
+       if (!db_manager) {
                g_propagate_error (error, internal_error);
 
                g_clear_object (&ontologies);
@@ -3847,7 +3849,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                *first_time = is_first_time_index;
        }
 
-       iface = tracker_db_manager_get_db_interface ();
+       iface = tracker_db_manager_get_db_interface (db_manager);
 
 #ifndef DISABLE_JOURNAL
        if (journal_check && is_first_time_index) {
@@ -3870,8 +3872,9 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                                              TRACKER_DB_JOURNAL_ERROR_BEGIN_OF_JOURNAL)) {
                                g_propagate_error (error, internal_error);
 
-                               tracker_db_manager_shutdown ();
+                               g_clear_pointer (&db_manager, tracker_db_manager_free);
                                g_clear_object (&ontologies);
+
                                tracker_data_update_shutdown ();
 
                                return FALSE;
@@ -3896,7 +3899,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                             TRACKER_DATA_ONTOLOGY_NOT_FOUND,
                             "'%s' is not a ontology location", uri);
                g_free (uri);
-               tracker_db_manager_shutdown ();
+               g_clear_pointer (&db_manager, tracker_db_manager_free);
                g_clear_object (&ontologies);
                tracker_data_update_shutdown ();
                return FALSE;
@@ -3920,7 +3923,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                                                          TRACKER_DB_JOURNAL_ERROR_BEGIN_OF_JOURNAL)) {
                                        g_propagate_error (error, internal_error);
 
-                                       tracker_db_manager_shutdown ();
+                                       g_clear_pointer (&db_manager, tracker_db_manager_free);
                                        g_clear_object (&ontologies);
                                        tracker_data_update_shutdown ();
 
@@ -3953,7 +3956,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                if (internal_error) {
                        g_propagate_error (error, internal_error);
 
-                       tracker_db_manager_shutdown ();
+                       g_clear_pointer (&db_manager, tracker_db_manager_free);
                        g_clear_object (&ontologies);
                        tracker_data_update_shutdown ();
 
@@ -3993,7 +3996,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                        tracker_db_journal_free (ontology_writer, NULL);
                        ontology_writer = NULL;
 #endif /* DISABLE_JOURNAL */
-                       tracker_db_manager_shutdown ();
+                       g_clear_pointer (&db_manager, tracker_db_manager_free);
                        g_clear_object (&ontologies);
                        tracker_data_update_shutdown ();
 
@@ -4012,7 +4015,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                        tracker_db_journal_free (ontology_writer, NULL);
                        ontology_writer = NULL;
 #endif /* DISABLE_JOURNAL */
-                       tracker_db_manager_shutdown ();
+                       g_clear_pointer (&db_manager, tracker_db_manager_free);
                        g_clear_object (&ontologies);
                        tracker_data_update_shutdown ();
 
@@ -4036,7 +4039,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 
                                        tracker_db_journal_free (ontology_writer, NULL);
                                        ontology_writer = NULL;
-                                       tracker_db_manager_shutdown ();
+                                       g_clear_pointer (&db_manager, tracker_db_manager_free);
                                        g_clear_object (&ontologies);
                                        tracker_data_update_shutdown ();
 
@@ -4055,7 +4058,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 
                if (internal_error) {
                        g_propagate_error (error, internal_error);
-                       tracker_db_manager_shutdown ();
+                       g_clear_pointer (&db_manager, tracker_db_manager_free);
                        g_clear_object (&ontologies);
 #ifndef DISABLE_JOURNAL
                        tracker_db_journal_free (ontology_writer, NULL);
@@ -4087,7 +4090,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                        if (internal_error) {
                                g_propagate_error (error, internal_error);
 
-                               tracker_db_manager_shutdown ();
+                               g_clear_pointer (&db_manager, tracker_db_manager_free);
                                g_clear_object (&ontologies);
                                tracker_data_update_shutdown ();
 
@@ -4245,7 +4248,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                                                        tracker_db_journal_free (ontology_writer, NULL);
                                                        ontology_writer = NULL;
 #endif /* DISABLE_JOURNAL */
-                                                       tracker_db_manager_shutdown ();
+                                                       g_clear_pointer (&db_manager, 
tracker_db_manager_free);
                                                        g_clear_object (&ontologies);
                                                        tracker_data_update_shutdown ();
 
@@ -4335,7 +4338,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                                                tracker_db_journal_free (ontology_writer, NULL);
                                                ontology_writer = NULL;
 #endif /* DISABLE_JOURNAL */
-                                               tracker_db_manager_shutdown ();
+                                               g_clear_pointer (&db_manager, tracker_db_manager_free);
                                                g_clear_object (&ontologies);
                                                tracker_data_update_shutdown ();
 
@@ -4516,7 +4519,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                                tracker_db_journal_free (ontology_writer, NULL);
                                ontology_writer = NULL;
 #endif /* DISABLE_JOURNAL */
-                               tracker_db_manager_shutdown ();
+                               g_clear_pointer (&db_manager, tracker_db_manager_free);
                                g_clear_object (&ontologies);
                                tracker_data_update_shutdown ();
 
@@ -4550,7 +4553,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                                tracker_db_journal_free (ontology_writer, NULL);
                                ontology_writer = NULL;
 #endif /* DISABLE_JOURNAL */
-                               tracker_db_manager_shutdown ();
+                               g_clear_pointer (&db_manager, tracker_db_manager_free);
                                g_clear_object (&ontologies);
                                tracker_data_update_shutdown ();
 
@@ -4584,8 +4587,8 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 
                        if (g_error_matches (internal_error, TRACKER_DB_INTERFACE_ERROR, 
TRACKER_DB_NO_SPACE)) {
                                GError *n_error = NULL;
-                               tracker_db_manager_remove_all ();
-                               tracker_db_manager_shutdown ();
+                               tracker_db_manager_remove_all (db_manager);
+                               g_clear_pointer (&db_manager, tracker_db_manager_free);
                                /* Call may fail without notice, we're in error handling already.
                                 * When fails it means that close() of journal file failed. */
                                if (n_error) {
@@ -4598,7 +4601,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                        g_hash_table_unref (uri_id_map);
                        g_propagate_error (error, internal_error);
 
-                       tracker_db_manager_shutdown ();
+                       g_clear_pointer (&db_manager, tracker_db_manager_free);
                        g_clear_object (&ontologies);
                        tracker_data_update_shutdown ();
 
@@ -4615,7 +4618,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
        if (internal_error) {
                g_propagate_error (error, internal_error);
 
-               tracker_db_manager_shutdown ();
+               g_clear_pointer (&db_manager, tracker_db_manager_free);
                g_clear_object (&ontologies);
                tracker_data_update_shutdown ();
 
@@ -4624,7 +4627,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 #endif /* DISABLE_JOURNAL */
 
        /* If locale changed, re-create indexes */
-       if (!read_only && tracker_db_manager_locale_changed (NULL)) {
+       if (!read_only && tracker_db_manager_locale_changed (db_manager, NULL)) {
                /* Report OPERATION - STATUS */
                busy_status = g_strdup_printf ("%s - %s",
                                               busy_operation,
@@ -4644,18 +4647,18 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 #ifndef DISABLE_JOURNAL
                        tracker_db_journal_free (journal_writer, NULL);
 #endif /* DISABLE_JOURNAL */
-                       tracker_db_manager_shutdown ();
+                       g_clear_pointer (&db_manager, tracker_db_manager_free);
                        g_clear_object (&ontologies);
                        tracker_data_update_shutdown ();
 
                        return FALSE;
                }
 
-               tracker_db_manager_set_current_locale ();
+               tracker_db_manager_set_current_locale (db_manager);
 
 #if HAVE_TRACKER_FTS
                rebuild_fts_tokens (iface);
-       } else if (!read_only && tracker_db_manager_get_tokenizer_changed ()) {
+       } else if (!read_only && tracker_db_manager_get_tokenizer_changed (db_manager)) {
                rebuild_fts_tokens (iface);
 #endif
        }
@@ -4699,7 +4702,7 @@ tracker_data_manager_shutdown (void)
        }
 #endif /* DISABLE_JOURNAL */
 
-       tracker_db_manager_shutdown ();
+       g_clear_pointer (&db_manager, tracker_db_manager_free);
        g_clear_object (&ontologies);
 
 #if HAVE_TRACKER_FTS
@@ -4732,3 +4735,15 @@ tracker_data_manager_get_ontologies (void)
 {
        return ontologies;
 }
+
+TrackerDBManager *
+tracker_data_manager_get_db_manager (void)
+{
+       return db_manager;
+}
+
+TrackerDBInterface *
+tracker_data_manager_get_db_interface (void)
+{
+       return tracker_db_manager_get_db_interface (db_manager);
+}
diff --git a/src/libtracker-data/tracker-data-manager.h b/src/libtracker-data/tracker-data-manager.h
index 47200d4..76771d3 100644
--- a/src/libtracker-data/tracker-data-manager.h
+++ b/src/libtracker-data/tracker-data-manager.h
@@ -74,6 +74,9 @@ TrackerDBJournal * tracker_data_manager_get_journal_writer (void);
 TrackerDBJournal * tracker_data_manager_get_ontology_writer (void);
 TrackerOntologies * tracker_data_manager_get_ontologies (void);
 
+TrackerDBManager * tracker_data_manager_get_db_manager (void);
+TrackerDBInterface * tracker_data_manager_get_db_interface (void);
+
 gboolean tracker_data_manager_init_fts               (TrackerDBInterface     *interface,
                                                      gboolean                create);
 
diff --git a/src/libtracker-data/tracker-data-query.c b/src/libtracker-data/tracker-data-query.c
index 79cde12..7de71ea 100644
--- a/src/libtracker-data/tracker-data-query.c
+++ b/src/libtracker-data/tracker-data-query.c
@@ -43,7 +43,7 @@ tracker_data_query_rdf_type (gint id)
        GError *error = NULL;
        TrackerOntologies *ontologies;
 
-       iface = tracker_db_manager_get_db_interface ();
+       iface = tracker_data_manager_get_db_interface ();
        ontologies = tracker_data_manager_get_ontologies ();
 
        stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
@@ -103,7 +103,7 @@ tracker_data_query_resource_id (const gchar *uri)
 
        g_return_val_if_fail (uri != NULL, 0);
 
-       iface = tracker_db_manager_get_db_interface ();
+       iface = tracker_data_manager_get_db_interface ();
 
        stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
                                                      "SELECT ID FROM Resource WHERE Uri = ?");
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 9206aa2..6477d74 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -358,7 +358,7 @@ tracker_data_update_get_new_service_id (void)
                        return ++max_ontology_id;
                }
 
-               iface = tracker_db_manager_get_db_interface ();
+               iface = tracker_data_manager_get_db_interface ();
 
                stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, 
&error,
                                                              "SELECT MAX(ID) AS A FROM Resource WHERE ID <= 
%d", TRACKER_ONTOLOGIES_MAX_ID);
@@ -389,7 +389,7 @@ tracker_data_update_get_new_service_id (void)
 
                max_service_id = TRACKER_ONTOLOGIES_MAX_ID;
 
-               iface = tracker_db_manager_get_db_interface ();
+               iface = tracker_data_manager_get_db_interface ();
 
                stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, 
&error,
                                                              "SELECT MAX(ID) AS A FROM Resource");
@@ -425,7 +425,7 @@ tracker_data_update_get_next_modseq (void)
        GError             *error = NULL;
        gint                max_modseq = 0;
 
-       temp_iface = tracker_db_manager_get_db_interface ();
+       temp_iface = tracker_data_manager_get_db_interface ();
 
        stmt = tracker_db_interface_create_statement (temp_iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, 
&error,
                                                      "SELECT MAX(\"tracker:modified\") AS A FROM 
\"rdfs:Resource\"");
@@ -639,7 +639,7 @@ ensure_resource_id (const gchar *uri,
        }
 
        if (id == 0) {
-               iface = tracker_db_manager_get_db_interface ();
+               iface = tracker_data_manager_get_db_interface ();
 
                id = tracker_data_update_get_new_service_id ();
                stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, 
&error,
@@ -729,7 +729,7 @@ tracker_data_resource_buffer_flush (GError **error)
        gint                            i, param;
        GError                         *actual_error = NULL;
 
-       iface = tracker_db_manager_get_db_interface ();
+       iface = tracker_data_manager_get_db_interface ();
 
        g_hash_table_iter_init (&iter, resource_buffer->tables);
        while (g_hash_table_iter_next (&iter, (gpointer*) &table_name, (gpointer*) &table)) {
@@ -1379,7 +1379,7 @@ get_property_values (TrackerProperty *property)
                table_name = tracker_property_get_table_name (property);
                field_name = tracker_property_get_name (property);
 
-               iface = tracker_db_manager_get_db_interface ();
+               iface = tracker_data_manager_get_db_interface ();
 
                stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, 
&error,
                                                              "SELECT \"%s\" FROM \"%s\" WHERE ID = ?",
@@ -1449,7 +1449,7 @@ get_old_property_values (TrackerProperty  *property,
                if (tracker_property_get_fulltext_indexed (property)) {
                        TrackerDBInterface *iface;
 
-                       iface = tracker_db_manager_get_db_interface ();
+                       iface = tracker_data_manager_get_db_interface ();
 
                        if (!resource_buffer->fts_updated && !resource_buffer->create) {
                                TrackerOntologies *ontologies;
@@ -2090,7 +2090,7 @@ cache_delete_resource_type_full (TrackerClass *class,
        GError             *error = NULL;
        TrackerOntologies  *ontologies;
 
-       iface = tracker_db_manager_get_db_interface ();
+       iface = tracker_data_manager_get_db_interface ();
        ontologies = tracker_data_manager_get_ontologies ();
 
        if (!single_type) {
@@ -3322,10 +3322,13 @@ void
 tracker_data_begin_transaction (GError **error)
 {
        TrackerDBInterface *iface;
+       TrackerDBManager *db_manager;
 
        g_return_if_fail (!in_transaction);
 
-       if (!tracker_db_manager_has_enough_space ()) {
+       db_manager = tracker_data_manager_get_db_manager ();
+
+       if (!tracker_db_manager_has_enough_space (db_manager)) {
                g_set_error (error, TRACKER_SPARQL_ERROR, TRACKER_SPARQL_ERROR_NO_SPACE,
                        "There is not enough space on the file system for update operations");
                return;
@@ -3348,7 +3351,7 @@ tracker_data_begin_transaction (GError **error)
                blank_buffer.table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
        }
 
-       iface = tracker_db_manager_get_db_interface ();
+       iface = tracker_data_manager_get_db_interface ();
 
        tracker_db_interface_execute_query (iface, NULL, "PRAGMA cache_size = %d", 
TRACKER_DB_CACHE_SIZE_UPDATE);
 
@@ -3392,7 +3395,7 @@ tracker_data_commit_transaction (GError **error)
 
        g_return_if_fail (in_transaction);
 
-       iface = tracker_db_manager_get_db_interface ();
+       iface = tracker_data_manager_get_db_interface ();
 
        tracker_data_update_buffer_flush (&actual_error);
        if (actual_error) {
@@ -3486,7 +3489,7 @@ tracker_data_rollback_transaction (void)
        in_transaction = FALSE;
        in_ontology_transaction = FALSE;
 
-       iface = tracker_db_manager_get_db_interface ();
+       iface = tracker_data_manager_get_db_interface ();
 
        tracker_data_update_buffer_clear ();
 
@@ -3639,7 +3642,7 @@ tracker_data_replay_journal (TrackerBusyCallback   busy_callback,
 
                        tracker_db_journal_reader_get_resource (reader, &id, &uri);
 
-                       iface = tracker_db_manager_get_db_interface ();
+                       iface = tracker_data_manager_get_db_interface ();
 
                        stmt = tracker_db_interface_create_statement (iface, 
TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &new_error,
                                                                      "INSERT INTO Resource (ID, Uri) VALUES 
(?, ?)");
diff --git a/src/libtracker-data/tracker-db-backup.c b/src/libtracker-data/tracker-db-backup.c
index 8a506e5..fc69bfe 100644
--- a/src/libtracker-data/tracker-db-backup.c
+++ b/src/libtracker-data/tracker-db-backup.c
@@ -87,6 +87,7 @@ backup_job (GTask        *task,
             GCancellable *cancellable)
 {
        BackupInfo *info = task_data;
+       TrackerDBManager *db_manager;
 
        const gchar *src_path;
        GFile *parent_file, *temp_file;
@@ -96,7 +97,8 @@ backup_job (GTask        *task,
        sqlite3 *temp_db = NULL;
        sqlite3_backup *backup = NULL;
 
-       src_path = tracker_db_manager_get_file (TRACKER_DB_METADATA);
+       db_manager = tracker_data_manager_get_db_manager ();
+       src_path = tracker_db_manager_get_file (db_manager);
        parent_file = g_file_get_parent (info->destination);
        temp_file = g_file_get_child (parent_file, TRACKER_DB_BACKUP_META_FILENAME_T);
        g_file_delete (temp_file, NULL, NULL);
diff --git a/src/libtracker-data/tracker-db-manager.c b/src/libtracker-data/tracker-db-manager.c
index 3d8d2c1..eb915d0 100644
--- a/src/libtracker-data/tracker-db-manager.c
+++ b/src/libtracker-data/tracker-db-manager.c
@@ -65,11 +65,6 @@
 #define PARSER_SHA1_FILENAME          "parser-sha1.txt"
 
 typedef enum {
-       TRACKER_DB_LOCATION_DATA_DIR,
-       TRACKER_DB_LOCATION_USER_DATA_DIR,
-} TrackerDBLocation;
-
-typedef enum {
        TRACKER_DB_VERSION_UNKNOWN, /* Unknown */
        TRACKER_DB_VERSION_0_6_6,   /* before indexer-split */
        TRACKER_DB_VERSION_0_6_90,  /* after  indexer-split */
@@ -98,8 +93,6 @@ typedef enum {
 } TrackerDBVersion;
 
 typedef struct {
-       TrackerDB           db;
-       TrackerDBLocation   location;
        TrackerDBInterface *iface;
        const gchar        *file;
        const gchar        *name;
@@ -111,72 +104,41 @@ typedef struct {
        guint64             mtime;
 } TrackerDBDefinition;
 
-static TrackerDBDefinition dbs[] = {
-       { TRACKER_DB_UNKNOWN,
-         TRACKER_DB_LOCATION_USER_DATA_DIR,
-         NULL,
-         NULL,
-         NULL,
-         NULL,
-         32,
-         TRACKER_DB_PAGE_SIZE_DONT_SET,
-         FALSE,
-         FALSE,
-         0 },
-       { TRACKER_DB_METADATA,
-         TRACKER_DB_LOCATION_DATA_DIR,
-         NULL,
-         "meta.db",
-         "meta",
-         NULL,
-         TRACKER_DB_CACHE_SIZE_DEFAULT,
-         8192,
-         FALSE,
-         FALSE,
-         0 },
+static TrackerDBDefinition db_base = {
+       NULL,
+       "meta.db",
+       "meta",
+       NULL,
+       TRACKER_DB_CACHE_SIZE_DEFAULT,
+       8192,
+       FALSE,
+       FALSE,
+       0
+};
+
+struct _TrackerDBManager {
+       TrackerDBDefinition db;
+       gboolean locations_initialized;
+       gchar *data_dir;
+       gchar *user_data_dir;
+       gchar *in_use_filename;
+       GFile *cache_location;
+       GFile *data_location;
+       TrackerDBManagerFlags flags;
+       guint s_cache_size;
+       guint u_cache_size;
 };
 
 static gboolean            db_exec_no_reply                        (TrackerDBInterface   *iface,
                                                                     const gchar          *query,
                                                                     ...);
-static TrackerDBInterface *db_interface_create                      (TrackerDB            db,
-                                                                     GError             **error);
-static TrackerDBInterface *tracker_db_manager_get_db_interfaces     (GError             **error,
+static TrackerDBInterface *tracker_db_manager_create_db_interface   (TrackerDBManager    *db_manager,
                                                                      gboolean             readonly,
-                                                                     gint                 num,
-                                                                     ...);
-static void                db_remove_locale_file                    (void);
-
-static gboolean              initialized;
-static gboolean              locations_initialized;
-static gchar                *data_dir = NULL;
-static gchar                *user_data_dir = NULL;
-static gchar                *in_use_filename = NULL;
-static GFile                *in_use_cache_location = NULL;
-static GFile                *in_use_data_location = NULL;
-static gpointer              db_type_enum_class_pointer;
-static TrackerDBManagerFlags old_flags = 0;
-static guint                 s_cache_size;
-static guint                 u_cache_size;
+                                                                     GError             **error);
+static void                db_remove_locale_file                    (TrackerDBManager    *db_manager);
 
 static GPrivate              interface_data_key = G_PRIVATE_INIT ((GDestroyNotify)g_object_unref);
 
-/* mutex protecting DB manager initialization/shutdown */
-static GMutex                init_mutex;
-
-static const gchar *
-location_to_directory (TrackerDBLocation location)
-{
-       switch (location) {
-       case TRACKER_DB_LOCATION_DATA_DIR:
-               return data_dir;
-       case TRACKER_DB_LOCATION_USER_DATA_DIR:
-               return user_data_dir;
-       default:
-               return NULL;
-       };
-}
-
 static gboolean
 db_exec_no_reply (TrackerDBInterface *iface,
                   const gchar        *query,
@@ -192,15 +154,17 @@ db_exec_no_reply (TrackerDBInterface *iface,
 }
 
 TrackerDBManagerFlags
-tracker_db_manager_get_flags (guint *select_cache_size, guint *update_cache_size)
+tracker_db_manager_get_flags (TrackerDBManager *db_manager,
+                              guint            *select_cache_size,
+                              guint            *update_cache_size)
 {
        if (select_cache_size)
-               *select_cache_size = s_cache_size;
+               *select_cache_size = db_manager->s_cache_size;
 
        if (update_cache_size)
-               *update_cache_size = u_cache_size;
+               *update_cache_size = db_manager->u_cache_size;
 
-       return old_flags;
+       return db_manager->flags;
 }
 
 static void
@@ -268,151 +232,36 @@ db_set_params (TrackerDBInterface   *iface,
        g_info ("  Setting cache size to %d", cache_size);
 }
 
-
-static const gchar *
-db_type_to_string (TrackerDB db)
-{
-       GType       type;
-       GEnumClass *enum_class;
-       GEnumValue *enum_value;
-
-       type = tracker_db_get_type ();
-       enum_class = G_ENUM_CLASS (g_type_class_peek (type));
-       enum_value = g_enum_get_value (enum_class, db);
-
-       if (!enum_value) {
-               return "unknown";
-       }
-
-       return enum_value->value_nick;
-}
-
-static TrackerDBInterface *
-db_interface_get (TrackerDB   type,
-                  gboolean   *create,
-                  GError    **error)
-{
-       TrackerDBInterface *iface;
-       const gchar *path;
-       GError *internal_error = NULL;
-
-       path = dbs[type].abs_filename;
-
-       if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
-               *create = TRUE;
-       } else {
-               *create = FALSE;
-       }
-
-       g_info ("%s database... '%s' (%s)",
-               *create ? "Creating" : "Loading",
-               path,
-               db_type_to_string (type));
-
-       iface = tracker_db_interface_sqlite_new (path, FALSE,
-                                                &internal_error);
-
-       if (internal_error) {
-               g_propagate_error (error, internal_error);
-               return NULL;
-       }
-
-       db_set_params (iface,
-                      dbs[type].cache_size,
-                      dbs[type].page_size,
-                      TRUE,
-                      &internal_error);
-
-       if (internal_error) {
-               g_propagate_error (error, internal_error);
-               g_object_unref (iface);
-               return NULL;
-       }
-
-       return iface;
-}
-
-static TrackerDBInterface *
-db_interface_get_metadata (GError **error)
-{
-       TrackerDBInterface *iface;
-       gboolean create;
-       GError *internal_error = NULL;
-
-       iface = db_interface_get (TRACKER_DB_METADATA, &create, &internal_error);
-
-       if (internal_error) {
-               g_propagate_error (error, internal_error);
-               return NULL;
-       }
-
-       return iface;
-}
-
-static TrackerDBInterface *
-db_interface_create (TrackerDB db,
-                     GError **error)
-{
-       TrackerDBInterface *iface;
-       GError *internal_error = NULL;
-
-       switch (db) {
-       case TRACKER_DB_UNKNOWN:
-               return NULL;
-
-       case TRACKER_DB_METADATA:
-               iface = db_interface_get_metadata (&internal_error);
-               if (internal_error) {
-                       g_propagate_error (error, internal_error);
-                       return NULL;
-               }
-               return iface;
-
-       default:
-               g_critical ("This TrackerDB type:%d->'%s' has no interface set up yet!!",
-                           db,
-                           db_type_to_string (db));
-               return NULL;
-       }
-}
-
-static void
-db_manager_remove_all (void)
+void
+tracker_db_manager_remove_all (TrackerDBManager *db_manager)
 {
-       guint i;
+       gchar *filename;
 
        g_info ("Removing all database/storage files");
 
-       /* NOTE: We don't have to be initialized for this so we
-        * calculate the absolute directories here.
-        */
-       for (i = 1; i < G_N_ELEMENTS (dbs); i++) {
-               gchar *filename;
-
-               g_info ("  Removing database:'%s'", dbs[i].abs_filename);
-               g_unlink (dbs[i].abs_filename);
+       g_info ("  Removing database:'%s'", db_manager->db.abs_filename);
+       g_unlink (db_manager->db.abs_filename);
 
-               /* also delete shm and wal helper files */
-               filename = g_strdup_printf ("%s-shm", dbs[i].abs_filename);
-               g_unlink (filename);
-               g_free (filename);
+       /* also delete shm and wal helper files */
+       filename = g_strdup_printf ("%s-shm", db_manager->db.abs_filename);
+       g_unlink (filename);
+       g_free (filename);
 
-               filename = g_strdup_printf ("%s-wal", dbs[i].abs_filename);
-               g_unlink (filename);
-               g_free (filename);
-       }
+       filename = g_strdup_printf ("%s-wal", db_manager->db.abs_filename);
+       g_unlink (filename);
+       g_free (filename);
 
        /* Remove locale file also */
-       db_remove_locale_file ();
+       db_remove_locale_file (db_manager);
 }
 
 static TrackerDBVersion
-db_get_version (void)
+db_get_version (TrackerDBManager *db_manager)
 {
        TrackerDBVersion  version;
        gchar            *filename;
 
-       filename = g_build_filename (data_dir, TRACKER_DB_VERSION_FILE, NULL);
+       filename = g_build_filename (db_manager->data_dir, TRACKER_DB_VERSION_FILE, NULL);
 
        if (G_LIKELY (g_file_test (filename, G_FILE_TEST_EXISTS))) {
                gchar *contents;
@@ -446,13 +295,13 @@ db_get_version (void)
 }
 
 void
-tracker_db_manager_create_version_file (void)
+tracker_db_manager_create_version_file (TrackerDBManager *db_manager)
 {
        GError *error = NULL;
        gchar  *filename;
        gchar  *str;
 
-       filename = g_build_filename (data_dir, TRACKER_DB_VERSION_FILE, NULL);
+       filename = g_build_filename (db_manager->data_dir, TRACKER_DB_VERSION_FILE, NULL);
        g_info ("  Creating version file '%s'", filename);
 
        str = g_strdup_printf ("%d", TRACKER_DB_VERSION_NOW);
@@ -468,34 +317,34 @@ tracker_db_manager_create_version_file (void)
 }
 
 void
-tracker_db_manager_remove_version_file (void)
+tracker_db_manager_remove_version_file (TrackerDBManager *db_manager)
 {
        gchar *filename;
 
-       filename = g_build_filename (data_dir, TRACKER_DB_VERSION_FILE, NULL);
+       filename = g_build_filename (db_manager->data_dir, TRACKER_DB_VERSION_FILE, NULL);
        g_info ("  Removing db-version file:'%s'", filename);
        g_unlink (filename);
        g_free (filename);
 }
 
 static void
-db_remove_locale_file (void)
+db_remove_locale_file (TrackerDBManager *db_manager)
 {
        gchar *filename;
 
-       filename = g_build_filename (data_dir, TRACKER_DB_LOCALE_FILE, NULL);
+       filename = g_build_filename (db_manager->data_dir, TRACKER_DB_LOCALE_FILE, NULL);
        g_info ("  Removing db-locale file:'%s'", filename);
        g_unlink (filename);
        g_free (filename);
 }
 
 static gchar *
-db_get_locale (void)
+db_get_locale (TrackerDBManager *db_manager)
 {
        gchar *locale = NULL;
        gchar *filename;
 
-       filename = g_build_filename (data_dir, TRACKER_DB_LOCALE_FILE, NULL);
+       filename = g_build_filename (db_manager->data_dir, TRACKER_DB_LOCALE_FILE, NULL);
 
        if (G_LIKELY (g_file_test (filename, G_FILE_TEST_EXISTS))) {
                gchar *contents;
@@ -524,13 +373,14 @@ db_get_locale (void)
 }
 
 static void
-db_set_locale (const gchar *locale)
+db_set_locale (TrackerDBManager *db_manager,
+              const gchar      *locale)
 {
        GError *error = NULL;
        gchar  *filename;
        gchar  *str;
 
-       filename = g_build_filename (data_dir, TRACKER_DB_LOCALE_FILE, NULL);
+       filename = g_build_filename (db_manager->data_dir, TRACKER_DB_LOCALE_FILE, NULL);
        g_info ("  Creating locale file '%s'", filename);
 
        str = g_strdup_printf ("%s", locale ? locale : "");
@@ -546,7 +396,8 @@ db_set_locale (const gchar *locale)
 }
 
 gboolean
-tracker_db_manager_locale_changed (GError **error)
+tracker_db_manager_locale_changed (TrackerDBManager  *db_manager,
+                                   GError           **error)
 {
        gchar *db_locale;
        gchar *current_locale;
@@ -556,15 +407,13 @@ tracker_db_manager_locale_changed (GError **error)
         * tracker_data_manager_init() has been called, so it can be used
         * to check for locale mismatches for initializing the database.
         */
-       if (!locations_initialized) {
-               tracker_db_manager_init_locations (in_use_cache_location, in_use_data_location);
-       }
+       tracker_db_manager_ensure_locations (db_manager, db_manager->cache_location, 
db_manager->data_location);
 
        /* Get current collation locale */
        current_locale = tracker_locale_get (TRACKER_LOCALE_COLLATE);
 
        /* Get db locale */
-       db_locale = db_get_locale ();
+       db_locale = db_get_locale (db_manager);
 
        /* If they are different, recreate indexes. Note that having
         * both to NULL is actually valid, they would default to
@@ -588,56 +437,39 @@ tracker_db_manager_locale_changed (GError **error)
 }
 
 void
-tracker_db_manager_set_current_locale (void)
+tracker_db_manager_set_current_locale (TrackerDBManager *db_manager)
 {
        gchar *current_locale;
 
        /* Get current collation locale */
        current_locale = tracker_locale_get (TRACKER_LOCALE_COLLATE);
        g_info ("Saving DB locale as: '%s'", current_locale);
-       db_set_locale (current_locale);
+       db_set_locale (db_manager, current_locale);
        g_free (current_locale);
 }
 
 static void
-db_manager_analyze (TrackerDB           db,
+db_manager_analyze (TrackerDBManager   *db_manager,
                     TrackerDBInterface *iface)
 {
        guint64             current_mtime;
 
-       current_mtime = tracker_file_get_mtime (dbs[db].abs_filename);
+       current_mtime = tracker_file_get_mtime (db_manager->db.abs_filename);
 
-       if (current_mtime > dbs[db].mtime) {
-               g_info ("  Analyzing DB:'%s'", dbs[db].name);
-               db_exec_no_reply (iface, "ANALYZE %s.Services", dbs[db].name);
+       if (current_mtime > db_manager->db.mtime) {
+               g_info ("  Analyzing DB:'%s'", db_manager->db.name);
+               db_exec_no_reply (iface, "ANALYZE %s.Services", db_manager->db.name);
 
                /* Remember current mtime for future */
-               dbs[db].mtime = current_mtime;
+               db_manager->db.mtime = current_mtime;
        } else {
-               g_info ("  Not updating DB:'%s', no changes since last optimize", dbs[db].name);
-       }
-}
-
-GType
-tracker_db_get_type (void)
-{
-       static GType etype = 0;
-
-       if (etype == 0) {
-               static const GEnumValue values[] = {
-                       { TRACKER_DB_METADATA,
-                         "TRACKER_DB_METADATA",
-                         "metadata" },
-               };
-
-               etype = g_enum_register_static ("TrackerDB", values);
+               g_info ("  Not updating DB:'%s', no changes since last optimize", db_manager->db.name);
        }
-
-       return etype;
 }
 
 static void
-db_recreate_all (GError **error)
+db_recreate_all (TrackerDBManager  *db_manager,
+                GError           **error)
 {
        guint i;
        gchar *locale;
@@ -649,69 +481,54 @@ db_recreate_all (GError **error)
         */
        g_info ("Cleaning up database files for reindex");
 
-       db_manager_remove_all ();
+       tracker_db_manager_remove_all (db_manager);
 
        /* Now create the databases and close them */
        g_info ("Creating database files, this may take a few moments...");
 
-       for (i = 1; i < G_N_ELEMENTS (dbs); i++) {
-               dbs[i].iface = db_interface_create (i, &internal_error);
-               if (internal_error) {
-                       guint y;
-
-                       for (y = 1; y < i; y++) {
-                               g_object_unref (dbs[y].iface);
-                               dbs[y].iface = NULL;
-                       }
-
-                       g_propagate_error (error, internal_error);
-
-                       return;
-               }
+       db_manager->db.iface = tracker_db_manager_create_db_interface (db_manager, FALSE, &internal_error);
+       if (internal_error) {
+               g_propagate_error (error, internal_error);
+               return;
        }
 
-       /* We don't close the dbs in the same loop as before
-        * becase some databases need other databases
-        * attached to be created correctly.
-        */
-       for (i = 1; i < G_N_ELEMENTS (dbs); i++) {
-               g_object_unref (dbs[i].iface);
-               dbs[i].iface = NULL;
-       }
+       g_clear_object (&db_manager->db.iface);
 
        locale = tracker_locale_get (TRACKER_LOCALE_COLLATE);
        /* Initialize locale file */
-       db_set_locale (locale);
+       db_set_locale (db_manager, locale);
        g_free (locale);
 }
 
 void
-tracker_db_manager_init_locations (GFile *cache_location,
-                                   GFile *data_location)
+tracker_db_manager_ensure_locations (TrackerDBManager *db_manager,
+                                     GFile            *cache_location,
+                                     GFile            *data_location)
 {
-       const gchar *dir;
-       guint i;
+       gchar *dir;
 
-       if (locations_initialized) {
+       if (db_manager->locations_initialized) {
                return;
        }
 
-       data_dir = g_file_get_path (cache_location);
+       db_manager->locations_initialized = TRUE;
+       db_manager->data_dir = g_file_get_path (cache_location);
 
        /* For DISABLE_JOURNAL case we should use g_get_user_data_dir here. For now
         * keeping this as-is */
-       user_data_dir = g_file_get_path (data_location);
+       db_manager->user_data_dir = g_file_get_path (data_location);
 
-       for (i = 1; i < G_N_ELEMENTS (dbs); i++) {
-               dir = location_to_directory (dbs[i].location);
-               dbs[i].abs_filename = g_build_filename (dir, dbs[i].file, NULL);
-       }
+       db_manager->db = db_base;
 
-       locations_initialized = TRUE;
+       dir = g_file_get_path (cache_location);
+       db_manager->db.abs_filename = g_build_filename (dir, db_manager->db.file, NULL);
+       g_free (dir);
 }
 
 static void
-perform_recreate (gboolean *first_time, GError **error)
+perform_recreate (TrackerDBManager  *db_manager,
+                 gboolean          *first_time,
+                 GError           **error)
 {
        GError *internal_error = NULL;
        guint i;
@@ -720,14 +537,9 @@ perform_recreate (gboolean *first_time, GError **error)
                *first_time = TRUE;
        }
 
-       for (i = 1; i < G_N_ELEMENTS (dbs); i++) {
-               if (dbs[i].iface) {
-                       g_object_unref (dbs[i].iface);
-                       dbs[i].iface = NULL;
-               }
-       }
+       g_clear_object (&db_manager->db.iface);
 
-       if (!tracker_file_system_has_enough_space (data_dir, TRACKER_DB_MIN_REQUIRED_SPACE, TRUE)) {
+       if (!tracker_file_system_has_enough_space (db_manager->data_dir, TRACKER_DB_MIN_REQUIRED_SPACE, 
TRUE)) {
                g_set_error (error,
                             TRACKER_DB_INTERFACE_ERROR,
                             TRACKER_DB_OPEN_ERROR,
@@ -735,28 +547,28 @@ perform_recreate (gboolean *first_time, GError **error)
                return;
        }
 
-       db_recreate_all (&internal_error);
+       db_recreate_all (db_manager, &internal_error);
 
        if (internal_error) {
                g_propagate_error (error, internal_error);
        }
 }
 
-static gboolean
-db_manager_init_unlocked (TrackerDBManagerFlags   flags,
-                          GFile                  *cache_location,
-                          GFile                  *data_location,
-                          gboolean               *first_time,
-                          gboolean                restoring_backup,
-                          gboolean                shared_cache,
-                          guint                   select_cache_size,
-                          guint                   update_cache_size,
-                          TrackerBusyCallback     busy_callback,
-                          gpointer                busy_user_data,
-                          const gchar            *busy_operation,
-                          GError                **error)
+TrackerDBManager *
+tracker_db_manager_new (TrackerDBManagerFlags   flags,
+                       GFile                  *cache_location,
+                       GFile                  *data_location,
+                       gboolean               *first_time,
+                       gboolean                restoring_backup,
+                       gboolean                shared_cache,
+                       guint                   select_cache_size,
+                       guint                   update_cache_size,
+                       TrackerBusyCallback     busy_callback,
+                       gpointer                busy_user_data,
+                       const gchar            *busy_operation,
+                       GError                **error)
 {
-       GType etype;
+       TrackerDBManager *db_manager;
        TrackerDBVersion version;
        gboolean need_reindex;
        guint i;
@@ -765,43 +577,35 @@ db_manager_init_unlocked (TrackerDBManagerFlags   flags,
        TrackerDBInterface *resources_iface;
        GError *internal_error = NULL;
 
+       if (!cache_location || !data_location) {
+               g_set_error (error,
+                            TRACKER_DATA_ONTOLOGY_ERROR,
+                            TRACKER_DATA_UNSUPPORTED_LOCATION,
+                            "All data storage and ontology locations must be provided");
+               return NULL;
+       }
+
+       db_manager = g_new0 (TrackerDBManager, 1);
+
        /* First set defaults for return values */
        if (first_time) {
                *first_time = FALSE;
        }
 
-       if (initialized) {
-               return TRUE;
-       }
-
        need_reindex = FALSE;
 
-       /* Since we don't reference this enum anywhere, we do
-        * it here to make sure it exists when we call
-        * g_type_class_peek(). This wouldn't be necessary if
-        * it was a param in a GObject for example.
-        *
-        * This does mean that we are leaking by 1 reference
-        * here and should clean it up, but it doesn't grow so
-        * this is acceptable.
-        */
-       etype = tracker_db_get_type ();
-       db_type_enum_class_pointer = g_type_class_ref (etype);
-
        /* Set up locations */
        g_info ("Setting database locations");
 
-       old_flags = flags;
+       db_manager->flags = flags;
 
-       g_set_object (&in_use_cache_location, cache_location);
-       g_set_object (&in_use_data_location, data_location);
+       g_set_object (&db_manager->cache_location, cache_location);
+       g_set_object (&db_manager->data_location, data_location);
 
-       tracker_db_manager_init_locations (cache_location, data_location);
-
-       g_free (in_use_filename);
-       in_use_filename = g_build_filename (user_data_dir,
-                                           IN_USE_FILENAME,
-                                           NULL);
+       tracker_db_manager_ensure_locations (db_manager, cache_location, data_location);
+       db_manager->in_use_filename = g_build_filename (db_manager->user_data_dir,
+                                                       IN_USE_FILENAME,
+                                                       NULL);
 
        /* Don't do need_reindex checks for readonly (direct-access) */
        if ((flags & TRACKER_DB_MANAGER_READONLY) == 0) {
@@ -809,12 +613,12 @@ db_manager_init_unlocked (TrackerDBManagerFlags   flags,
                /* Make sure the directories exist */
                g_info ("Checking database directories exist");
 
-               g_mkdir_with_parents (data_dir, 00755);
-               g_mkdir_with_parents (user_data_dir, 00755);
+               g_mkdir_with_parents (db_manager->data_dir, 00755);
+               g_mkdir_with_parents (db_manager->user_data_dir, 00755);
 
                g_info ("Checking database version");
 
-               version = db_get_version ();
+               version = db_get_version (db_manager);
 
                if (version < TRACKER_DB_VERSION_NOW) {
                        g_info ("  A reindex will be forced");
@@ -822,50 +626,36 @@ db_manager_init_unlocked (TrackerDBManagerFlags   flags,
                }
 
                if (need_reindex) {
-                       tracker_db_manager_create_version_file ();
+                       tracker_db_manager_create_version_file (db_manager);
                }
        }
 
-       g_info ("Checking database files exist");
-
-       for (i = 1; i < G_N_ELEMENTS (dbs); i++) {
-               /* Check we have each database in place, if one is
-                * missing, we reindex.
-                */
+       g_info ("Checking whether database files exist");
 
+       /* Check we have the database in place, if it is
+        * missing, we reindex.
+        *
+        * There's no need to check for files not existing (for
+        * reindex) if reindexing is already needed.
+        */
+       if (!need_reindex &&
+           (flags & TRACKER_DB_MANAGER_READONLY) == 0 &&
+           !g_file_test (db_manager->db.abs_filename, G_FILE_TEST_EXISTS)) {
                if ((flags & TRACKER_DB_MANAGER_READONLY) == 0) {
-                       /* No need to check for other files not existing (for
-                        * reindex) if one is already missing.
-                        */
-                       if (need_reindex) {
-                               continue;
-                       }
-               }
-
-               if (!g_file_test (dbs[i].abs_filename, G_FILE_TEST_EXISTS)) {
-                       if ((flags & TRACKER_DB_MANAGER_READONLY) == 0) {
-                               g_info ("Could not find database file:'%s'", dbs[i].abs_filename);
-                               g_info ("One or more database files are missing, a reindex will be forced");
-                               need_reindex = TRUE;
-                       } else {
-                               guint y;
-
-                               g_set_error (error,
-                                            TRACKER_DB_INTERFACE_ERROR,
-                                            TRACKER_DB_OPEN_ERROR,
-                                            "Could not find database file:'%s'. One or more database files 
are missing", dbs[i].abs_filename);
-
-                               for (y = 1; y <= i; y++) {
-                                       g_free (dbs[y].abs_filename);
-                                       dbs[y].abs_filename = NULL;
-                               }
+                       g_info ("Could not find database file:'%s', reindex will be forced", 
db_manager->db.abs_filename);
+                       need_reindex = TRUE;
+               } else {
+                       g_set_error (error,
+                                    TRACKER_DB_INTERFACE_ERROR,
+                                    TRACKER_DB_OPEN_ERROR,
+                                    "Could not find database file:'%s'.", db_manager->db.abs_filename);
 
-                               return FALSE;
-                       }
+                       tracker_db_manager_free (db_manager);
+                       return NULL;
                }
        }
 
-       locations_initialized = TRUE;
+       db_manager->locations_initialized = TRUE;
 
        /* Don't do remove-dbs for readonly (direct-access) */
        if ((flags & TRACKER_DB_MANAGER_READONLY) == 0) {
@@ -874,8 +664,7 @@ db_manager_init_unlocked (TrackerDBManagerFlags   flags,
                 * return here.
                 */
                if ((flags & TRACKER_DB_MANAGER_REMOVE_ALL) != 0) {
-                       initialized = TRUE;
-                       return TRUE;
+                       return db_manager;
                }
        }
 
@@ -899,14 +688,16 @@ db_manager_init_unlocked (TrackerDBManagerFlags   flags,
                                     TRACKER_DB_OPEN_ERROR,
                                     "No reindexing supported in read-only mode (direct access)");
 
-                       return FALSE;
+                       tracker_db_manager_free (db_manager);
+                       return NULL;
                }
 
-               perform_recreate (first_time, &internal_error);
+               perform_recreate (db_manager, first_time, &internal_error);
 
                if (internal_error) {
                        g_propagate_error (error, internal_error);
-                       return FALSE;
+                       tracker_db_manager_free (db_manager);
+                       return NULL;
                }
 
                /* Load databases */
@@ -924,38 +715,38 @@ db_manager_init_unlocked (TrackerDBManagerFlags   flags,
                                                                        NULL);
 #endif /* DISABLE_JOURNAL */
 
-               if (!must_recreate && g_file_test (in_use_filename, G_FILE_TEST_EXISTS)) {
+               if (!must_recreate && g_file_test (db_manager->in_use_filename, G_FILE_TEST_EXISTS)) {
                        gsize size = 0;
-
-                       g_info ("Didn't shut down cleanly last time, doing integrity checks");
-
-                       for (i = 1; i < G_N_ELEMENTS (dbs) && !must_recreate; i++) {
-                               struct stat st;
-                               TrackerDBStatement *stmt;
+                       struct stat st;
+                       TrackerDBStatement *stmt;
 #ifndef DISABLE_JOURNAL
-                               gchar *busy_status;
+                       gchar *busy_status;
 #endif /* DISABLE_JOURNAL */
 
-                               if (g_stat (dbs[i].abs_filename, &st) == 0) {
-                                       size = st.st_size;
-                               }
+                       g_info ("Didn't shut down cleanly last time, doing integrity checks");
 
-                               /* Size is 1 when using echo > file.db, none of our databases
-                                * are only one byte in size even initually. */
+                       if (g_stat (db_manager->db.abs_filename, &st) == 0) {
+                               size = st.st_size;
+                       }
 
-                               if (size <= 1) {
-                                       if (!restoring_backup) {
-                                               must_recreate = TRUE;
-                                       } else {
-                                               g_set_error (&internal_error,
-                                                            TRACKER_DB_INTERFACE_ERROR,
-                                                            TRACKER_DB_OPEN_ERROR,
-                                                            "Corrupt db file");
-                                       }
-                                       continue;
+                       /* Size is 1 when using echo > file.db, none of our databases
+                        * are only one byte in size even initually. */
+
+                       if (size <= 1) {
+                               if (!restoring_backup) {
+                                       must_recreate = TRUE;
+                               } else {
+                                       g_set_error (error,
+                                                    TRACKER_DB_INTERFACE_ERROR,
+                                                    TRACKER_DB_OPEN_ERROR,
+                                                    "Corrupt db file");
+                                       tracker_db_manager_free (db_manager);
+                                       return NULL;
                                }
+                       }
 
-                               dbs[i].iface = db_interface_create (i, &internal_error);
+                       if (!must_recreate) {
+                               db_manager->db.iface = tracker_db_manager_create_db_interface (db_manager, 
FALSE, &internal_error);
 
                                if (internal_error) {
                                        /* If this already doesn't succeed, then surely the file is
@@ -963,11 +754,16 @@ db_manager_init_unlocked (TrackerDBManagerFlags   flags,
                                        if (!restoring_backup) {
                                                g_clear_error (&internal_error);
                                                must_recreate = TRUE;
+                                       } else {
+                                               g_propagate_error (error, internal_error);
+                                               tracker_db_manager_free (db_manager);
+                                               return NULL;
                                        }
-                                       continue;
                                }
+                       }
 
-                               dbs[i].mtime = tracker_file_get_mtime (dbs[i].abs_filename);
+                       if (!must_recreate) {
+                               db_manager->db.mtime = tracker_file_get_mtime (db_manager->db.abs_filename);
 
                                loaded = TRUE;
 
@@ -976,13 +772,13 @@ db_manager_init_unlocked (TrackerDBManagerFlags   flags,
                                busy_status = g_strdup_printf ("%s - %s",
                                                               busy_operation,
                                                               "Integrity checking");
-                               tracker_db_interface_set_busy_handler (dbs[i].iface,
+                               tracker_db_interface_set_busy_handler (db_manager->db.iface,
                                                                       busy_callback,
                                                                       busy_status,
                                                                       busy_user_data);
                                g_free (busy_status);
 
-                               stmt = tracker_db_interface_create_statement (dbs[i].iface, 
TRACKER_DB_STATEMENT_CACHE_TYPE_NONE,
+                               stmt = tracker_db_interface_create_statement (db_manager->db.iface, 
TRACKER_DB_STATEMENT_CACHE_TYPE_NONE,
                                                                              &internal_error,
                                                                              "PRAGMA integrity_check(1)");
 
@@ -1015,10 +811,12 @@ db_manager_init_unlocked (TrackerDBManagerFlags   flags,
                                        }
                                }
 #endif /* DISABLE_JOURNAL */
+                       }
 
+                       if (!must_recreate) {
                                /* ensure that database has been initialized by an earlier tracker-store start
                                   by checking whether Resource table exists */
-                               stmt = tracker_db_interface_create_statement (dbs[i].iface, 
TRACKER_DB_STATEMENT_CACHE_TYPE_NONE,
+                               stmt = tracker_db_interface_create_statement (db_manager->db.iface, 
TRACKER_DB_STATEMENT_CACHE_TYPE_NONE,
                                                                              &internal_error,
                                                                              "SELECT 1 FROM Resource");
                                if (internal_error != NULL) {
@@ -1026,14 +824,12 @@ db_manager_init_unlocked (TrackerDBManagerFlags   flags,
                                                must_recreate = TRUE;
                                                g_error_free (internal_error);
                                                internal_error = NULL;
-                                       } else {
-                                               continue;
                                        }
                                } else {
                                        g_object_unref (stmt);
                                }
 
-                               tracker_db_interface_set_busy_handler (dbs[i].iface, NULL, NULL, NULL);
+                               tracker_db_interface_set_busy_handler (db_manager->db.iface, NULL, NULL, 
NULL);
                        }
                }
 
@@ -1045,7 +841,7 @@ db_manager_init_unlocked (TrackerDBManagerFlags   flags,
                                ".");
 #endif /* DISABLE_JOURNAL */
 
-                       perform_recreate (first_time, &internal_error);
+                       perform_recreate (db_manager, first_time, &internal_error);
                        if (internal_error) {
                                g_propagate_error (error, internal_error);
                                return FALSE;
@@ -1060,14 +856,12 @@ db_manager_init_unlocked (TrackerDBManagerFlags   flags,
        }
 
        if (!loaded) {
-               for (i = 1; i < G_N_ELEMENTS (dbs); i++) {
-                       dbs[i].mtime = tracker_file_get_mtime (dbs[i].abs_filename);
-               }
+               db_manager->db.mtime = tracker_file_get_mtime (db_manager->db.abs_filename);
        }
 
        if ((flags & TRACKER_DB_MANAGER_READONLY) == 0) {
                /* do not create in-use file for read-only mode (direct access) */
-               in_use_file = g_open (in_use_filename,
+               in_use_file = g_open (db_manager->in_use_filename,
                                      O_WRONLY | O_APPEND | O_CREAT | O_SYNC,
                                      S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
 
@@ -1077,32 +871,29 @@ db_manager_init_unlocked (TrackerDBManagerFlags   flags,
                }
        }
 
-       initialized = TRUE;
-
-       resources_iface = tracker_db_manager_get_db_interfaces (&internal_error,
-                                                               (flags & TRACKER_DB_MANAGER_READONLY) != 0,
-                                                               1, TRACKER_DB_METADATA);
+       resources_iface = tracker_db_manager_create_db_interface (db_manager,
+                                                                 (flags & TRACKER_DB_MANAGER_READONLY) != 0,
+                                                                 &internal_error);
 
        if (internal_error) {
                if ((!restoring_backup) && (flags & TRACKER_DB_MANAGER_READONLY) == 0) {
                        GError *new_error = NULL;
 
-                       perform_recreate (first_time, &new_error);
+                       perform_recreate (db_manager, first_time, &new_error);
                        if (!new_error) {
-                               resources_iface = tracker_db_manager_get_db_interfaces (&internal_error,
-                                                                                       FALSE, 1,
-                                                                                       TRACKER_DB_METADATA);
+                               resources_iface = tracker_db_manager_create_db_interface (db_manager, FALSE,
+                                                                                         &internal_error);
                        } else {
                                /* Most serious error is the recreate one here */
                                g_clear_error (&internal_error);
                                g_propagate_error (error, new_error);
-                               initialized = FALSE;
-                               return FALSE;
+                               tracker_db_manager_free (db_manager);
+                               return NULL;
                        }
                } else {
                        g_propagate_error (error, internal_error);
-                       initialized = FALSE;
-                       return FALSE;
+                       tracker_db_manager_free (db_manager);
+                       return NULL;
                }
        }
 
@@ -1114,134 +905,43 @@ db_manager_init_unlocked (TrackerDBManagerFlags   flags,
                                                      TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE,
                                                      update_cache_size);
 
-       s_cache_size = select_cache_size;
-       u_cache_size = update_cache_size;
+       db_manager->s_cache_size = select_cache_size;
+       db_manager->u_cache_size = update_cache_size;
 
        g_private_replace (&interface_data_key, resources_iface);
 
-       return TRUE;
-}
-
-gboolean
-tracker_db_manager_init (TrackerDBManagerFlags   flags,
-                         GFile                  *cache_location,
-                         GFile                  *data_location,
-                         gboolean               *first_time,
-                         gboolean                restoring_backup,
-                         gboolean                shared_cache,
-                         guint                   select_cache_size,
-                         guint                   update_cache_size,
-                         TrackerBusyCallback     busy_callback,
-                         gpointer                busy_user_data,
-                         const gchar            *busy_operation,
-                         GError                **error)
-{
-       gboolean retval;
-
-       if (!cache_location || !data_location) {
-               g_set_error (error,
-                            TRACKER_DATA_ONTOLOGY_ERROR,
-                            TRACKER_DATA_UNSUPPORTED_LOCATION,
-                            "All data storage and ontology locations must be provided");
-               return FALSE;
-       }
-
-       g_mutex_lock (&init_mutex);
-
-       retval = db_manager_init_unlocked (flags, cache_location, data_location,
-                                          first_time, restoring_backup,
-                                          shared_cache,
-                                          select_cache_size, update_cache_size,
-                                          busy_callback, busy_user_data,
-                                          busy_operation, error);
-
-       g_mutex_unlock (&init_mutex);
-
-       return retval;
+       return db_manager;
 }
 
-static void
-db_manager_shutdown_unlocked (void)
+void
+tracker_db_manager_free (TrackerDBManager *db_manager)
 {
-       guint i;
-
-       if (!initialized) {
-               return;
-       }
-
-       for (i = 1; i < G_N_ELEMENTS (dbs); i++) {
-               if (dbs[i].abs_filename) {
-                       g_free (dbs[i].abs_filename);
-                       dbs[i].abs_filename = NULL;
-
-                       if (dbs[i].iface) {
-                               g_object_unref (dbs[i].iface);
-                               dbs[i].iface = NULL;
-                       }
-               }
-       }
+       g_free (db_manager->db.abs_filename);
+       g_clear_object (&db_manager->db.iface);
 
-       g_free (data_dir);
-       data_dir = NULL;
-       g_free (user_data_dir);
-       user_data_dir = NULL;
+       g_free (db_manager->data_dir);
+       g_free (db_manager->user_data_dir);
 
-       /* shutdown db interface in all threads */
-       g_private_replace (&interface_data_key, NULL);
-
-       /* Since we don't reference this enum anywhere, we do
-        * it here to make sure it exists when we call
-        * g_type_class_peek(). This wouldn't be necessary if
-        * it was a param in a GObject for example.
-        *
-        * This does mean that we are leaking by 1 reference
-        * here and should clean it up, but it doesn't grow so
-        * this is acceptable.
-        */
-       g_type_class_unref (db_type_enum_class_pointer);
-       db_type_enum_class_pointer = NULL;
-
-       initialized = FALSE;
-       locations_initialized = FALSE;
-
-       if ((tracker_db_manager_get_flags (NULL, NULL) & TRACKER_DB_MANAGER_READONLY) == 0) {
+       if ((db_manager->flags & TRACKER_DB_MANAGER_READONLY) == 0) {
                /* do not delete in-use file for read-only mode (direct access) */
-               g_unlink (in_use_filename);
+               g_unlink (db_manager->in_use_filename);
        }
 
-       g_free (in_use_filename);
-       in_use_filename = NULL;
+       g_free (db_manager->in_use_filename);
+       g_free (db_manager);
 }
 
 void
-tracker_db_manager_shutdown (void)
-{
-       g_mutex_lock (&init_mutex);
-       db_manager_shutdown_unlocked ();
-       g_mutex_unlock (&init_mutex);
-}
-
-void
-tracker_db_manager_remove_all (void)
-{
-       g_return_if_fail (initialized != FALSE);
-
-       db_manager_remove_all ();
-}
-
-void
-tracker_db_manager_optimize (void)
+tracker_db_manager_optimize (TrackerDBManager *db_manager)
 {
        gboolean dbs_are_open = FALSE;
        TrackerDBInterface *iface;
 
-       g_return_if_fail (initialized != FALSE);
-
        g_info ("Optimizing database...");
 
        g_info ("  Checking database is not in use");
 
-       iface = tracker_db_manager_get_db_interface ();
+       iface = tracker_db_manager_get_db_interface (db_manager);
 
        /* Check if any connections are open? */
        if (G_OBJECT (iface)->ref_count > 1) {
@@ -1257,87 +957,49 @@ tracker_db_manager_optimize (void)
        }
 
        /* Optimize the metadata database */
-       db_manager_analyze (TRACKER_DB_METADATA, iface);
+       db_manager_analyze (db_manager, iface);
 }
 
 const gchar *
-tracker_db_manager_get_file (TrackerDB db)
+tracker_db_manager_get_file (TrackerDBManager *db_manager)
 {
-       g_return_val_if_fail (initialized != FALSE, NULL);
-
-       return dbs[db].abs_filename;
+       return db_manager->db.abs_filename;
 }
 
-/**
- * tracker_db_manager_get_db_interfaces:
- * @num: amount of TrackerDB files wanted
- * @...: All the files that you want in the connection as TrackerDB items
- *
- * Request a database connection where the first requested file gets connected
- * to and the subsequent requsted files get attached to the connection.
- *
- * The caller must g_object_unref the result when finished using it.
- *
- * returns: (caller-owns): a database connection
- **/
 static TrackerDBInterface *
-tracker_db_manager_get_db_interfaces (GError   **error,
-                                      gboolean   readonly,
-                                      gint       num,
-                                      ...)
+tracker_db_manager_create_db_interface (TrackerDBManager  *db_manager,
+                                        gboolean           readonly,
+                                        GError           **error)
 {
-       gint n_args;
-       va_list args;
-       TrackerDBInterface *connection = NULL;
+       TrackerDBInterface *connection;
        GError *internal_error = NULL;
+       TrackerDBInterfaceFlags flags = 0;
 
-       g_return_val_if_fail (initialized != FALSE, NULL);
-
-       va_start (args, num);
-       for (n_args = 1; n_args <= num; n_args++) {
-               TrackerDB db = va_arg (args, TrackerDB);
-
-               if (!connection) {
-                       TrackerDBInterfaceFlags flags = 0;
-
-                       if (readonly)
-                               flags |= TRACKER_DB_INTERFACE_READONLY;
-                       if (tracker_db_manager_get_flags (NULL, NULL) & TRACKER_DB_MANAGER_ENABLE_MUTEXES)
-                               flags |= TRACKER_DB_INTERFACE_USE_MUTEX;
-
-                       connection = tracker_db_interface_sqlite_new (dbs[db].abs_filename,
-                                                                     flags,
-                                                                     &internal_error);
-
-                       if (internal_error) {
-                               g_propagate_error (error, internal_error);
-                               connection = NULL;
-                               goto end_on_error;
-                       }
-
-                       db_set_params (connection,
-                                      dbs[db].cache_size,
-                                      dbs[db].page_size,
-                                      readonly,
-                                      &internal_error);
+       if (readonly)
+               flags |= TRACKER_DB_INTERFACE_READONLY;
+       if (db_manager->flags & TRACKER_DB_MANAGER_ENABLE_MUTEXES)
+               flags |= TRACKER_DB_INTERFACE_USE_MUTEX;
 
-                       if (internal_error) {
-                               g_propagate_error (error, internal_error);
-                               g_clear_object (&connection);
-                               goto end_on_error;
-                       }
-               } else {
-                       db_exec_no_reply (connection,
-                                         "ATTACH '%s' as '%s'",
-                                         dbs[db].abs_filename,
-                                         dbs[db].name);
-               }
+       connection = tracker_db_interface_sqlite_new (db_manager->db.abs_filename,
+                                                     flags,
+                                                     &internal_error);
 
+       if (internal_error) {
+               g_propagate_error (error, internal_error);
+               return NULL;
        }
 
-       end_on_error:
+       db_set_params (connection,
+                      db_manager->db.cache_size,
+                      db_manager->db.page_size,
+                      readonly,
+                      &internal_error);
 
-       va_end (args);
+       if (internal_error) {
+               g_propagate_error (error, internal_error);
+               g_object_unref (connection);
+               return NULL;
+       }
 
        return connection;
 }
@@ -1352,23 +1014,21 @@ tracker_db_manager_get_db_interfaces (GError   **error,
  * returns: (callee-owns): a database connection
  **/
 TrackerDBInterface *
-tracker_db_manager_get_db_interface (void)
+tracker_db_manager_get_db_interface (TrackerDBManager *db_manager)
 {
        GError *internal_error = NULL;
        TrackerDBInterface *interface;
 
-       g_return_val_if_fail (initialized != FALSE, NULL);
-
        interface = g_private_get (&interface_data_key);
 
        /* Ensure the interface is there */
        if (!interface) {
                TrackerDBManagerFlags flags;
 
-               flags = tracker_db_manager_get_flags (NULL, NULL);
-               interface = tracker_db_manager_get_db_interfaces (&internal_error,
-                                                                 (flags & TRACKER_DB_MANAGER_READONLY) != 0,
-                                                                 1, TRACKER_DB_METADATA);
+               flags = tracker_db_manager_get_flags (db_manager, NULL, NULL);
+               interface = tracker_db_manager_create_db_interface (db_manager,
+                                                                   (flags & TRACKER_DB_MANAGER_READONLY) != 
0,
+                                                                   &internal_error);
 
                if (internal_error) {
                        g_critical ("Error opening database: %s", internal_error->message);
@@ -1380,11 +1040,11 @@ tracker_db_manager_get_db_interface (void)
 
                tracker_db_interface_set_max_stmt_cache_size (interface,
                                                              TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT,
-                                                             s_cache_size);
+                                                             db_manager->s_cache_size);
 
                tracker_db_interface_set_max_stmt_cache_size (interface,
                                                              TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE,
-                                                             u_cache_size);
+                                                             db_manager->u_cache_size);
 
                g_private_set (&interface_data_key, interface);
        }
@@ -1401,27 +1061,27 @@ tracker_db_manager_get_db_interface (void)
  * returns: TRUE if there is enough space, FALSE otherwise
  **/
 gboolean
-tracker_db_manager_has_enough_space  (void)
+tracker_db_manager_has_enough_space (TrackerDBManager *db_manager)
 {
-       return tracker_file_system_has_enough_space (data_dir, TRACKER_DB_MIN_REQUIRED_SPACE, FALSE);
+       return tracker_file_system_has_enough_space (db_manager->data_dir, TRACKER_DB_MIN_REQUIRED_SPACE, 
FALSE);
 }
 
 inline static gchar *
-get_parser_sha1_filename (void)
+get_parser_sha1_filename (TrackerDBManager *db_manager)
 {
-       return g_build_filename (data_dir,
+       return g_build_filename (db_manager->data_dir,
                                 PARSER_SHA1_FILENAME,
                                 NULL);
 }
 
 
 gboolean
-tracker_db_manager_get_tokenizer_changed (void)
+tracker_db_manager_get_tokenizer_changed (TrackerDBManager *db_manager)
 {
        gchar *filename, *sha1;
        gboolean changed = TRUE;
 
-       filename = get_parser_sha1_filename ();
+       filename = get_parser_sha1_filename (db_manager);
 
        if (g_file_get_contents (filename, &sha1, NULL, NULL)) {
                changed = strcmp (sha1, TRACKER_PARSER_SHA1) != 0;
@@ -1434,12 +1094,12 @@ tracker_db_manager_get_tokenizer_changed (void)
 }
 
 void
-tracker_db_manager_tokenizer_update (void)
+tracker_db_manager_tokenizer_update (TrackerDBManager *db_manager)
 {
        GError *error = NULL;
        gchar *filename;
 
-       filename = get_parser_sha1_filename ();
+       filename = get_parser_sha1_filename (db_manager);
 
        if (!g_file_set_contents (filename, TRACKER_PARSER_SHA1, -1, &error)) {
                g_warning ("The file '%s' could not be rewritten by Tracker and "
diff --git a/src/libtracker-data/tracker-db-manager.h b/src/libtracker-data/tracker-db-manager.h
index 1e79713..3b1507c 100644
--- a/src/libtracker-data/tracker-db-manager.h
+++ b/src/libtracker-data/tracker-db-manager.h
@@ -33,14 +33,6 @@ G_BEGIN_DECLS
 #define TRACKER_DB_CACHE_SIZE_DEFAULT 250
 #define TRACKER_DB_CACHE_SIZE_UPDATE 2000
 
-#define TRACKER_TYPE_DB (tracker_db_get_type ())
-
-typedef enum {
-       TRACKER_DB_UNKNOWN,
-       TRACKER_DB_METADATA,
-       TRACKER_DB_FULLTEXT,
-} TrackerDB;
-
 typedef enum {
        TRACKER_DB_MANAGER_FORCE_REINDEX         = 1 << 1,
        TRACKER_DB_MANAGER_REMOVE_CACHE          = 1 << 2,
@@ -51,8 +43,9 @@ typedef enum {
        TRACKER_DB_MANAGER_ENABLE_MUTEXES        = 1 << 7,
 } TrackerDBManagerFlags;
 
-GType               tracker_db_get_type                       (void) G_GNUC_CONST;
-gboolean            tracker_db_manager_init                   (TrackerDBManagerFlags   flags,
+typedef struct _TrackerDBManager TrackerDBManager;
+
+TrackerDBManager   *tracker_db_manager_new                    (TrackerDBManagerFlags   flags,
                                                                GFile                  *cache_location,
                                                                GFile                  *data_location,
                                                                gboolean               *first_time,
@@ -64,34 +57,40 @@ gboolean            tracker_db_manager_init                   (TrackerDBManagerF
                                                                gpointer                busy_user_data,
                                                                const gchar            *busy_operation,
                                                                GError                **error);
-void                tracker_db_manager_shutdown               (void);
-void                tracker_db_manager_remove_all             (void);
-void                tracker_db_manager_optimize               (void);
-const gchar *       tracker_db_manager_get_file               (TrackerDB              db);
-TrackerDBInterface *tracker_db_manager_get_db_interface       (void);
-void                tracker_db_manager_init_locations         (GFile                 *cache_location,
+void                tracker_db_manager_free                   (TrackerDBManager      *db_manager);
+void                tracker_db_manager_remove_all             (TrackerDBManager      *db_manager);
+void                tracker_db_manager_optimize               (TrackerDBManager      *db_manager);
+const gchar *       tracker_db_manager_get_file               (TrackerDBManager      *db_manager);
+TrackerDBInterface *tracker_db_manager_get_db_interface       (TrackerDBManager      *db_manager);
+void                tracker_db_manager_ensure_locations       (TrackerDBManager      *db_manager,
+                                                              GFile                 *cache_location,
                                                                GFile                 *data_location);
-gboolean            tracker_db_manager_has_enough_space       (void);
-void                tracker_db_manager_create_version_file    (void);
-void                tracker_db_manager_remove_version_file    (void);
+gboolean            tracker_db_manager_has_enough_space       (TrackerDBManager      *db_manager);
+void                tracker_db_manager_create_version_file    (TrackerDBManager      *db_manager);
+void                tracker_db_manager_remove_version_file    (TrackerDBManager      *db_manager);
 
 TrackerDBManagerFlags
-                    tracker_db_manager_get_flags              (guint *select_cache_size,
-                                                               guint *update_cache_size);
-
-gboolean            tracker_db_manager_get_first_index_done   (void);
-guint64             tracker_db_manager_get_last_crawl_done    (void);
-gboolean            tracker_db_manager_get_need_mtime_check   (void);
-
-void                tracker_db_manager_set_first_index_done   (gboolean done);
-void                tracker_db_manager_set_last_crawl_done    (gboolean done);
-void                tracker_db_manager_set_need_mtime_check   (gboolean needed);
-
-gboolean            tracker_db_manager_locale_changed         (GError **error);
-void                tracker_db_manager_set_current_locale     (void);
-
-gboolean            tracker_db_manager_get_tokenizer_changed  (void);
-void                tracker_db_manager_tokenizer_update       (void);
+                    tracker_db_manager_get_flags              (TrackerDBManager      *db_manager,
+                                                              guint                 *select_cache_size,
+                                                               guint                 *update_cache_size);
+
+gboolean            tracker_db_manager_get_first_index_done   (TrackerDBManager      *db_manager);
+guint64             tracker_db_manager_get_last_crawl_done    (TrackerDBManager      *db_manager);
+gboolean            tracker_db_manager_get_need_mtime_check   (TrackerDBManager      *db_manager);
+
+void                tracker_db_manager_set_first_index_done   (TrackerDBManager      *db_manager,
+                                                              gboolean               done);
+void                tracker_db_manager_set_last_crawl_done    (TrackerDBManager      *db_manager,
+                                                              gboolean               done);
+void                tracker_db_manager_set_need_mtime_check   (TrackerDBManager      *db_manager,
+                                                              gboolean               needed);
+
+gboolean            tracker_db_manager_locale_changed         (TrackerDBManager      *db_manager,
+                                                               GError               **error);
+void                tracker_db_manager_set_current_locale     (TrackerDBManager      *db_manager);
+
+gboolean            tracker_db_manager_get_tokenizer_changed  (TrackerDBManager      *db_manager);
+void                tracker_db_manager_tokenizer_update       (TrackerDBManager      *db_manager);
 
 G_END_DECLS
 
diff --git a/src/libtracker-data/tracker-sparql-pattern.vala b/src/libtracker-data/tracker-sparql-pattern.vala
index 9d2ae79..51dee71 100644
--- a/src/libtracker-data/tracker-sparql-pattern.vala
+++ b/src/libtracker-data/tracker-sparql-pattern.vala
@@ -37,7 +37,7 @@ namespace Tracker.Sparql {
 
                                        DBCursor cursor = null;
                                        if (subject_id > 0) {
-                                               var iface = DBManager.get_db_interface ();
+                                               var iface = Data.Manager.get_db_interface ();
                                                var stmt = iface.create_statement 
(DBStatementCacheType.SELECT,
                                                                                   "SELECT (SELECT Uri FROM 
Resource WHERE ID = \"rdf:type\") " +
                                                                                   "FROM 
\"rdfs:Resource_rdf:type\" WHERE ID = ?");
@@ -86,7 +86,7 @@ namespace Tracker.Sparql {
                                        // single object
                                        var object_id = Data.query_resource_id (object);
 
-                                       var iface = DBManager.get_db_interface ();
+                                       var iface = Data.Manager.get_db_interface ();
                                        var stmt = iface.create_statement (DBStatementCacheType.SELECT,
                                                                           "SELECT (SELECT Uri FROM Resource 
WHERE ID = \"rdf:type\") " +
                                                                           "FROM \"rdfs:Resource_rdf:type\" 
WHERE ID = ?");
diff --git a/src/libtracker-data/tracker-sparql-query.vala b/src/libtracker-data/tracker-sparql-query.vala
index 82f86e1..ce45461 100644
--- a/src/libtracker-data/tracker-sparql-query.vala
+++ b/src/libtracker-data/tracker-sparql-query.vala
@@ -505,7 +505,7 @@ public class Tracker.Sparql.Query : Object {
        }
 
        DBStatement prepare_for_exec (string sql) throws DBInterfaceError, Sparql.Error, DateError {
-               var iface = DBManager.get_db_interface ();
+               var iface = Data.Manager.get_db_interface ();
                if (iface == null) {
                        throw new DBInterfaceError.OPEN_ERROR ("Error opening database");
                }
diff --git a/src/libtracker-direct/tracker-direct.vala b/src/libtracker-direct/tracker-direct.vala
index df7ee16..69fc542 100644
--- a/src/libtracker-direct/tracker-direct.vala
+++ b/src/libtracker-direct/tracker-direct.vala
@@ -98,7 +98,7 @@ public class Tracker.Direct.Connection : Tracker.Sparql.Connection, AsyncInitabl
 
        static void wal_checkpoint_on_thread () {
                new Thread<void*> ("wal-checkpoint", () => {
-                       var iface = DBManager.get_db_interface ();
+                       var iface = Data.Manager.get_db_interface ();
                        wal_checkpoint (iface, false);
                        return null;
                });
@@ -126,7 +126,7 @@ public class Tracker.Direct.Connection : Tracker.Sparql.Connection, AsyncInitabl
                                           database_loc, journal_loc, ontology_loc,
                                           null, false, false, 100, 100, null, null);
 
-                       var iface = DBManager.get_db_interface ();
+                       var iface = Data.Manager.get_db_interface ();
                        iface.sqlite_wal_hook (wal_hook);
                } catch (Error e) {
                        init_error = e;
diff --git a/src/tracker-store/tracker-statistics.vala b/src/tracker-store/tracker-statistics.vala
index 70f8daf..8a1a81d 100644
--- a/src/tracker-store/tracker-statistics.vala
+++ b/src/tracker-store/tracker-statistics.vala
@@ -29,7 +29,7 @@ public class Tracker.Statistics : Object {
                var ontologies = Data.Manager.get_ontologies ();
 
                if (!initialized) {
-                       var iface = DBManager.get_db_interface ();
+                       var iface = Data.Manager.get_db_interface ();
 
                        foreach (var cl in ontologies.get_classes ()) {
                                /* xsd classes do not derive from rdfs:Resource and do not use separate 
tables */
diff --git a/src/tracker-store/tracker-store.vala b/src/tracker-store/tracker-store.vala
index 1e9f028..dac9f97 100644
--- a/src/tracker-store/tracker-store.vala
+++ b/src/tracker-store/tracker-store.vala
@@ -213,7 +213,7 @@ public class Tracker.Store {
 
                                query_task.in_thread (cursor);
                        } else {
-                               var iface = DBManager.get_db_interface ();
+                               var iface = Data.Manager.get_db_interface ();
                                iface.sqlite_wal_hook (wal_hook);
 
                                if (task.type == TaskType.UPDATE) {
@@ -250,7 +250,7 @@ public class Tracker.Store {
        public static void wal_checkpoint () {
                try {
                        debug ("Checkpointing database...");
-                       var iface = DBManager.get_db_interface ();
+                       var iface = Data.Manager.get_db_interface ();
                        iface.execute_query ("PRAGMA wal_checkpoint");
                        debug ("Checkpointing complete...");
                } catch (Error e) {
diff --git a/src/tracker/tracker-reset.c b/src/tracker/tracker-reset.c
index dce61f0..158b8d2 100644
--- a/src/tracker/tracker-reset.c
+++ b/src/tracker/tracker-reset.c
@@ -261,6 +261,7 @@ reset_run (void)
                guint log_handler_id;
                GFile *cache_location, *data_location;
                gchar *dir;
+               TrackerDBManager *db_manager;
 #ifndef DISABLE_JOURNAL
                gchar *rotate_to;
                TrackerDBConfig *db_config;
@@ -302,32 +303,33 @@ reset_run (void)
 #endif /* DISABLE_JOURNAL */
 
                /* Clean up (select_cache_size and update_cache_size don't matter here) */
-               if (!tracker_db_manager_init (TRACKER_DB_MANAGER_REMOVE_ALL,
-                                             cache_location, data_location,
-                                             NULL,
-                                             FALSE,
-                                             FALSE,
-                                             100,
-                                             100,
-                                             NULL,
-                                             NULL,
-                                             NULL,
-                                             &error)) {
-
+               db_manager = tracker_db_manager_new (TRACKER_DB_MANAGER_REMOVE_ALL,
+                                                    cache_location, data_location,
+                                                    NULL,
+                                                    FALSE,
+                                                    FALSE,
+                                                    100,
+                                                    100,
+                                                    NULL,
+                                                    NULL,
+                                                    NULL,
+                                                    &error);
+
+               if (!db_manager) {
                        g_message ("Error initializing database: %s", error->message);
                        g_free (error);
 
                        return EXIT_FAILURE;
                }
 
-               tracker_db_manager_remove_all ();
+               tracker_db_manager_remove_all (db_manager);
 #ifndef DISABLE_JOURNAL
                journal_writer = tracker_db_journal_new (data_location, FALSE, NULL);
                tracker_db_journal_remove (journal_writer);
 #endif /* DISABLE_JOURNAL */
 
-               tracker_db_manager_remove_version_file ();
-               tracker_db_manager_shutdown ();
+               tracker_db_manager_remove_version_file (db_manager);
+               tracker_db_manager_free (db_manager);
 
                /* Unset log handler */
                g_log_remove_handler (NULL, log_handler_id);
diff --git a/src/tracker/tracker-sql.c b/src/tracker/tracker-sql.c
index a4c2852..76f6af8 100644
--- a/src/tracker/tracker-sql.c
+++ b/src/tracker/tracker-sql.c
@@ -132,7 +132,7 @@ sql_by_query (void)
        g_print ("--------------------------------------------------\n");
        g_print ("\n\n");
 
-       iface = tracker_db_manager_get_db_interface ();
+       iface = tracker_data_manager_get_db_interface ();
 
        stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_NONE, &error, 
"%s", query);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]