[tracker/wip/carlosg/domain-ontologies: 47/124] libtracker-data: Turn tracker ontologies into an object



commit 390ac881b884894ac2986cf513b0e06fda737f42
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Jun 7 01:15:09 2017 +0200

    libtracker-data: Turn tracker ontologies into an object
    
    And make it a singleton in tracker-data-manager.c at the moment.

 src/libtracker-data/libtracker-data.vapi           |    3 +-
 src/libtracker-data/tracker-class.c                |   21 +-
 src/libtracker-data/tracker-class.h                |    4 +
 src/libtracker-data/tracker-data-manager.c         |  200 +++++----
 src/libtracker-data/tracker-data-manager.h         |    1 +
 src/libtracker-data/tracker-data-query.c           |    4 +-
 src/libtracker-data/tracker-data-update.c          |  106 +++--
 src/libtracker-data/tracker-namespace.c            |   16 +-
 src/libtracker-data/tracker-namespace.h            |    3 +
 src/libtracker-data/tracker-ontologies.c           |  472 +++++++++++---------
 src/libtracker-data/tracker-ontologies.h           |  109 +++--
 src/libtracker-data/tracker-ontology.c             |   14 +
 src/libtracker-data/tracker-ontology.h             |    3 +
 src/libtracker-data/tracker-property.c             |   37 ++-
 src/libtracker-data/tracker-property.h             |    3 +
 src/libtracker-data/tracker-sparql-expression.vala |    3 +-
 src/libtracker-data/tracker-sparql-pattern.vala    |   22 +-
 src/libtracker-data/tracker-sparql-query.vala      |    6 +-
 src/libtracker-fts/tracker-fts-tokenizer.c         |    6 +-
 src/tracker-store/tracker-events.c                 |    4 +-
 src/tracker-store/tracker-statistics.vala          |    5 +-
 src/tracker-store/tracker-writeback.c              |    4 +-
 22 files changed, 637 insertions(+), 409 deletions(-)
---
diff --git a/src/libtracker-data/libtracker-data.vapi b/src/libtracker-data/libtracker-data.vapi
index c831916..2e55d3a 100644
--- a/src/libtracker-data/libtracker-data.vapi
+++ b/src/libtracker-data/libtracker-data.vapi
@@ -172,7 +172,7 @@ namespace Tracker {
        }
 
        [CCode (cheader_filename = "libtracker-data/tracker-ontologies.h")]
-       namespace Ontologies {
+       public class Ontologies : GLib.Object {
                public unowned Class get_class_by_uri (string class_uri);
                public unowned Property get_property_by_uri (string property_uri);
                public unowned Namespace[] get_namespaces ();
@@ -232,6 +232,7 @@ namespace Tracker {
        namespace Data.Manager {
                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 ();
        }
 
        [CCode (cheader_filename = "libtracker-data/tracker-db-interface-sqlite.h")]
diff --git a/src/libtracker-data/tracker-class.c b/src/libtracker-data/tracker-class.c
index 3048560..6c9754e 100644
--- a/src/libtracker-data/tracker-class.c
+++ b/src/libtracker-data/tracker-class.c
@@ -48,6 +48,8 @@ struct _TrackerClassPrivate {
        GArray *last_domain_indexes;
        GArray *last_super_classes;
 
+       TrackerOntologies *ontologies;
+
        struct {
                struct {
                        GArray *sub_pred_ids;
@@ -224,14 +226,14 @@ tracker_class_get_super_classes (TrackerClass *service)
 
                tracker_class_reset_super_classes (service);
 
-               variant = tracker_ontologies_get_class_value_gvdb (priv->uri, "super-classes");
+               variant = tracker_ontologies_get_class_value_gvdb (priv->ontologies, priv->uri, 
"super-classes");
                if (variant) {
                        GVariantIter iter;
                        const gchar *uri;
 
                        g_variant_iter_init (&iter, variant);
                        while (g_variant_iter_loop (&iter, "&s", &uri)) {
-                               super_class = tracker_ontologies_get_class_by_uri (uri);
+                               super_class = tracker_ontologies_get_class_by_uri (priv->ontologies, uri);
 
                                tracker_class_add_super_class (service, super_class);
                        }
@@ -346,7 +348,7 @@ tracker_class_set_uri (TrackerClass *service,
                        g_critical ("Unknown namespace of class %s", priv->uri);
                } else {
                        namespace_uri = g_strndup (priv->uri, hash - priv->uri + 1);
-                       namespace = tracker_ontologies_get_namespace_by_uri (namespace_uri);
+                       namespace = tracker_ontologies_get_namespace_by_uri (priv->ontologies, namespace_uri);
                        if (namespace == NULL) {
                                g_critical ("Unknown namespace %s of class %s", namespace_uri, priv->uri);
                        } else {
@@ -746,3 +748,16 @@ tracker_class_add_delete_event (TrackerClass *class,
                                 pred_id,
                                 object_id);
 }
+
+void
+tracker_class_set_ontologies (TrackerClass      *class,
+                              TrackerOntologies *ontologies)
+{
+       TrackerClassPrivate *priv;
+
+       g_return_if_fail (TRACKER_IS_CLASS (class));
+       g_return_if_fail (ontologies != NULL);
+       priv = GET_PRIV (class);
+
+       priv->ontologies = ontologies;
+}
diff --git a/src/libtracker-data/tracker-class.h b/src/libtracker-data/tracker-class.h
index c3f1c8d..c056341 100644
--- a/src/libtracker-data/tracker-class.h
+++ b/src/libtracker-data/tracker-class.h
@@ -36,6 +36,7 @@ G_BEGIN_DECLS
 #define TRACKER_IS_CLASS_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), TRACKER_TYPE_CLASS))
 #define TRACKER_CLASS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_CLASS, TrackerClassClass))
 
+typedef struct _TrackerOntologies TrackerOntologies;
 typedef struct _TrackerProperty TrackerProperty;
 typedef struct _TrackerClass TrackerClass;
 typedef struct _TrackerClassClass TrackerClassClass;
@@ -92,6 +93,9 @@ void              tracker_class_set_db_schema_changed  (TrackerClass        *ser
 void              tracker_class_set_notify             (TrackerClass        *service,
                                                         gboolean             value);
 
+void              tracker_class_set_ontologies         (TrackerClass        *class,
+                                                        TrackerOntologies   *ontologies);
+
 /* For signals API */
 void              tracker_class_foreach_delete_event   (TrackerClass        *class,
                                                         TrackerEventsForeach foreach,
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 0913203..985b89e 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -77,6 +77,8 @@ static TrackerDBJournal *journal_writer = NULL;
 static TrackerDBJournal *ontology_writer = NULL;
 #endif
 
+static TrackerOntologies *ontologies = NULL;
+
 typedef struct {
        const gchar *from;
        const gchar *to;
@@ -598,7 +600,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
        if (g_strcmp0 (predicate, RDF_TYPE) == 0) {
                if (g_strcmp0 (object, RDFS_CLASS) == 0) {
                        TrackerClass *class;
-                       class = tracker_ontologies_get_class_by_uri (subject);
+                       class = tracker_ontologies_get_class_by_uri (ontologies, subject);
 
                        if (class != NULL) {
                                if (seen_classes)
@@ -619,11 +621,12 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
                        }
 
                        class = tracker_class_new (FALSE);
+                       tracker_class_set_ontologies (class, ontologies);
                        tracker_class_set_is_new (class, in_update);
                        tracker_class_set_uri (class, subject);
                        tracker_class_set_id (class, subject_id);
-                       tracker_ontologies_add_class (class);
-                       tracker_ontologies_add_id_uri_pair (subject_id, subject);
+                       tracker_ontologies_add_class (ontologies, class);
+                       tracker_ontologies_add_id_uri_pair (ontologies, subject_id, subject);
 
                        if (seen_classes)
                                g_ptr_array_add (seen_classes, g_object_ref (class));
@@ -637,7 +640,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
                } else if (g_strcmp0 (object, RDF_PROPERTY) == 0) {
                        TrackerProperty *property;
 
-                       property = tracker_ontologies_get_property_by_uri (subject);
+                       property = tracker_ontologies_get_property_by_uri (ontologies, subject);
                        if (property != NULL) {
                                if (seen_properties)
                                        g_ptr_array_add (seen_properties, g_object_ref (property));
@@ -665,12 +668,13 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
                        }
 
                        property = tracker_property_new (FALSE);
+                       tracker_property_set_ontologies (property, ontologies);
                        tracker_property_set_is_new (property, in_update);
                        tracker_property_set_uri (property, subject);
                        tracker_property_set_id (property, subject_id);
                        tracker_property_set_multiple_values (property, TRUE);
-                       tracker_ontologies_add_property (property);
-                       tracker_ontologies_add_id_uri_pair (subject_id, subject);
+                       tracker_ontologies_add_property (ontologies, property);
+                       tracker_ontologies_add_id_uri_pair (ontologies, subject_id, subject);
 
                        if (seen_properties)
                                g_ptr_array_add (seen_properties, g_object_ref (property));
@@ -684,7 +688,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
                } else if (g_strcmp0 (object, NRL_INVERSE_FUNCTIONAL_PROPERTY) == 0) {
                        TrackerProperty *property;
 
-                       property = tracker_ontologies_get_property_by_uri (subject);
+                       property = tracker_ontologies_get_property_by_uri (ontologies, subject);
                        if (property == NULL) {
                                g_critical ("%s: Unknown property %s", ontology_path, subject);
                                return;
@@ -694,31 +698,33 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
                } else if (g_strcmp0 (object, TRACKER_PREFIX_TRACKER "Namespace") == 0) {
                        TrackerNamespace *namespace;
 
-                       if (tracker_ontologies_get_namespace_by_uri (subject) != NULL) {
+                       if (tracker_ontologies_get_namespace_by_uri (ontologies, subject) != NULL) {
                                if (!in_update)
                                        g_critical ("%s: Duplicate definition of namespace %s", 
ontology_path, subject);
                                return;
                        }
 
                        namespace = tracker_namespace_new (FALSE);
+                       tracker_namespace_set_ontologies (namespace, ontologies);
                        tracker_namespace_set_is_new (namespace, in_update);
                        tracker_namespace_set_uri (namespace, subject);
-                       tracker_ontologies_add_namespace (namespace);
+                       tracker_ontologies_add_namespace (ontologies, namespace);
                        g_object_unref (namespace);
 
                } else if (g_strcmp0 (object, TRACKER_PREFIX_TRACKER "Ontology") == 0) {
                        TrackerOntology *ontology;
 
-                       if (tracker_ontologies_get_ontology_by_uri (subject) != NULL) {
+                       if (tracker_ontologies_get_ontology_by_uri (ontologies, subject) != NULL) {
                                if (!in_update)
                                        g_critical ("%s: Duplicate definition of ontology %s", ontology_path, 
subject);
                                return;
                        }
 
                        ontology = tracker_ontology_new ();
+                       tracker_ontology_set_ontologies (ontology, ontologies);
                        tracker_ontology_set_is_new (ontology, in_update);
                        tracker_ontology_set_uri (ontology, subject);
-                       tracker_ontologies_add_ontology (ontology);
+                       tracker_ontologies_add_ontology (ontologies, ontology);
                        g_object_unref (ontology);
 
                }
@@ -726,7 +732,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
                TrackerClass *class, *super_class;
                gboolean is_new;
 
-               class = tracker_ontologies_get_class_by_uri (subject);
+               class = tracker_ontologies_get_class_by_uri (ontologies, subject);
                if (class == NULL) {
                        g_critical ("%s: Unknown class %s", ontology_path, subject);
                        return;
@@ -740,7 +746,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
                                TrackerClass **super_classes = tracker_class_get_super_classes (class);
                                gboolean had = FALSE;
 
-                               super_class = tracker_ontologies_get_class_by_uri (object);
+                               super_class = tracker_ontologies_get_class_by_uri (ontologies, object);
                                if (super_class == NULL) {
                                        g_critical ("%s: Unknown class %s", ontology_path, object);
                                        return;
@@ -783,14 +789,14 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
                        }
 
                        if (!ignore) {
-                               super_class = tracker_ontologies_get_class_by_uri (object);
+                               super_class = tracker_ontologies_get_class_by_uri (ontologies, object);
                                tracker_class_add_super_class (class, super_class);
                        }
 
                        return;
                }
 
-               super_class = tracker_ontologies_get_class_by_uri (object);
+               super_class = tracker_ontologies_get_class_by_uri (ontologies, object);
                if (super_class == NULL) {
                        g_critical ("%s: Unknown class %s", ontology_path, object);
                        return;
@@ -801,7 +807,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
        } else if (g_strcmp0 (predicate, TRACKER_PREFIX_TRACKER "notify") == 0) {
                TrackerClass *class;
 
-               class = tracker_ontologies_get_class_by_uri (subject);
+               class = tracker_ontologies_get_class_by_uri (ontologies, subject);
 
                if (class == NULL) {
                        g_critical ("%s: Unknown class %s", ontology_path, subject);
@@ -817,14 +823,14 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
                gboolean had = FALSE;
                guint n_props, i;
 
-               class = tracker_ontologies_get_class_by_uri (subject);
+               class = tracker_ontologies_get_class_by_uri (ontologies, subject);
 
                if (class == NULL) {
                        g_critical ("%s: Unknown class %s", ontology_path, subject);
                        return;
                }
 
-               property = tracker_ontologies_get_property_by_uri (object);
+               property = tracker_ontologies_get_property_by_uri (ontologies, object);
 
                if (property == NULL) {
 
@@ -853,7 +859,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
                        return;
                }
 
-               properties = tracker_ontologies_get_properties (&n_props);
+               properties = tracker_ontologies_get_properties (ontologies, &n_props);
                for (i = 0; i < n_props; i++) {
                        if (tracker_property_get_domain (properties[i]) == class &&
                            properties[i] == property) {
@@ -898,7 +904,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
        } else if (g_strcmp0 (predicate, TRACKER_PREFIX_TRACKER "writeback") == 0) {
                TrackerProperty *property;
 
-               property = tracker_ontologies_get_property_by_uri (subject);
+               property = tracker_ontologies_get_property_by_uri (ontologies, subject);
 
                if (property == NULL) {
                        g_critical ("%s: Unknown property %s", ontology_path, subject);
@@ -909,7 +915,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
        } else if (g_strcmp0 (predicate, TRACKER_PREFIX_TRACKER "forceJournal") == 0) {
                TrackerProperty *property;
 
-               property = tracker_ontologies_get_property_by_uri (subject);
+               property = tracker_ontologies_get_property_by_uri (ontologies, subject);
 
                if (property == NULL) {
                        g_critical ("%s: Unknown property %s", ontology_path, subject);
@@ -921,7 +927,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
                TrackerProperty *property, *super_property;
                gboolean is_new;
 
-               property = tracker_ontologies_get_property_by_uri (subject);
+               property = tracker_ontologies_get_property_by_uri (ontologies, subject);
                if (property == NULL) {
                        g_critical ("%s: Unknown property %s", ontology_path, subject);
                        return;
@@ -935,7 +941,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
                                TrackerProperty **super_properties = tracker_property_get_super_properties 
(property);
                                gboolean had = FALSE;
 
-                               super_property = tracker_ontologies_get_property_by_uri (object);
+                               super_property = tracker_ontologies_get_property_by_uri (ontologies, object);
                                if (super_property == NULL) {
                                        g_critical ("%s: Unknown property %s", ontology_path, object);
                                        return;
@@ -977,14 +983,14 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
                        }
 
                        if (!ignore) {
-                               super_property = tracker_ontologies_get_property_by_uri (object);
+                               super_property = tracker_ontologies_get_property_by_uri (ontologies, object);
                                tracker_property_add_super_property (property, super_property);
                        }
 
                        return;
                }
 
-               super_property = tracker_ontologies_get_property_by_uri (object);
+               super_property = tracker_ontologies_get_property_by_uri (ontologies, object);
                if (super_property == NULL) {
                        g_critical ("%s: Unknown property %s", ontology_path, object);
                        return;
@@ -996,13 +1002,13 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
                TrackerClass *domain;
                gboolean is_new;
 
-               property = tracker_ontologies_get_property_by_uri (subject);
+               property = tracker_ontologies_get_property_by_uri (ontologies, subject);
                if (property == NULL) {
                        g_critical ("%s: Unknown property %s", ontology_path, subject);
                        return;
                }
 
-               domain = tracker_ontologies_get_class_by_uri (object);
+               domain = tracker_ontologies_get_class_by_uri (ontologies, object);
                if (domain == NULL) {
                        g_critical ("%s: Unknown class %s", ontology_path, object);
                        return;
@@ -1030,7 +1036,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
                TrackerProperty *property;
                TrackerClass *range;
 
-               property = tracker_ontologies_get_property_by_uri (subject);
+               property = tracker_ontologies_get_property_by_uri (ontologies, subject);
                if (property == NULL) {
                        g_critical ("%s: Unknown property %s", ontology_path, subject);
                        return;
@@ -1049,7 +1055,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
                        }
                }
 
-               range = tracker_ontologies_get_class_by_uri (object);
+               range = tracker_ontologies_get_class_by_uri (ontologies, object);
                if (range == NULL) {
                        g_critical ("%s: Unknown class %s", ontology_path, object);
                        return;
@@ -1059,7 +1065,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
        } else if (g_strcmp0 (predicate, NRL_MAX_CARDINALITY) == 0) {
                TrackerProperty *property;
 
-               property = tracker_ontologies_get_property_by_uri (subject);
+               property = tracker_ontologies_get_property_by_uri (ontologies, subject);
                if (property == NULL) {
                        g_critical ("%s: Unknown property %s", ontology_path, subject);
                        return;
@@ -1076,7 +1082,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
        } else if (g_strcmp0 (predicate, TRACKER_PREFIX_TRACKER "indexed") == 0) {
                TrackerProperty *property;
 
-               property = tracker_ontologies_get_property_by_uri (subject);
+               property = tracker_ontologies_get_property_by_uri (ontologies, subject);
                if (property == NULL) {
                        g_critical ("%s: Unknown property %s", ontology_path, subject);
                        return;
@@ -1086,13 +1092,13 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
        } else if (g_strcmp0 (predicate, TRACKER_PREFIX_TRACKER "secondaryIndex") == 0) {
                TrackerProperty *property, *secondary_index;
 
-               property = tracker_ontologies_get_property_by_uri (subject);
+               property = tracker_ontologies_get_property_by_uri (ontologies, subject);
                if (property == NULL) {
                        g_critical ("%s: Unknown property %s", ontology_path, subject);
                        return;
                }
 
-               secondary_index = tracker_ontologies_get_property_by_uri (object);
+               secondary_index = tracker_ontologies_get_property_by_uri (ontologies, object);
                if (secondary_index == NULL) {
                        g_critical ("%s: Unknown property %s", ontology_path, object);
                        return;
@@ -1103,7 +1109,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
                TrackerProperty *property;
                gboolean is_new;
 
-               property = tracker_ontologies_get_property_by_uri (subject);
+               property = tracker_ontologies_get_property_by_uri (ontologies, subject);
                if (property == NULL) {
                        g_critical ("%s: Unknown property %s", ontology_path, subject);
                        return;
@@ -1138,7 +1144,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
        } else if (g_strcmp0 (predicate, TRACKER_PREFIX_TRACKER "fulltextIndexed") == 0) {
                TrackerProperty *property;
 
-               property = tracker_ontologies_get_property_by_uri (subject);
+               property = tracker_ontologies_get_property_by_uri (ontologies, subject);
                if (property == NULL) {
                        g_critical ("%s: Unknown property %s", ontology_path, subject);
                        return;
@@ -1149,7 +1155,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
        } else if (g_strcmp0 (predicate, TRACKER_PREFIX_TRACKER "defaultValue") == 0) {
                TrackerProperty *property;
 
-               property = tracker_ontologies_get_property_by_uri (subject);
+               property = tracker_ontologies_get_property_by_uri (ontologies, subject);
                if (property == NULL) {
                        g_critical ("%s: Unknown property %s", ontology_path, subject);
                        return;
@@ -1159,7 +1165,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
        } else if (g_strcmp0 (predicate, TRACKER_PREFIX_TRACKER "prefix") == 0) {
                TrackerNamespace *namespace;
 
-               namespace = tracker_ontologies_get_namespace_by_uri (subject);
+               namespace = tracker_ontologies_get_namespace_by_uri (ontologies, subject);
                if (namespace == NULL) {
                        g_critical ("%s: Unknown namespace %s", ontology_path, subject);
                        return;
@@ -1173,7 +1179,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
        } else if (g_strcmp0 (predicate, NAO_LAST_MODIFIED) == 0) {
                TrackerOntology *ontology;
 
-               ontology = tracker_ontologies_get_ontology_by_uri (subject);
+               ontology = tracker_ontologies_get_ontology_by_uri (ontologies, subject);
                if (ontology == NULL) {
                        g_critical ("%s: Unknown ontology %s", ontology_path, subject);
                        return;
@@ -1232,7 +1238,7 @@ check_for_deleted_domain_index (TrackerClass *class)
 
                tracker_class_set_db_schema_changed (class, TRUE);
 
-               properties = tracker_ontologies_get_properties (&n_props);
+               properties = tracker_ontologies_get_properties (ontologies, &n_props);
                for (i = 0; i < n_props; i++) {
                        if (tracker_property_get_domain (properties[i]) == class &&
                            !tracker_property_get_multiple_values (properties[i])) {
@@ -1801,6 +1807,7 @@ get_ontology_from_file (GFile *file)
                                TrackerOntology *ontology;
 
                                ontology = tracker_ontology_new ();
+                               tracker_ontology_set_ontologies (ontology, ontologies);
                                tracker_ontology_set_uri (ontology, subject);
 
                                /* Passes ownership */
@@ -1892,7 +1899,7 @@ tracker_data_ontology_process_statement (const gchar *graph,
                if (g_strcmp0 (object, RDFS_CLASS) == 0) {
                        TrackerClass *class;
 
-                       class = tracker_ontologies_get_class_by_uri (subject);
+                       class = tracker_ontologies_get_class_by_uri (ontologies, subject);
 
                        if (class && tracker_class_get_is_new (class) != in_update) {
                                return;
@@ -1900,7 +1907,7 @@ tracker_data_ontology_process_statement (const gchar *graph,
                } else if (g_strcmp0 (object, RDF_PROPERTY) == 0) {
                        TrackerProperty *prop;
 
-                       prop = tracker_ontologies_get_property_by_uri (subject);
+                       prop = tracker_ontologies_get_property_by_uri (ontologies, subject);
 
                        if (prop && tracker_property_get_is_new (prop) != in_update) {
                                return;
@@ -1908,7 +1915,7 @@ tracker_data_ontology_process_statement (const gchar *graph,
                } else if (g_strcmp0 (object, TRACKER_PREFIX_TRACKER "Namespace") == 0) {
                        TrackerNamespace *namespace;
 
-                       namespace = tracker_ontologies_get_namespace_by_uri (subject);
+                       namespace = tracker_ontologies_get_namespace_by_uri (ontologies, subject);
 
                        if (namespace && tracker_namespace_get_is_new (namespace) != in_update) {
                                return;
@@ -1916,7 +1923,7 @@ tracker_data_ontology_process_statement (const gchar *graph,
                } else if (g_strcmp0 (object, TRACKER_PREFIX_TRACKER "Ontology") == 0) {
                        TrackerOntology *ontology;
 
-                       ontology = tracker_ontologies_get_ontology_by_uri (subject);
+                       ontology = tracker_ontologies_get_ontology_by_uri (ontologies, subject);
 
                        if (ontology && tracker_ontology_get_is_new (ontology) != in_update) {
                                return;
@@ -1925,7 +1932,7 @@ tracker_data_ontology_process_statement (const gchar *graph,
        } else if (g_strcmp0 (predicate, RDFS_SUB_CLASS_OF) == 0) {
                TrackerClass *class;
 
-               class = tracker_ontologies_get_class_by_uri (subject);
+               class = tracker_ontologies_get_class_by_uri (ontologies, subject);
 
                if (class && tracker_class_get_is_new (class) != in_update) {
                        return;
@@ -1939,7 +1946,7 @@ tracker_data_ontology_process_statement (const gchar *graph,
                   g_strcmp0 (predicate, TRACKER_PREFIX_TRACKER "fulltextIndexed") == 0) {
                TrackerProperty *prop;
 
-               prop = tracker_ontologies_get_property_by_uri (subject);
+               prop = tracker_ontologies_get_property_by_uri (ontologies, subject);
 
                if (prop && tracker_property_get_is_new (prop) != in_update) {
                        return;
@@ -1947,7 +1954,7 @@ tracker_data_ontology_process_statement (const gchar *graph,
        } else if (g_strcmp0 (predicate, TRACKER_PREFIX_TRACKER "prefix") == 0) {
                TrackerNamespace *namespace;
 
-               namespace = tracker_ontologies_get_namespace_by_uri (subject);
+               namespace = tracker_ontologies_get_namespace_by_uri (ontologies, subject);
 
                if (namespace && tracker_namespace_get_is_new (namespace) != in_update) {
                        return;
@@ -1955,7 +1962,7 @@ tracker_data_ontology_process_statement (const gchar *graph,
        } else if (g_strcmp0 (predicate, NAO_LAST_MODIFIED) == 0) {
                TrackerOntology *ontology;
 
-               ontology = tracker_ontologies_get_ontology_by_uri (subject);
+               ontology = tracker_ontologies_get_ontology_by_uri (ontologies, subject);
 
                if (ontology && tracker_ontology_get_is_new (ontology) != in_update) {
                        return;
@@ -2056,7 +2063,7 @@ class_add_super_classes_from_db (TrackerDBInterface *iface,
                        const gchar *super_class_uri;
 
                        super_class_uri = tracker_db_cursor_get_string (cursor, 0, NULL);
-                       super_class = tracker_ontologies_get_class_by_uri (super_class_uri);
+                       super_class = tracker_ontologies_get_class_by_uri (ontologies, super_class_uri);
                        tracker_class_add_super_class (class, super_class);
                }
 
@@ -2094,7 +2101,7 @@ class_add_domain_indexes_from_db (TrackerDBInterface *iface,
                        const gchar *domain_index_uri;
 
                        domain_index_uri = tracker_db_cursor_get_string (cursor, 0, NULL);
-                       domain_index = tracker_ontologies_get_property_by_uri (domain_index_uri);
+                       domain_index = tracker_ontologies_get_property_by_uri (ontologies, domain_index_uri);
                        tracker_class_add_domain_index (class, domain_index);
                        tracker_property_add_domain_index (domain_index, class);
                }
@@ -2132,7 +2139,7 @@ property_add_super_properties_from_db (TrackerDBInterface *iface,
                        const gchar *super_property_uri;
 
                        super_property_uri = tracker_db_cursor_get_string (cursor, 0, NULL);
-                       super_property = tracker_ontologies_get_property_by_uri (super_property_uri);
+                       super_property = tracker_ontologies_get_property_by_uri (ontologies, 
super_property_uri);
                        tracker_property_add_super_property (property, super_property);
                }
 
@@ -2167,6 +2174,7 @@ db_get_static_data (TrackerDBInterface  *iface,
                        time_t           last_mod;
 
                        ontology = tracker_ontology_new ();
+                       tracker_ontology_set_ontologies (ontology, ontologies);
 
                        uri = tracker_db_cursor_get_string (cursor, 0, NULL);
                        last_mod = (time_t) tracker_db_cursor_get_int (cursor, 1);
@@ -2174,7 +2182,7 @@ db_get_static_data (TrackerDBInterface  *iface,
                        tracker_ontology_set_is_new (ontology, FALSE);
                        tracker_ontology_set_uri (ontology, uri);
                        tracker_ontology_set_last_modified (ontology, last_mod);
-                       tracker_ontologies_add_ontology (ontology);
+                       tracker_ontologies_add_ontology (ontologies, ontology);
 
                        g_object_unref (ontology);
                }
@@ -2208,10 +2216,11 @@ db_get_static_data (TrackerDBInterface  *iface,
                        uri = tracker_db_cursor_get_string (cursor, 0, NULL);
                        prefix = tracker_db_cursor_get_string (cursor, 1, NULL);
 
+                       tracker_namespace_set_ontologies (namespace, ontologies);
                        tracker_namespace_set_is_new (namespace, FALSE);
                        tracker_namespace_set_uri (namespace, uri);
                        tracker_namespace_set_prefix (namespace, prefix);
-                       tracker_ontologies_add_namespace (namespace);
+                       tracker_ontologies_add_namespace (ontologies, namespace);
 
                        g_object_unref (namespace);
 
@@ -2260,6 +2269,7 @@ db_get_static_data (TrackerDBInterface  *iface,
                                notify = FALSE;
                        }
 
+                       tracker_class_set_ontologies (class, ontologies);
                        tracker_class_set_db_schema_changed (class, FALSE);
                        tracker_class_set_is_new (class, FALSE);
                        tracker_class_set_uri (class, uri);
@@ -2270,8 +2280,8 @@ db_get_static_data (TrackerDBInterface  *iface,
                        /* We do this later, we first need to load the properties too
                           class_add_domain_indexes_from_db (iface, class); */
 
-                       tracker_ontologies_add_class (class);
-                       tracker_ontologies_add_id_uri_pair (id, uri);
+                       tracker_ontologies_add_class (ontologies, class);
+                       tracker_ontologies_add_id_uri_pair (ontologies, id, uri);
                        tracker_class_set_id (class, id);
 
                        g_object_unref (class);
@@ -2402,14 +2412,15 @@ db_get_static_data (TrackerDBInterface  *iface,
 
                        default_value = tracker_db_cursor_get_string (cursor, 12, NULL);
 
-                       tracker_property_set_is_new_domain_index (property, 
tracker_ontologies_get_class_by_uri (domain_uri), FALSE);
+                       tracker_property_set_ontologies (property, ontologies);
+                       tracker_property_set_is_new_domain_index (property, 
tracker_ontologies_get_class_by_uri (ontologies, domain_uri), FALSE);
                        tracker_property_set_is_new (property, FALSE);
                        tracker_property_set_cardinality_changed (property, FALSE);
                        tracker_property_set_transient (property, transient);
                        tracker_property_set_uri (property, uri);
                        tracker_property_set_id (property, id);
-                       tracker_property_set_domain (property, tracker_ontologies_get_class_by_uri 
(domain_uri));
-                       tracker_property_set_range (property, tracker_ontologies_get_class_by_uri 
(range_uri));
+                       tracker_property_set_domain (property, tracker_ontologies_get_class_by_uri 
(ontologies, domain_uri));
+                       tracker_property_set_range (property, tracker_ontologies_get_class_by_uri 
(ontologies, range_uri));
                        tracker_property_set_multiple_values (property, multi_valued);
                        tracker_property_set_orig_multiple_values (property, multi_valued);
                        tracker_property_set_indexed (property, indexed);
@@ -2420,7 +2431,7 @@ db_get_static_data (TrackerDBInterface  *iface,
                        tracker_property_set_writeback (property, writeback);
 
                        if (secondary_index_uri) {
-                               tracker_property_set_secondary_index (property, 
tracker_ontologies_get_property_by_uri (secondary_index_uri));
+                               tracker_property_set_secondary_index (property, 
tracker_ontologies_get_property_by_uri (ontologies, secondary_index_uri));
                        }
 
                        tracker_property_set_orig_fulltext_indexed (property, fulltext_indexed);
@@ -2432,8 +2443,8 @@ db_get_static_data (TrackerDBInterface  *iface,
                                property_add_super_properties_from_db (iface, property);
                        }
 
-                       tracker_ontologies_add_property (property);
-                       tracker_ontologies_add_id_uri_pair (id, uri);
+                       tracker_ontologies_add_property (ontologies, property);
+                       tracker_ontologies_add_id_uri_pair (ontologies, id, uri);
 
                        g_object_unref (property);
 
@@ -2444,7 +2455,7 @@ db_get_static_data (TrackerDBInterface  *iface,
        }
 
        /* Now that the properties are loaded we can do this foreach class */
-       classes = tracker_ontologies_get_classes (&n_classes);
+       classes = tracker_ontologies_get_classes (ontologies, &n_classes);
        for (i = 0; i < n_classes; i++) {
                class_add_domain_indexes_from_db (iface, classes[i]);
        }
@@ -2880,7 +2891,7 @@ create_decomposed_metadata_tables (TrackerDBInterface  *iface,
                }
        }
 
-       properties = tracker_ontologies_get_properties (&n_props);
+       properties = tracker_ontologies_get_properties (ontologies, &n_props);
        domain_indexes = tracker_class_get_domain_indexes (service);
 
        for (i = 0; i < n_props; i++) {
@@ -3280,7 +3291,7 @@ clean_decomposed_transient_metadata (TrackerDBInterface *iface)
        TrackerProperty *property;
        guint i, n_props;
 
-       properties = tracker_ontologies_get_properties (&n_props);
+       properties = tracker_ontologies_get_properties (ontologies, &n_props);
 
        for (i = 0; i < n_props; i++) {
                property = properties[i];
@@ -3325,8 +3336,8 @@ tracker_data_ontology_import_finished (void)
        TrackerProperty **properties;
        guint i, n_props, n_classes;
 
-       classes = tracker_ontologies_get_classes (&n_classes);
-       properties = tracker_ontologies_get_properties (&n_props);
+       classes = tracker_ontologies_get_classes (ontologies, &n_classes);
+       properties = tracker_ontologies_get_properties (ontologies, &n_props);
 
        for (i = 0; i < n_classes; i++) {
                tracker_class_set_is_new (classes[i], FALSE);
@@ -3353,8 +3364,8 @@ tracker_data_ontology_import_into_db (gboolean   in_update,
 
        iface = tracker_db_manager_get_db_interface ();
 
-       classes = tracker_ontologies_get_classes (&n_classes);
-       properties = tracker_ontologies_get_properties (&n_props);
+       classes = tracker_ontologies_get_classes (ontologies, &n_classes);
+       properties = tracker_ontologies_get_properties (ontologies, &n_props);
 
        /* create tables */
        for (i = 0; i < n_classes; i++) {
@@ -3515,7 +3526,7 @@ tracker_data_manager_recreate_indexes (TrackerBusyCallback    busy_callback,
        guint n_properties;
        guint i;
 
-       properties = tracker_ontologies_get_properties (&n_properties);
+       properties = tracker_ontologies_get_properties (ontologies, &n_properties);
        if (!properties) {
                g_critical ("Couldn't get all properties to recreate indexes");
                return;
@@ -3611,7 +3622,7 @@ write_ontologies_gvdb (gboolean   overwrite,
        g_object_unref (child);
 
        if (overwrite || !g_file_test (filename, G_FILE_TEST_EXISTS)) {
-               retval = tracker_ontologies_write_gvdb (filename, error);
+               retval = tracker_ontologies_write_gvdb (ontologies, filename, error);
        }
 
        g_free (filename);
@@ -3629,7 +3640,8 @@ load_ontologies_gvdb (GError **error)
        filename = g_file_get_path (child);
        g_object_unref (child);
 
-       tracker_ontologies_load_gvdb (filename, error);
+       g_object_unref (ontologies);
+       ontologies = tracker_ontologies_load_gvdb (filename, error);
 
        g_free (filename);
 }
@@ -3644,7 +3656,7 @@ ontology_get_fts_properties (gboolean     only_new,
        gboolean has_changed = FALSE;
        guint i, len;
 
-       properties = tracker_ontologies_get_properties (&len);
+       properties = tracker_ontologies_get_properties (ontologies, &len);
        *multivalued = g_hash_table_new (g_str_hash, g_str_equal);
        *fts_properties = g_hash_table_new_full (g_str_hash, g_str_equal,
                                                 NULL, (GDestroyNotify) g_list_free);
@@ -3791,7 +3803,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
        }
 
        /* Make sure we initialize all other modules we depend on */
-       tracker_ontologies_init ();
+       ontologies = tracker_ontologies_new ();
 
        if (!reloading) {
                tracker_locale_sanity_check ();
@@ -3815,7 +3827,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                                      &internal_error)) {
                g_propagate_error (error, internal_error);
 
-               tracker_ontologies_shutdown ();
+               g_clear_object (&ontologies);
                tracker_data_update_shutdown ();
 
                return FALSE;
@@ -3859,7 +3871,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                                g_propagate_error (error, internal_error);
 
                                tracker_db_manager_shutdown ();
-                               tracker_ontologies_shutdown ();
+                               g_clear_object (&ontologies);
                                tracker_data_update_shutdown ();
 
                                return FALSE;
@@ -3885,7 +3897,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                             "'%s' is not a ontology location", uri);
                g_free (uri);
                tracker_db_manager_shutdown ();
-               tracker_ontologies_shutdown ();
+               g_clear_object (&ontologies);
                tracker_data_update_shutdown ();
                return FALSE;
        }
@@ -3909,7 +3921,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                                        g_propagate_error (error, internal_error);
 
                                        tracker_db_manager_shutdown ();
-                                       tracker_ontologies_shutdown ();
+                                       g_clear_object (&ontologies);
                                        tracker_data_update_shutdown ();
 
                                        return FALSE;
@@ -3942,7 +3954,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                        g_propagate_error (error, internal_error);
 
                        tracker_db_manager_shutdown ();
-                       tracker_ontologies_shutdown ();
+                       g_clear_object (&ontologies);
                        tracker_data_update_shutdown ();
 
                        return FALSE;
@@ -3982,7 +3994,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                        ontology_writer = NULL;
 #endif /* DISABLE_JOURNAL */
                        tracker_db_manager_shutdown ();
-                       tracker_ontologies_shutdown ();
+                       g_clear_object (&ontologies);
                        tracker_data_update_shutdown ();
 
                        return FALSE;
@@ -4001,7 +4013,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                        ontology_writer = NULL;
 #endif /* DISABLE_JOURNAL */
                        tracker_db_manager_shutdown ();
-                       tracker_ontologies_shutdown ();
+                       g_clear_object (&ontologies);
                        tracker_data_update_shutdown ();
 
                        return FALSE;
@@ -4025,7 +4037,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                                        tracker_db_journal_free (ontology_writer, NULL);
                                        ontology_writer = NULL;
                                        tracker_db_manager_shutdown ();
-                                       tracker_ontologies_shutdown ();
+                                       g_clear_object (&ontologies);
                                        tracker_data_update_shutdown ();
 
                                        return FALSE;
@@ -4044,7 +4056,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                if (internal_error) {
                        g_propagate_error (error, internal_error);
                        tracker_db_manager_shutdown ();
-                       tracker_ontologies_shutdown ();
+                       g_clear_object (&ontologies);
 #ifndef DISABLE_JOURNAL
                        tracker_db_journal_free (ontology_writer, NULL);
                        ontology_writer = NULL;
@@ -4076,7 +4088,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                                g_propagate_error (error, internal_error);
 
                                tracker_db_manager_shutdown ();
-                               tracker_ontologies_shutdown ();
+                               g_clear_object (&ontologies);
                                tracker_data_update_shutdown ();
 
                                return FALSE;
@@ -4234,7 +4246,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                                                        ontology_writer = NULL;
 #endif /* DISABLE_JOURNAL */
                                                        tracker_db_manager_shutdown ();
-                                                       tracker_ontologies_shutdown ();
+                                                       g_clear_object (&ontologies);
                                                        tracker_data_update_shutdown ();
 
                                                        return FALSE;
@@ -4324,7 +4336,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                                                ontology_writer = NULL;
 #endif /* DISABLE_JOURNAL */
                                                tracker_db_manager_shutdown ();
-                                               tracker_ontologies_shutdown ();
+                                               g_clear_object (&ontologies);
                                                tracker_data_update_shutdown ();
 
                                                return FALSE;
@@ -4505,7 +4517,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                                ontology_writer = NULL;
 #endif /* DISABLE_JOURNAL */
                                tracker_db_manager_shutdown ();
-                               tracker_ontologies_shutdown ();
+                               g_clear_object (&ontologies);
                                tracker_data_update_shutdown ();
 
                                return FALSE;
@@ -4539,7 +4551,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                                ontology_writer = NULL;
 #endif /* DISABLE_JOURNAL */
                                tracker_db_manager_shutdown ();
-                               tracker_ontologies_shutdown ();
+                               g_clear_object (&ontologies);
                                tracker_data_update_shutdown ();
 
                                return FALSE;
@@ -4587,7 +4599,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                        g_propagate_error (error, internal_error);
 
                        tracker_db_manager_shutdown ();
-                       tracker_ontologies_shutdown ();
+                       g_clear_object (&ontologies);
                        tracker_data_update_shutdown ();
 
                        return FALSE;
@@ -4604,7 +4616,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                g_propagate_error (error, internal_error);
 
                tracker_db_manager_shutdown ();
-               tracker_ontologies_shutdown ();
+               g_clear_object (&ontologies);
                tracker_data_update_shutdown ();
 
                return FALSE;
@@ -4633,7 +4645,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                        tracker_db_journal_free (journal_writer, NULL);
 #endif /* DISABLE_JOURNAL */
                        tracker_db_manager_shutdown ();
-                       tracker_ontologies_shutdown ();
+                       g_clear_object (&ontologies);
                        tracker_data_update_shutdown ();
 
                        return FALSE;
@@ -4649,7 +4661,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
        }
 
        if (!read_only) {
-               tracker_ontologies_sort ();
+               tracker_ontologies_sort (ontologies);
        }
 
        initialized = TRUE;
@@ -4688,7 +4700,7 @@ tracker_data_manager_shutdown (void)
 #endif /* DISABLE_JOURNAL */
 
        tracker_db_manager_shutdown ();
-       tracker_ontologies_shutdown ();
+       g_clear_object (&ontologies);
 
 #if HAVE_TRACKER_FTS
        if (!tracker_fts_shutdown ()) {
@@ -4714,3 +4726,9 @@ tracker_data_manager_get_ontology_writer (void)
        return ontology_writer;
 }
 #endif
+
+TrackerOntologies *
+tracker_data_manager_get_ontologies (void)
+{
+       return ontologies;
+}
diff --git a/src/libtracker-data/tracker-data-manager.h b/src/libtracker-data/tracker-data-manager.h
index 520df12..47200d4 100644
--- a/src/libtracker-data/tracker-data-manager.h
+++ b/src/libtracker-data/tracker-data-manager.h
@@ -72,6 +72,7 @@ GFile * tracker_data_manager_get_cache_location();
 GFile * tracker_data_manager_get_data_location ();
 TrackerDBJournal * tracker_data_manager_get_journal_writer (void);
 TrackerDBJournal * tracker_data_manager_get_ontology_writer (void);
+TrackerOntologies * tracker_data_manager_get_ontologies (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 4b93aff..79cde12 100644
--- a/src/libtracker-data/tracker-data-query.c
+++ b/src/libtracker-data/tracker-data-query.c
@@ -41,8 +41,10 @@ tracker_data_query_rdf_type (gint id)
        TrackerDBStatement *stmt;
        GPtrArray *ret = NULL;
        GError *error = NULL;
+       TrackerOntologies *ontologies;
 
        iface = tracker_db_manager_get_db_interface ();
+       ontologies = tracker_data_manager_get_ontologies ();
 
        stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
                                                      "SELECT (SELECT Uri FROM Resource WHERE ID = 
\"rdf:type\") "
@@ -67,7 +69,7 @@ tracker_data_query_rdf_type (gint id)
                        TrackerClass *cl;
 
                        class_uri = tracker_db_cursor_get_string (cursor, 0, NULL);
-                       cl = tracker_ontologies_get_class_by_uri (class_uri);
+                       cl = tracker_ontologies_get_class_by_uri (ontologies, class_uri);
                        if (!cl) {
                                g_critical ("Unknown class %s", class_uri);
                                continue;
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 725ae84..9206aa2 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -1157,6 +1157,7 @@ cache_create_service_decomposed (TrackerClass *cl,
        TrackerProperty    **domain_indexes;
        GValue              gvalue = { 0 };
        gint                i, final_graph_id, class_id;
+       TrackerOntologies  *ontologies;
 
        /* also create instance of all super classes */
        super_classes = tracker_class_get_super_classes (cl);
@@ -1184,6 +1185,7 @@ cache_create_service_decomposed (TrackerClass *cl,
         * class_id = ensure_resource_id (tracker_class_get_uri (cl), NULL); */
 
        class_id = tracker_class_get_id (cl);
+       ontologies = tracker_data_manager_get_ontologies ();
 
        g_value_set_int64 (&gvalue, class_id);
        cache_insert_value ("rdfs:Resource_rdf:type", "rdf:type", FALSE, &gvalue,
@@ -1200,7 +1202,7 @@ cache_create_service_decomposed (TrackerClass *cl,
 
                        delegate = g_ptr_array_index (insert_callbacks, n);
                        delegate->callback (final_graph_id, graph, resource_buffer->id, 
resource_buffer->subject,
-                                           tracker_property_get_id (tracker_ontologies_get_rdf_type ()),
+                                           tracker_property_get_id (tracker_ontologies_get_rdf_type 
(ontologies)),
                                            class_id,
                                            tracker_class_get_uri (cl),
                                            resource_buffer->types,
@@ -1450,13 +1452,15 @@ get_old_property_values (TrackerProperty  *property,
                        iface = tracker_db_manager_get_db_interface ();
 
                        if (!resource_buffer->fts_updated && !resource_buffer->create) {
+                               TrackerOntologies *ontologies;
                                guint i, n_props;
                                TrackerProperty   **properties, *prop;
 
                                /* first fulltext indexed property to be modified
                                 * retrieve values of all fulltext indexed properties
                                 */
-                               properties = tracker_ontologies_get_properties (&n_props);
+                               ontologies = tracker_data_manager_get_ontologies ();
+                               properties = tracker_ontologies_get_properties (ontologies, &n_props);
 
                                for (i = 0; i < n_props; i++) {
                                        prop = properties[i];
@@ -1817,8 +1821,10 @@ delete_first_object (TrackerProperty  *field,
                                g_strcmp0 (graph, TRACKER_OWN_GRAPH_URN) == 0) {
                                /* do not journal this statement extracted from filesystem */
                                TrackerProperty *damaged;
+                               TrackerOntologies *ontologies;
 
-                               damaged = tracker_ontologies_get_property_by_uri (TRACKER_PREFIX_TRACKER 
"damaged");
+                               ontologies = tracker_data_manager_get_ontologies ();
+                               damaged = tracker_ontologies_get_property_by_uri (ontologies, 
TRACKER_PREFIX_TRACKER "damaged");
 
                                tracker_db_journal_append_insert_statement (journal_writer,
                                                                            graph_id,
@@ -2082,8 +2088,10 @@ cache_delete_resource_type_full (TrackerClass *class,
        gint                i;
        guint               p, n_props;
        GError             *error = NULL;
+       TrackerOntologies  *ontologies;
 
        iface = tracker_db_manager_get_db_interface ();
+       ontologies = tracker_data_manager_get_ontologies ();
 
        if (!single_type) {
                if (strcmp (tracker_class_get_uri (class), TRACKER_PREFIX_RDFS "Resource") == 0 &&
@@ -2140,7 +2148,7 @@ cache_delete_resource_type_full (TrackerClass *class,
                                const gchar *class_uri;
 
                                class_uri = tracker_db_cursor_get_string (cursor, 0, NULL);
-                               cache_delete_resource_type_full (tracker_ontologies_get_class_by_uri 
(class_uri),
+                               cache_delete_resource_type_full (tracker_ontologies_get_class_by_uri 
(ontologies, class_uri),
                                                                 graph, graph_id, FALSE);
                        }
 
@@ -2159,7 +2167,7 @@ cache_delete_resource_type_full (TrackerClass *class,
 
        /* delete all property values */
 
-       properties = tracker_ontologies_get_properties (&n_props);
+       properties = tracker_ontologies_get_properties (ontologies, &n_props);
 
        for (p = 0; p < n_props; p++) {
                gboolean            multiple_values;
@@ -2268,7 +2276,7 @@ cache_delete_resource_type_full (TrackerClass *class,
 
                        delegate = g_ptr_array_index (delete_callbacks, n);
                        delegate->callback (final_graph_id, graph, resource_buffer->id, 
resource_buffer->subject,
-                                           tracker_property_get_id (tracker_ontologies_get_rdf_type ()),
+                                           tracker_property_get_id (tracker_ontologies_get_rdf_type 
(ontologies)),
                                            tracker_class_get_id (class),
                                            tracker_class_get_uri (class),
                                            resource_buffer->types,
@@ -2360,6 +2368,7 @@ tracker_data_delete_statement (const gchar  *graph,
        TrackerClass       *class;
        gint                subject_id = 0;
        gboolean            change = FALSE;
+       TrackerOntologies  *ontologies;
 
        g_return_if_fail (subject != NULL);
        g_return_if_fail (predicate != NULL);
@@ -2374,9 +2383,10 @@ tracker_data_delete_statement (const gchar  *graph,
        }
 
        resource_buffer_switch (graph, subject, subject_id);
+       ontologies = tracker_data_manager_get_ontologies ();
 
        if (object && g_strcmp0 (predicate, TRACKER_PREFIX_RDF "type") == 0) {
-               class = tracker_ontologies_get_class_by_uri (object);
+               class = tracker_ontologies_get_class_by_uri (ontologies, object);
                if (class != NULL) {
                        has_persistent = TRUE;
 
@@ -2401,7 +2411,7 @@ tracker_data_delete_statement (const gchar  *graph,
                gboolean tried = FALSE;
                TrackerProperty *field;
 
-               field = tracker_ontologies_get_property_by_uri (predicate);
+               field = tracker_ontologies_get_property_by_uri (ontologies, predicate);
                if (field != NULL) {
                        if (!tracker_property_get_transient (field)) {
                                has_persistent = TRUE;
@@ -2435,7 +2445,7 @@ tracker_data_delete_statement (const gchar  *graph,
                                                /* do not journal this statement extracted from filesystem */
                                                TrackerProperty *damaged;
 
-                                               damaged = tracker_ontologies_get_property_by_uri 
(TRACKER_PREFIX_TRACKER "damaged");
+                                               damaged = tracker_ontologies_get_property_by_uri (ontologies, 
TRACKER_PREFIX_TRACKER "damaged");
 
                                                tracker_db_journal_append_insert_statement (journal_writer,
                                                                                            graph_id,
@@ -2493,6 +2503,7 @@ delete_all_objects (const gchar  *graph,
        gboolean change = FALSE;
        GError *new_error = NULL;
        TrackerProperty *field;
+       TrackerOntologies *ontologies;
 
        g_return_if_fail (subject != NULL);
        g_return_if_fail (predicate != NULL);
@@ -2506,8 +2517,9 @@ delete_all_objects (const gchar  *graph,
        }
 
        resource_buffer_switch (graph, subject, subject_id);
+       ontologies = tracker_data_manager_get_ontologies ();
 
-       field = tracker_ontologies_get_property_by_uri (predicate);
+       field = tracker_ontologies_get_property_by_uri (ontologies, predicate);
        if (field != NULL) {
                GArray *old_values;
 
@@ -2595,13 +2607,16 @@ tracker_data_insert_statement (const gchar            *graph,
                                GError                **error)
 {
        TrackerProperty *property;
+       TrackerOntologies *ontologies;
 
        g_return_if_fail (subject != NULL);
        g_return_if_fail (predicate != NULL);
        g_return_if_fail (object != NULL);
        g_return_if_fail (in_transaction);
 
-       property = tracker_ontologies_get_property_by_uri (predicate);
+       ontologies = tracker_data_manager_get_ontologies ();
+
+       property = tracker_ontologies_get_property_by_uri (ontologies, predicate);
        if (property != NULL) {
                if (tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_RESOURCE) {
                        tracker_data_insert_statement_with_uri (graph, subject, predicate, object, error);
@@ -2677,13 +2692,16 @@ tracker_data_insert_statement_with_uri (const gchar            *graph,
        gint             prop_id = 0, graph_id = 0;
        gint             final_prop_id = 0, object_id = 0;
        gboolean change = FALSE;
+       TrackerOntologies *ontologies;
 
        g_return_if_fail (subject != NULL);
        g_return_if_fail (predicate != NULL);
        g_return_if_fail (object != NULL);
        g_return_if_fail (in_transaction);
 
-       property = tracker_ontologies_get_property_by_uri (predicate);
+       ontologies = tracker_data_manager_get_ontologies ();
+
+       property = tracker_ontologies_get_property_by_uri (ontologies, predicate);
        if (property == NULL) {
                g_set_error (error, TRACKER_SPARQL_ERROR, TRACKER_SPARQL_ERROR_UNKNOWN_PROPERTY,
                             "Property '%s' not found in the ontology", predicate);
@@ -2722,10 +2740,10 @@ tracker_data_insert_statement_with_uri (const gchar            *graph,
                return;
        }
 
-       if (property == tracker_ontologies_get_rdf_type ()) {
+       if (property == tracker_ontologies_get_rdf_type (ontologies)) {
                /* handle rdf:type statements specially to
                   cope with inference and insert blank rows */
-               class = tracker_ontologies_get_class_by_uri (object);
+               class = tracker_ontologies_get_class_by_uri (ontologies, object);
                if (class != NULL) {
                        cache_create_service_decomposed (class, graph, 0);
                } else {
@@ -2794,6 +2812,7 @@ tracker_data_insert_statement_with_string (const gchar            *graph,
        TrackerProperty *property;
        gboolean         change;
        gint             graph_id = 0, pred_id = 0;
+       TrackerOntologies *ontologies;
 #ifndef DISABLE_JOURNAL
        gboolean         tried = FALSE;
 #endif
@@ -2803,7 +2822,9 @@ tracker_data_insert_statement_with_string (const gchar            *graph,
        g_return_if_fail (object != NULL);
        g_return_if_fail (in_transaction);
 
-       property = tracker_ontologies_get_property_by_uri (predicate);
+       ontologies = tracker_data_manager_get_ontologies ();
+
+       property = tracker_ontologies_get_property_by_uri (ontologies, predicate);
        if (property == NULL) {
                g_set_error (error, TRACKER_SPARQL_ERROR, TRACKER_SPARQL_ERROR_UNKNOWN_PROPERTY,
                             "Property '%s' not found in the ontology", predicate);
@@ -2869,7 +2890,7 @@ tracker_data_insert_statement_with_string (const gchar            *graph,
                        /* do not journal this statement extracted from filesystem */
                        TrackerProperty *damaged;
 
-                       damaged = tracker_ontologies_get_property_by_uri (TRACKER_PREFIX_TRACKER "damaged");
+                       damaged = tracker_ontologies_get_property_by_uri (ontologies, TRACKER_PREFIX_TRACKER 
"damaged");
                        tracker_db_journal_append_insert_statement (journal_writer,
                                                                    graph_id,
                                                                    resource_buffer->id,
@@ -2899,12 +2920,15 @@ tracker_data_update_statement_with_uri (const gchar            *graph,
        gint             prop_id = 0, graph_id = 0;
        gint             final_prop_id = 0, object_id = 0;
        gboolean         change = FALSE;
+       TrackerOntologies *ontologies;
 
        g_return_if_fail (subject != NULL);
        g_return_if_fail (predicate != NULL);
        g_return_if_fail (in_transaction);
 
-       property = tracker_ontologies_get_property_by_uri (predicate);
+       ontologies = tracker_data_manager_get_ontologies ();
+
+       property = tracker_ontologies_get_property_by_uri (ontologies, predicate);
        if (property == NULL) {
                g_set_error (error, TRACKER_SPARQL_ERROR, TRACKER_SPARQL_ERROR_UNKNOWN_PROPERTY,
                             "Property '%s' not found in the ontology", predicate);
@@ -2944,10 +2968,10 @@ tracker_data_update_statement_with_uri (const gchar            *graph,
                return;
        }
 
-       if (property == tracker_ontologies_get_rdf_type ()) {
+       if (property == tracker_ontologies_get_rdf_type (ontologies)) {
                /* handle rdf:type statements specially to
                   cope with inference and insert blank rows */
-               class = tracker_ontologies_get_class_by_uri (object);
+               class = tracker_ontologies_get_class_by_uri (ontologies, object);
                if (class != NULL) {
                        /* Create here is fine for Update too */
                        cache_create_service_decomposed (class, graph, 0);
@@ -3102,6 +3126,7 @@ tracker_data_update_statement_with_string (const gchar            *graph,
        gboolean change;
        gint graph_id = 0, pred_id = 0;
        gboolean multiple_values;
+       TrackerOntologies *ontologies;
 #ifndef DISABLE_JOURNAL
        gboolean tried = FALSE;
 #endif
@@ -3113,7 +3138,9 @@ tracker_data_update_statement_with_string (const gchar            *graph,
        g_return_if_fail (predicate != NULL);
        g_return_if_fail (in_transaction);
 
-       property = tracker_ontologies_get_property_by_uri (predicate);
+       ontologies = tracker_data_manager_get_ontologies ();
+
+       property = tracker_ontologies_get_property_by_uri (ontologies, predicate);
        if (property == NULL) {
                g_set_error (error, TRACKER_SPARQL_ERROR, TRACKER_SPARQL_ERROR_UNKNOWN_PROPERTY,
                             "Property '%s' not found in the ontology", predicate);
@@ -3217,7 +3244,7 @@ tracker_data_update_statement_with_string (const gchar            *graph,
                        /* do not journal this statement extracted from filesystem */
                        TrackerProperty *damaged;
 
-                       damaged = tracker_ontologies_get_property_by_uri (TRACKER_PREFIX_TRACKER "damaged");
+                       damaged = tracker_ontologies_get_property_by_uri (ontologies, TRACKER_PREFIX_TRACKER 
"damaged");
                        tracker_db_journal_append_update_statement (journal_writer,
                                                                    graph_id,
                                                                    resource_buffer->id,
@@ -3242,16 +3269,19 @@ tracker_data_update_statement (const gchar            *graph,
                                GError                **error)
 {
        TrackerProperty *property;
+       TrackerOntologies *ontologies;
 
        g_return_if_fail (subject != NULL);
        g_return_if_fail (predicate != NULL);
        g_return_if_fail (in_transaction);
 
-       property = tracker_ontologies_get_property_by_uri (predicate);
+       ontologies = tracker_data_manager_get_ontologies ();
+       property = tracker_ontologies_get_property_by_uri (ontologies, predicate);
+
        if (property != NULL) {
                if (object == NULL) {
                        GError *new_error = NULL;
-                       if (property == tracker_ontologies_get_rdf_type ()) {
+                       if (property == tracker_ontologies_get_rdf_type (ontologies)) {
                                g_set_error (error, TRACKER_SPARQL_ERROR, TRACKER_SPARQL_ERROR_UNSUPPORTED,
                                             "Using 'null' with '%s' is not supported", predicate);
                                return;
@@ -3579,8 +3609,10 @@ tracker_data_replay_journal (TrackerBusyCallback   busy_callback,
        GError *n_error = NULL;
        GFile *data_location;
        TrackerDBJournalReader *reader;
+       TrackerOntologies *ontologies;
 
-       rdf_type = tracker_ontologies_get_rdf_type ();
+       ontologies = tracker_data_manager_get_ontologies ();
+       rdf_type = tracker_ontologies_get_rdf_type (ontologies);
 
        data_location = tracker_data_manager_get_data_location ();
        reader = tracker_db_journal_reader_new (data_location, &n_error);
@@ -3657,9 +3689,9 @@ tracker_data_replay_journal (TrackerBusyCallback   busy_callback,
                        }
                        last_operation_type = 1;
 
-                       uri = tracker_ontologies_get_uri_by_id (predicate_id);
+                       uri = tracker_ontologies_get_uri_by_id (ontologies, predicate_id);
                        if (uri) {
-                               property = tracker_ontologies_get_property_by_uri (uri);
+                               property = tracker_ontologies_get_property_by_uri (ontologies, uri);
                        }
 
                        if (property) {
@@ -3696,9 +3728,9 @@ tracker_data_replay_journal (TrackerBusyCallback   busy_callback,
                        }
                        last_operation_type = 1;
 
-                       uri = tracker_ontologies_get_uri_by_id (predicate_id);
+                       uri = tracker_ontologies_get_uri_by_id (ontologies, predicate_id);
                        if (uri) {
-                               property = tracker_ontologies_get_property_by_uri (uri);
+                               property = tracker_ontologies_get_property_by_uri (ontologies, uri);
                        }
 
                        if (property) {
@@ -3708,9 +3740,9 @@ tracker_data_replay_journal (TrackerBusyCallback   busy_callback,
                                        resource_buffer_switch (NULL, NULL, subject_id);
 
                                        if (property == rdf_type) {
-                                               uri = tracker_ontologies_get_uri_by_id (object_id);
+                                               uri = tracker_ontologies_get_uri_by_id (ontologies, 
object_id);
                                                if (uri) {
-                                                       class = tracker_ontologies_get_class_by_uri (uri);
+                                                       class = tracker_ontologies_get_class_by_uri 
(ontologies, uri);
                                                }
                                                if (class) {
                                                        cache_create_service_decomposed (class, NULL, 
graph_id);
@@ -3754,9 +3786,9 @@ tracker_data_replay_journal (TrackerBusyCallback   busy_callback,
 
                        resource_buffer_switch (NULL, NULL, subject_id);
 
-                       uri = tracker_ontologies_get_uri_by_id (predicate_id);
+                       uri = tracker_ontologies_get_uri_by_id (ontologies, predicate_id);
                        if (uri) {
-                               property = tracker_ontologies_get_property_by_uri (uri);
+                               property = tracker_ontologies_get_property_by_uri (ontologies, uri);
                        }
 
                        if (property) {
@@ -3765,7 +3797,7 @@ tracker_data_replay_journal (TrackerBusyCallback   busy_callback,
                                if (object && rdf_type == property) {
                                        TrackerClass *class;
 
-                                       class = tracker_ontologies_get_class_by_uri (object);
+                                       class = tracker_ontologies_get_class_by_uri (ontologies, object);
                                        if (class != NULL) {
                                                cache_delete_resource_type (class, NULL, graph_id);
                                        } else {
@@ -3800,9 +3832,9 @@ tracker_data_replay_journal (TrackerBusyCallback   busy_callback,
                        }
                        last_operation_type = -1;
 
-                       uri = tracker_ontologies_get_uri_by_id (predicate_id);
+                       uri = tracker_ontologies_get_uri_by_id (ontologies, predicate_id);
                        if (uri) {
-                               property = tracker_ontologies_get_property_by_uri (uri);
+                               property = tracker_ontologies_get_property_by_uri (ontologies, uri);
                        }
 
                        if (property) {
@@ -3810,9 +3842,9 @@ tracker_data_replay_journal (TrackerBusyCallback   busy_callback,
                                resource_buffer_switch (NULL, NULL, subject_id);
 
                                if (property == rdf_type) {
-                                       uri = tracker_ontologies_get_uri_by_id (object_id);
+                                       uri = tracker_ontologies_get_uri_by_id (ontologies, object_id);
                                        if (uri) {
-                                               class = tracker_ontologies_get_class_by_uri (uri);
+                                               class = tracker_ontologies_get_class_by_uri (ontologies, uri);
                                        }
                                        if (class) {
                                                cache_delete_resource_type (class, NULL, graph_id);
diff --git a/src/libtracker-data/tracker-namespace.c b/src/libtracker-data/tracker-namespace.c
index efcd794..9134a2d 100644
--- a/src/libtracker-data/tracker-namespace.c
+++ b/src/libtracker-data/tracker-namespace.c
@@ -37,6 +37,7 @@ struct _TrackerNamespacePrivate {
 
        gchar *prefix;
        gboolean is_new;
+       TrackerOntologies *ontologies;
 };
 
 static void namespace_finalize     (GObject      *object);
@@ -110,7 +111,7 @@ tracker_namespace_get_prefix (TrackerNamespace *namespace)
        priv = GET_PRIV (namespace);
 
        if (!priv->prefix && priv->use_gvdb) {
-               priv->prefix = g_strdup (tracker_ontologies_get_namespace_string_gvdb (priv->uri, "prefix"));
+               priv->prefix = g_strdup (tracker_ontologies_get_namespace_string_gvdb (priv->ontologies, 
priv->uri, "prefix"));
        }
 
        return priv->prefix;
@@ -178,3 +179,16 @@ tracker_namespace_set_is_new (TrackerNamespace *namespace,
 
        priv->is_new = value;
 }
+
+void
+tracker_namespace_set_ontologies (TrackerNamespace  *namespace,
+                                  TrackerOntologies *ontologies)
+{
+       TrackerNamespacePrivate *priv;
+
+       g_return_if_fail (TRACKER_IS_NAMESPACE (namespace));
+       g_return_if_fail (ontologies != NULL);
+       priv = GET_PRIV (namespace);
+
+       priv->ontologies = ontologies;
+}
diff --git a/src/libtracker-data/tracker-namespace.h b/src/libtracker-data/tracker-namespace.h
index 6d1cc7d..dccc24b 100644
--- a/src/libtracker-data/tracker-namespace.h
+++ b/src/libtracker-data/tracker-namespace.h
@@ -21,6 +21,7 @@
 #define __LIBTRACKER_DATA_NAMESPACE_H__
 
 #include <glib-object.h>
+#include "tracker-class.h"
 
 G_BEGIN_DECLS
 
@@ -61,6 +62,8 @@ void              tracker_namespace_set_prefix    (TrackerNamespace *namespace_,
                                                    const gchar      *value);
 void              tracker_namespace_set_is_new    (TrackerNamespace *namespace_,
                                                    gboolean         value);
+void              tracker_namespace_set_ontologies (TrackerNamespace  *namespace,
+                                                    TrackerOntologies *ontologies);
 
 G_END_DECLS
 
diff --git a/src/libtracker-data/tracker-ontologies.c b/src/libtracker-data/tracker-ontologies.c
index 3926a59..b8cbd90 100644
--- a/src/libtracker-data/tracker-ontologies.c
+++ b/src/libtracker-data/tracker-ontologies.c
@@ -32,203 +32,196 @@
 
 #include "tracker-ontologies.h"
 
-static gboolean    initialized;
+typedef struct _TrackerOntologiesPrivate TrackerOntologiesPrivate;
 
-/* List of TrackerNamespace objects */
-static GPtrArray  *namespaces;
+struct _TrackerOntologiesPrivate {
+       /* List of TrackerNamespace objects */
+       GPtrArray  *namespaces;
 
-/* Namespace uris */
-static GHashTable *namespace_uris;
+       /* Namespace uris */
+       GHashTable *namespace_uris;
 
-/* List of TrackerOntology objects */
-static GPtrArray  *ontologies;
+       /* List of TrackerOntology objects */
+       GPtrArray  *ontologies;
 
-/* Ontology uris */
-static GHashTable *ontology_uris;
+       /* Ontology uris */
+       GHashTable *ontology_uris;
 
-/* List of TrackerClass objects */
-static GPtrArray  *classes;
+       /* List of TrackerClass objects */
+       GPtrArray  *classes;
 
-/* Hash (gchar *class_uri, TrackerClass *service) */
-static GHashTable *class_uris;
+       /* Hash (gchar *class_uri, TrackerClass *service) */
+       GHashTable *class_uris;
 
-/* List of TrackerProperty objects */
-static GPtrArray  *properties;
+       /* List of TrackerProperty objects */
+       GPtrArray  *properties;
 
-/* Field uris */
-static GHashTable *property_uris;
+       /* Field uris */
+       GHashTable *property_uris;
 
-/* FieldType enum class */
-static gpointer    property_type_enum_class;
+       /* FieldType enum class */
+       gpointer    property_type_enum_class;
 
-/* Hash (int id, const gchar *uri) */
-static GHashTable *id_uri_pairs;
+       /* Hash (int id, const gchar *uri) */
+       GHashTable *id_uri_pairs;
 
-/* rdf:type */
-static TrackerProperty *rdf_type = NULL;
+       /* rdf:type */
+       TrackerProperty *rdf_type;
 
-static GvdbTable *gvdb_table;
-static GvdbTable *gvdb_namespaces_table;
-static GvdbTable *gvdb_classes_table;
-static GvdbTable *gvdb_properties_table;
+       GvdbTable *gvdb_table;
+       GvdbTable *gvdb_namespaces_table;
+       GvdbTable *gvdb_classes_table;
+       GvdbTable *gvdb_properties_table;
+};
 
-void
-tracker_ontologies_init (void)
-{
-       if (initialized) {
-               return;
-       }
+G_DEFINE_TYPE_WITH_PRIVATE (TrackerOntologies, tracker_ontologies, G_TYPE_OBJECT)
 
-       namespaces = g_ptr_array_new ();
+static void
+tracker_ontologies_init (TrackerOntologies *ontologies)
+{
+       TrackerOntologiesPrivate *priv = tracker_ontologies_get_instance_private (ontologies);
 
-       ontologies = g_ptr_array_new ();
+       priv->namespaces = g_ptr_array_new_with_free_func (g_object_unref);
 
-       namespace_uris = g_hash_table_new_full (g_str_hash,
-                                               g_str_equal,
-                                               g_free,
-                                               g_object_unref);
+       priv->ontologies = g_ptr_array_new_with_free_func (g_object_unref);
 
-       ontology_uris = g_hash_table_new_full (g_str_hash,
-                                              g_str_equal,
-                                              g_free,
-                                              g_object_unref);
+       priv->namespace_uris = g_hash_table_new_full (g_str_hash,
+                                                     g_str_equal,
+                                                     g_free,
+                                                     g_object_unref);
 
-       classes = g_ptr_array_new ();
+       priv->ontology_uris = g_hash_table_new_full (g_str_hash,
+                                                    g_str_equal,
+                                                    g_free,
+                                                    g_object_unref);
 
-       class_uris = g_hash_table_new_full (g_str_hash,
-                                           g_str_equal,
-                                           g_free,
-                                           g_object_unref);
+       priv->classes = g_ptr_array_new_with_free_func (g_object_unref);
 
-       id_uri_pairs = g_hash_table_new_full (g_direct_hash, g_direct_equal,
-                                             NULL,
-                                             g_free);
+       priv->class_uris = g_hash_table_new_full (g_str_hash,
+                                                 g_str_equal,
+                                                 g_free,
+                                                 g_object_unref);
 
-       properties = g_ptr_array_new ();
+       priv->id_uri_pairs = g_hash_table_new_full (g_direct_hash, g_direct_equal,
+                                                   NULL,
+                                                   g_free);
 
-       property_uris = g_hash_table_new_full (g_str_hash,
-                                              g_str_equal,
-                                              g_free,
-                                              g_object_unref);
+       priv->properties = g_ptr_array_new_with_free_func (g_object_unref);
 
-       /* We will need the class later in order to match strings to enum values
-        * when inserting metadata types in the DB, so the enum class needs to be
-        * created beforehand.
-        */
-       property_type_enum_class = g_type_class_ref (TRACKER_TYPE_PROPERTY_TYPE);
-
-       initialized = TRUE;
+       priv->property_uris = g_hash_table_new_full (g_str_hash,
+                                                    g_str_equal,
+                                                    g_free,
+                                                    g_object_unref);
 }
 
-void
-tracker_ontologies_shutdown (void)
+static void
+tracker_ontologies_finalize (GObject *object)
 {
-       if (!initialized) {
-               return;
-       }
-
-       g_ptr_array_foreach (namespaces, (GFunc) g_object_unref, NULL);
-       g_ptr_array_free (namespaces, TRUE);
-
-       g_hash_table_unref (namespace_uris);
-       namespace_uris = NULL;
-
-       g_ptr_array_foreach (ontologies, (GFunc) g_object_unref, NULL);
-       g_ptr_array_free (ontologies, TRUE);
-
-       g_hash_table_unref (ontology_uris);
-       ontology_uris = NULL;
+       TrackerOntologies *ontologies = TRACKER_ONTOLOGIES (object);
+       TrackerOntologiesPrivate *priv = tracker_ontologies_get_instance_private (ontologies);
 
-       g_ptr_array_foreach (classes, (GFunc) g_object_unref, NULL);
-       g_ptr_array_free (classes, TRUE);
+       g_ptr_array_free (priv->namespaces, TRUE);
+       g_hash_table_unref (priv->namespace_uris);
 
-       g_hash_table_unref (class_uris);
-       class_uris = NULL;
+       g_ptr_array_free (priv->ontologies, TRUE);
+       g_hash_table_unref (priv->ontology_uris);
 
-       g_hash_table_unref (id_uri_pairs);
-       id_uri_pairs = NULL;
+       g_ptr_array_free (priv->classes, TRUE);
+       g_hash_table_unref (priv->class_uris);
 
-       g_ptr_array_foreach (properties, (GFunc) g_object_unref, NULL);
-       g_ptr_array_free (properties, TRUE);
+       g_hash_table_unref (priv->id_uri_pairs);
 
-       g_hash_table_unref (property_uris);
-       property_uris = NULL;
+       g_ptr_array_free (priv->properties, TRUE);
+       g_hash_table_unref (priv->property_uris);
 
-       g_type_class_unref (property_type_enum_class);
-       property_type_enum_class = NULL;
+       if (priv->rdf_type) {
+               g_object_unref (priv->rdf_type);
+       }
 
-       if (rdf_type) {
-               g_object_unref (rdf_type);
-               rdf_type = NULL;
+       if (priv->gvdb_table) {
+               gvdb_table_unref (priv->gvdb_properties_table);
+               gvdb_table_unref (priv->gvdb_classes_table);
+               gvdb_table_unref (priv->gvdb_namespaces_table);
+               gvdb_table_unref (priv->gvdb_table);
        }
 
-       if (gvdb_table) {
-               gvdb_table_unref (gvdb_properties_table);
-               gvdb_properties_table = NULL;
+       G_OBJECT_CLASS (tracker_ontologies_parent_class)->finalize (object);
+}
 
-               gvdb_table_unref (gvdb_classes_table);
-               gvdb_classes_table = NULL;
+static void
+tracker_ontologies_class_init (TrackerOntologiesClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
-               gvdb_table_unref (gvdb_namespaces_table);
-               gvdb_namespaces_table = NULL;
+       object_class->finalize = tracker_ontologies_finalize;
 
-               gvdb_table_unref (gvdb_table);
-               gvdb_table = NULL;
-       }
-
-       initialized = FALSE;
+       /* We will need the class later in order to match strings to enum values
+        * when inserting metadata types in the DB, so the enum class needs to be
+        * created beforehand.
+        */
+       g_type_ensure (TRACKER_TYPE_PROPERTY_TYPE);
 }
 
 TrackerProperty *
-tracker_ontologies_get_rdf_type (void)
+tracker_ontologies_get_rdf_type (TrackerOntologies *ontologies)
 {
-       g_return_val_if_fail (rdf_type != NULL, NULL);
+       TrackerOntologiesPrivate *priv = tracker_ontologies_get_instance_private (ontologies);
+
+       g_return_val_if_fail (priv->rdf_type != NULL, NULL);
 
-       return rdf_type;
+       return priv->rdf_type;
 }
 
 const gchar*
-tracker_ontologies_get_uri_by_id (gint id)
+tracker_ontologies_get_uri_by_id (TrackerOntologies *ontologies,
+                                  gint               id)
 {
+       TrackerOntologiesPrivate *priv = tracker_ontologies_get_instance_private (ontologies);
+
        g_return_val_if_fail (id != -1, NULL);
 
-       return g_hash_table_lookup (id_uri_pairs, GINT_TO_POINTER (id));
+       return g_hash_table_lookup (priv->id_uri_pairs, GINT_TO_POINTER (id));
 }
 
 void
-tracker_ontologies_add_class (TrackerClass *service)
+tracker_ontologies_add_class (TrackerOntologies *ontologies,
+                              TrackerClass      *service)
 {
-
+       TrackerOntologiesPrivate *priv = tracker_ontologies_get_instance_private (ontologies);
        const gchar *uri;
 
        g_return_if_fail (TRACKER_IS_CLASS (service));
 
        uri = tracker_class_get_uri (service);
 
-       g_ptr_array_add (classes, g_object_ref (service));
+       g_ptr_array_add (priv->classes, g_object_ref (service));
+       tracker_class_set_ontologies (service, ontologies);
 
        if (uri) {
-               g_hash_table_insert (class_uris,
+               g_hash_table_insert (priv->class_uris,
                                     g_strdup (uri),
                                     g_object_ref (service));
        }
 }
 
 TrackerClass *
-tracker_ontologies_get_class_by_uri (const gchar *class_uri)
+tracker_ontologies_get_class_by_uri (TrackerOntologies *ontologies,
+                                     const gchar       *class_uri)
 {
+       TrackerOntologiesPrivate *priv = tracker_ontologies_get_instance_private (ontologies);
        TrackerClass *class;
 
        g_return_val_if_fail (class_uri != NULL, NULL);
 
-       class = g_hash_table_lookup (class_uris, class_uri);
+       class = g_hash_table_lookup (priv->class_uris, class_uri);
 
-       if (!class && gvdb_table) {
-               if (tracker_ontologies_get_class_string_gvdb (class_uri, "name") != NULL) {
+       if (!class && priv->gvdb_table) {
+               if (tracker_ontologies_get_class_string_gvdb (ontologies, class_uri, "name") != NULL) {
                        class = tracker_class_new (TRUE);
+                       tracker_class_set_ontologies (class, ontologies);
                        tracker_class_set_uri (class, class_uri);
 
-                       g_hash_table_insert (class_uris,
+                       g_hash_table_insert (priv->class_uris,
                                             g_strdup (class_uri),
                                             class);
                }
@@ -238,93 +231,111 @@ tracker_ontologies_get_class_by_uri (const gchar *class_uri)
 }
 
 TrackerNamespace **
-tracker_ontologies_get_namespaces (guint *length)
+tracker_ontologies_get_namespaces (TrackerOntologies *ontologies,
+                                   guint             *length)
 {
-       if (namespaces->len == 0 && gvdb_table) {
+       TrackerOntologiesPrivate *priv = tracker_ontologies_get_instance_private (ontologies);
+
+       if (priv->namespaces->len == 0 && priv->gvdb_table) {
                gchar **namespace_uris;
                gint i;
 
-               namespace_uris = gvdb_table_list (gvdb_namespaces_table, "");
+               namespace_uris = gvdb_table_list (priv->gvdb_namespaces_table, "");
 
                for (i = 0; namespace_uris[i]; i++) {
                        TrackerNamespace *namespace;
 
-                       namespace = tracker_ontologies_get_namespace_by_uri (namespace_uris[i]);
+                       namespace = tracker_ontologies_get_namespace_by_uri (ontologies,
+                                                                            namespace_uris[i]);
 
-                       g_ptr_array_add (namespaces, g_object_ref (namespace));
+                       g_ptr_array_add (priv->namespaces, g_object_ref (namespace));
+                       tracker_namespace_set_ontologies (namespace, ontologies);
                }
 
                g_strfreev (namespace_uris);
        }
 
-       *length = namespaces->len;
-       return (TrackerNamespace **) namespaces->pdata;
+       *length = priv->namespaces->len;
+       return (TrackerNamespace **) priv->namespaces->pdata;
 }
 
 TrackerOntology **
-tracker_ontologies_get_ontologies (guint *length)
+tracker_ontologies_get_ontologies (TrackerOntologies *ontologies,
+                                   guint             *length)
 {
-       if (G_UNLIKELY (!ontologies)) {
+       TrackerOntologiesPrivate *priv = tracker_ontologies_get_instance_private (ontologies);
+
+       if (G_UNLIKELY (!priv->ontologies)) {
                *length = 0;
                return NULL;
        }
 
-       *length = ontologies->len;
-       return (TrackerOntology **) ontologies->pdata;
+       *length = priv->ontologies->len;
+       return (TrackerOntology **) priv->ontologies->pdata;
 }
 
 TrackerClass **
-tracker_ontologies_get_classes (guint *length)
+tracker_ontologies_get_classes (TrackerOntologies *ontologies,
+                                guint             *length)
 {
-       if (classes->len == 0 && gvdb_table) {
+       TrackerOntologiesPrivate *priv = tracker_ontologies_get_instance_private (ontologies);
+
+       if (priv->classes->len == 0 && priv->gvdb_table) {
                gchar **class_uris;
                gint i;
 
-               class_uris = gvdb_table_list (gvdb_classes_table, "");
+               class_uris = gvdb_table_list (priv->gvdb_classes_table, "");
 
                for (i = 0; class_uris[i]; i++) {
                        TrackerClass *class;
 
-                       class = tracker_ontologies_get_class_by_uri (class_uris[i]);
+                       class = tracker_ontologies_get_class_by_uri (ontologies,class_uris[i]);
 
-                       g_ptr_array_add (classes, g_object_ref (class));
+                       g_ptr_array_add (priv->classes, g_object_ref (class));
+                       tracker_class_set_ontologies (class, ontologies);
                }
 
                g_strfreev (class_uris);
        }
 
-       *length = classes->len;
-       return (TrackerClass **) classes->pdata;
+       *length = priv->classes->len;
+       return (TrackerClass **) priv->classes->pdata;
 }
 
 TrackerProperty **
-tracker_ontologies_get_properties (guint *length)
+tracker_ontologies_get_properties (TrackerOntologies *ontologies,
+                                   guint             *length)
 {
-       if (properties->len == 0 && gvdb_table) {
+       TrackerOntologiesPrivate *priv = tracker_ontologies_get_instance_private (ontologies);
+
+       if (priv->properties->len == 0 && priv->gvdb_table) {
                gchar **property_uris;
                gint i;
 
-               property_uris = gvdb_table_list (gvdb_properties_table, "");
+               property_uris = gvdb_table_list (priv->gvdb_properties_table, "");
 
                for (i = 0; property_uris[i]; i++) {
                        TrackerProperty *property;
 
-                       property = tracker_ontologies_get_property_by_uri (property_uris[i]);
+                       property = tracker_ontologies_get_property_by_uri (ontologies, property_uris[i]);
 
-                       g_ptr_array_add (properties, g_object_ref (property));
+                       g_ptr_array_add (priv->properties, g_object_ref (property));
+                       tracker_property_set_ontologies (property, ontologies);
                }
 
                g_strfreev (property_uris);
        }
 
-       *length = properties->len;
-       return (TrackerProperty **) properties->pdata;
+       *length = priv->properties->len;
+       return (TrackerProperty **) priv->properties->pdata;
 }
 
 /* Field mechanics */
 void
-tracker_ontologies_add_property (TrackerProperty *field)
+tracker_ontologies_add_property (TrackerOntologies *ontologies,
+                                 TrackerProperty   *field)
 {
+       TrackerOntologiesPrivate *priv = tracker_ontologies_get_instance_private (ontologies);
        const gchar *uri;
 
        g_return_if_fail (TRACKER_IS_PROPERTY (field));
@@ -332,42 +343,47 @@ tracker_ontologies_add_property (TrackerProperty *field)
        uri = tracker_property_get_uri (field);
 
        if (g_strcmp0 (uri, TRACKER_PREFIX_RDF "type") == 0) {
-               if (rdf_type) {
-                       g_object_unref (rdf_type);
-               }
-               rdf_type = g_object_ref (field);
+               g_set_object (&priv->rdf_type, field);
        }
 
-       g_ptr_array_add (properties, g_object_ref (field));
+       g_ptr_array_add (priv->properties, g_object_ref (field));
+       tracker_property_set_ontologies (field, ontologies);
 
-       g_hash_table_insert (property_uris,
+       g_hash_table_insert (priv->property_uris,
                             g_strdup (uri),
                             g_object_ref (field));
 }
 
 void
-tracker_ontologies_add_id_uri_pair (gint id, const gchar *uri)
+tracker_ontologies_add_id_uri_pair (TrackerOntologies *ontologies,
+                                    gint               id,
+                                    const gchar       *uri)
 {
-       g_hash_table_insert (id_uri_pairs,
+       TrackerOntologiesPrivate *priv = tracker_ontologies_get_instance_private (ontologies);
+
+       g_hash_table_insert (priv->id_uri_pairs,
                             GINT_TO_POINTER (id),
                             g_strdup (uri));
 }
 
 TrackerProperty *
-tracker_ontologies_get_property_by_uri (const gchar *uri)
+tracker_ontologies_get_property_by_uri (TrackerOntologies *ontologies,
+                                        const gchar       *uri)
 {
+       TrackerOntologiesPrivate *priv = tracker_ontologies_get_instance_private (ontologies);
        TrackerProperty *property;
 
        g_return_val_if_fail (uri != NULL, NULL);
 
-       property = g_hash_table_lookup (property_uris, uri);
+       property = g_hash_table_lookup (priv->property_uris, uri);
 
-       if (!property && gvdb_table) {
-               if (tracker_ontologies_get_property_string_gvdb (uri, "name") != NULL) {
+       if (!property && priv->gvdb_table) {
+               if (tracker_ontologies_get_property_string_gvdb (ontologies, uri, "name") != NULL) {
                        property = tracker_property_new (TRUE);
+                       tracker_property_set_ontologies (property, ontologies);
                        tracker_property_set_uri (property, uri);
 
-                       g_hash_table_insert (property_uris,
+                       g_hash_table_insert (priv->property_uris,
                                             g_strdup (uri),
                                             property);
                }
@@ -377,52 +393,61 @@ tracker_ontologies_get_property_by_uri (const gchar *uri)
 }
 
 void
-tracker_ontologies_add_namespace (TrackerNamespace *namespace)
+tracker_ontologies_add_namespace (TrackerOntologies *ontologies,
+                                  TrackerNamespace  *namespace)
 {
+       TrackerOntologiesPrivate *priv = tracker_ontologies_get_instance_private (ontologies);
        const gchar *uri;
 
        g_return_if_fail (TRACKER_IS_NAMESPACE (namespace));
 
        uri = tracker_namespace_get_uri (namespace);
 
-       g_ptr_array_add (namespaces, g_object_ref (namespace));
+       g_ptr_array_add (priv->namespaces, g_object_ref (namespace));
+       tracker_namespace_set_ontologies (namespace, ontologies);
 
-       g_hash_table_insert (namespace_uris,
+       g_hash_table_insert (priv->namespace_uris,
                             g_strdup (uri),
                             g_object_ref (namespace));
 }
 
 void
-tracker_ontologies_add_ontology (TrackerOntology *ontology)
+tracker_ontologies_add_ontology (TrackerOntologies *ontologies,
+                                 TrackerOntology   *ontology)
 {
+       TrackerOntologiesPrivate *priv = tracker_ontologies_get_instance_private (ontologies);
        const gchar *uri;
 
        g_return_if_fail (TRACKER_IS_ONTOLOGY (ontology));
 
        uri = tracker_ontology_get_uri (ontology);
 
-       g_ptr_array_add (ontologies, g_object_ref (ontology));
+       g_ptr_array_add (priv->ontologies, g_object_ref (ontology));
+       tracker_ontology_set_ontologies (ontology, ontologies);
 
-       g_hash_table_insert (ontology_uris,
+       g_hash_table_insert (priv->ontology_uris,
                             g_strdup (uri),
                             g_object_ref (ontology));
 }
 
 TrackerNamespace *
-tracker_ontologies_get_namespace_by_uri (const gchar *uri)
+tracker_ontologies_get_namespace_by_uri (TrackerOntologies *ontologies,
+                                         const gchar       *uri)
 {
+       TrackerOntologiesPrivate *priv = tracker_ontologies_get_instance_private (ontologies);
        TrackerNamespace *namespace;
 
        g_return_val_if_fail (uri != NULL, NULL);
 
-       namespace = g_hash_table_lookup (namespace_uris, uri);
+       namespace = g_hash_table_lookup (priv->namespace_uris, uri);
 
-       if (!namespace && gvdb_table) {
-               if (tracker_ontologies_get_namespace_string_gvdb (uri, "prefix") != NULL) {
+       if (!namespace && priv->gvdb_table) {
+               if (tracker_ontologies_get_namespace_string_gvdb (ontologies, uri, "prefix") != NULL) {
                        namespace = tracker_namespace_new (TRUE);
+                       tracker_namespace_set_ontologies (namespace, ontologies);
                        tracker_namespace_set_uri (namespace, uri);
 
-                       g_hash_table_insert (namespace_uris,
+                       g_hash_table_insert (priv->namespace_uris,
                                             g_strdup (uri),
                                             namespace);
                }
@@ -433,11 +458,14 @@ tracker_ontologies_get_namespace_by_uri (const gchar *uri)
 
 
 TrackerOntology *
-tracker_ontologies_get_ontology_by_uri (const gchar *uri)
+tracker_ontologies_get_ontology_by_uri (TrackerOntologies *ontologies,
+                                        const gchar       *uri)
 {
+       TrackerOntologiesPrivate *priv = tracker_ontologies_get_instance_private (ontologies);
+
        g_return_val_if_fail (uri != NULL, NULL);
 
-       return g_hash_table_lookup (ontology_uris, uri);
+       return g_hash_table_lookup (priv->ontology_uris, uri);
 }
 
 static void
@@ -481,9 +509,11 @@ gvdb_hash_table_insert_statement (GHashTable  *table,
 }
 
 gboolean
-tracker_ontologies_write_gvdb (const gchar  *filename,
-                               GError      **error)
+tracker_ontologies_write_gvdb (TrackerOntologies  *ontologies,
+                               const gchar        *filename,
+                               GError            **error)
 {
+       TrackerOntologiesPrivate *priv = tracker_ontologies_get_instance_private (ontologies);
        GHashTable *root_table, *table;
        GvdbItem *root, *item;
        const gchar *uri;
@@ -494,10 +524,10 @@ tracker_ontologies_write_gvdb (const gchar  *filename,
 
        table = gvdb_hash_table_new (root_table, "namespaces");
        root = gvdb_hash_table_insert (table, "");
-       for (i = 0; i < namespaces->len; i++) {
+       for (i = 0; i < priv->namespaces->len; i++) {
                TrackerNamespace *namespace;
 
-               namespace = namespaces->pdata[i];
+               namespace = priv->namespaces->pdata[i];
                uri = tracker_namespace_get_uri (namespace);
 
                item = gvdb_hash_table_insert_item (table, root, uri);
@@ -508,12 +538,12 @@ tracker_ontologies_write_gvdb (const gchar  *filename,
 
        table = gvdb_hash_table_new (root_table, "classes");
        root = gvdb_hash_table_insert (table, "");
-       for (i = 0; i < classes->len; i++) {
+       for (i = 0; i < priv->classes->len; i++) {
                TrackerClass *class;
                TrackerClass **super_classes;
                GVariantBuilder builder;
 
-               class = classes->pdata[i];
+               class = priv->classes->pdata[i];
                uri = tracker_class_get_uri (class);
 
                item = gvdb_hash_table_insert_item (table, root, uri);
@@ -536,12 +566,12 @@ tracker_ontologies_write_gvdb (const gchar  *filename,
 
        table = gvdb_hash_table_new (root_table, "properties");
        root = gvdb_hash_table_insert (table, "");
-       for (i = 0; i < properties->len; i++) {
+       for (i = 0; i < priv->properties->len; i++) {
                TrackerProperty *property;
                TrackerClass **domain_indexes;
                GVariantBuilder builder;
 
-               property = properties->pdata[i];
+               property = priv->properties->pdata[i];
                uri = tracker_property_get_uri (property);
 
                item = gvdb_hash_table_insert_item (table, root, uri);
@@ -583,47 +613,53 @@ tracker_ontologies_write_gvdb (const gchar  *filename,
        return retval;
 }
 
-gboolean
+TrackerOntologies *
 tracker_ontologies_load_gvdb (const gchar  *filename,
                               GError      **error)
 {
-       tracker_ontologies_shutdown ();
+       TrackerOntologies *ontologies;
+       TrackerOntologiesPrivate *priv;
 
-       tracker_ontologies_init ();
+       ontologies = tracker_ontologies_new ();
+       priv = tracker_ontologies_get_instance_private (ontologies);
 
-       gvdb_table = gvdb_table_new (filename, TRUE, error);
-       if (!gvdb_table) {
-               return FALSE;
+       priv->gvdb_table = gvdb_table_new (filename, TRUE, error);
+       if (!priv->gvdb_table) {
+               g_object_unref (ontologies);
+               return NULL;
        }
 
-       gvdb_namespaces_table = gvdb_table_get_table (gvdb_table, "namespaces");
-       gvdb_classes_table = gvdb_table_get_table (gvdb_table, "classes");
-       gvdb_properties_table = gvdb_table_get_table (gvdb_table, "properties");
-       return TRUE;
+       priv->gvdb_namespaces_table = gvdb_table_get_table (priv->gvdb_table, "namespaces");
+       priv->gvdb_classes_table = gvdb_table_get_table (priv->gvdb_table, "classes");
+       priv->gvdb_properties_table = gvdb_table_get_table (priv->gvdb_table, "properties");
+       return ontologies;
 }
 
 GVariant *
-tracker_ontologies_get_namespace_value_gvdb (const gchar *uri,
-                                             const gchar *predicate)
+tracker_ontologies_get_namespace_value_gvdb (TrackerOntologies *ontologies,
+                                             const gchar       *uri,
+                                             const gchar       *predicate)
 {
+       TrackerOntologiesPrivate *priv = tracker_ontologies_get_instance_private (ontologies);
        gchar *key;
        GVariant *value;
 
        key = g_strdup_printf ("%s#%s", uri, predicate);
-       value = gvdb_table_get_value (gvdb_namespaces_table, key);
+       value = gvdb_table_get_value (priv->gvdb_namespaces_table, key);
        g_free (key);
 
        return value;
 }
 
 const gchar *
-tracker_ontologies_get_namespace_string_gvdb (const gchar *uri,
-                                              const gchar *predicate)
+tracker_ontologies_get_namespace_string_gvdb (TrackerOntologies *ontologies,
+                                              const gchar       *uri,
+                                              const gchar       *predicate)
 {
        GVariant *value;
        const gchar *result;
 
-       value = tracker_ontologies_get_namespace_value_gvdb (uri, predicate);
+       value = tracker_ontologies_get_namespace_value_gvdb (ontologies, uri, predicate);
 
        if (value == NULL) {
                return NULL;
@@ -636,27 +672,30 @@ tracker_ontologies_get_namespace_string_gvdb (const gchar *uri,
 }
 
 GVariant *
-tracker_ontologies_get_class_value_gvdb (const gchar *uri,
-                                         const gchar *predicate)
+tracker_ontologies_get_class_value_gvdb (TrackerOntologies *ontologies,
+                                         const gchar       *uri,
+                                         const gchar       *predicate)
 {
+       TrackerOntologiesPrivate *priv = tracker_ontologies_get_instance_private (ontologies);
        gchar *key;
        GVariant *value;
 
        key = g_strdup_printf ("%s#%s", uri, predicate);
-       value = gvdb_table_get_value (gvdb_classes_table, key);
+       value = gvdb_table_get_value (priv->gvdb_classes_table, key);
        g_free (key);
 
        return value;
 }
 
 const gchar *
-tracker_ontologies_get_class_string_gvdb (const gchar *uri,
-                                          const gchar *predicate)
+tracker_ontologies_get_class_string_gvdb (TrackerOntologies *ontologies,
+                                          const gchar       *uri,
+                                          const gchar       *predicate)
 {
        GVariant *value;
        const gchar *result;
 
-       value = tracker_ontologies_get_class_value_gvdb (uri, predicate);
+       value = tracker_ontologies_get_class_value_gvdb (ontologies, uri, predicate);
 
        if (value == NULL) {
                return NULL;
@@ -669,27 +708,30 @@ tracker_ontologies_get_class_string_gvdb (const gchar *uri,
 }
 
 GVariant *
-tracker_ontologies_get_property_value_gvdb (const gchar *uri,
-                                            const gchar *predicate)
+tracker_ontologies_get_property_value_gvdb (TrackerOntologies *ontologies,
+                                            const gchar       *uri,
+                                            const gchar       *predicate)
 {
+       TrackerOntologiesPrivate *priv = tracker_ontologies_get_instance_private (ontologies);
        gchar *key;
        GVariant *value;
 
        key = g_strdup_printf ("%s#%s", uri, predicate);
-       value = gvdb_table_get_value (gvdb_properties_table, key);
+       value = gvdb_table_get_value (priv->gvdb_properties_table, key);
        g_free (key);
 
        return value;
 }
 
 const gchar *
-tracker_ontologies_get_property_string_gvdb (const gchar *uri,
-                                             const gchar *predicate)
+tracker_ontologies_get_property_string_gvdb (TrackerOntologies *ontologies,
+                                             const gchar       *uri,
+                                             const gchar       *predicate)
 {
        GVariant *value;
        const gchar *result;
 
-       value = tracker_ontologies_get_property_value_gvdb (uri, predicate);
+       value = tracker_ontologies_get_property_value_gvdb (ontologies, uri, predicate);
 
        if (value == NULL) {
                return NULL;
@@ -710,8 +752,16 @@ class_sort_func (gconstpointer a,
 }
 
 void
-tracker_ontologies_sort (void)
+tracker_ontologies_sort (TrackerOntologies *ontologies)
 {
+       TrackerOntologiesPrivate *priv = tracker_ontologies_get_instance_private (ontologies);
+
        /* Sort result so it is alphabetical */
-       g_ptr_array_sort (classes, class_sort_func);
+       g_ptr_array_sort (priv->classes, class_sort_func);
+}
+
+TrackerOntologies *
+tracker_ontologies_new (void)
+{
+       return g_object_new (TRACKER_TYPE_ONTOLOGIES, NULL);
 }
diff --git a/src/libtracker-data/tracker-ontologies.h b/src/libtracker-data/tracker-ontologies.h
index 1feefbe..c820696 100644
--- a/src/libtracker-data/tracker-ontologies.h
+++ b/src/libtracker-data/tracker-ontologies.h
@@ -36,46 +36,83 @@ G_BEGIN_DECLS
 
 #define TRACKER_ONTOLOGIES_MAX_ID 100000
 
-void               tracker_ontologies_init                 (void);
-void               tracker_ontologies_shutdown             (void);
-void               tracker_ontologies_sort                 (void);
+#define TRACKER_TYPE_ONTOLOGIES         (tracker_ontologies_get_type ())
+#define TRACKER_ONTOLOGIES(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_ONTOLOGIES, 
TrackerOntologies))
+#define TRACKER_ONTOLOGIES_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST ((k), TRACKER_TYPE_ONTOLOGIES, 
TrackerOntologiesClass))
+#define TRACKER_IS_ONTOLOGIES(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_ONTOLOGIES))
+#define TRACKER_IS_ONTOLOGIES_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), TRACKER_TYPE_ONTOLOGIES))
+#define TRACKER_ONTOLOGIES_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_ONTOLOGIES, 
TrackerOntologiesClass))
+
+typedef struct _TrackerOntologiesClass TrackerOntologiesClass;
+
+struct _TrackerOntologies {
+       GObject parent;
+};
+
+struct _TrackerOntologiesClass {
+       GObjectClass parent_class;
+};
+
+TrackerOntologies *tracker_ontologies_new                  (void);
+void               tracker_ontologies_sort                 (TrackerOntologies *ontologies);
 
 /* Service mechanics */
-void               tracker_ontologies_add_class            (TrackerClass     *service);
-TrackerClass *     tracker_ontologies_get_class_by_uri     (const gchar      *service_uri);
-TrackerNamespace **tracker_ontologies_get_namespaces       (guint *length);
-TrackerOntology  **tracker_ontologies_get_ontologies       (guint *length);
-TrackerClass  **   tracker_ontologies_get_classes          (guint *length);
-TrackerProperty ** tracker_ontologies_get_properties       (guint *length);
-TrackerProperty *  tracker_ontologies_get_rdf_type         (void);
+void               tracker_ontologies_add_class            (TrackerOntologies *ontologies,
+                                                            TrackerClass      *service);
+TrackerClass *     tracker_ontologies_get_class_by_uri     (TrackerOntologies *ontologies,
+                                                            const gchar       *service_uri);
+TrackerNamespace **tracker_ontologies_get_namespaces       (TrackerOntologies *ontologies,
+                                                            guint             *length);
+TrackerOntology  **tracker_ontologies_get_ontologies       (TrackerOntologies *ontologies,
+                                                            guint             *length);
+TrackerClass  **   tracker_ontologies_get_classes          (TrackerOntologies *ontologies,
+                                                            guint             *length);
+TrackerProperty ** tracker_ontologies_get_properties       (TrackerOntologies *ontologies,
+                                                            guint             *length);
+TrackerProperty *  tracker_ontologies_get_rdf_type         (TrackerOntologies *ontologies);
 
 /* Field mechanics */
-void               tracker_ontologies_add_property         (TrackerProperty  *field);
-TrackerProperty *  tracker_ontologies_get_property_by_uri  (const gchar      *uri);
-void               tracker_ontologies_add_namespace        (TrackerNamespace *namespace_);
-void               tracker_ontologies_add_ontology         (TrackerOntology  *ontology);
-TrackerNamespace * tracker_ontologies_get_namespace_by_uri (const gchar      *namespace_uri);
-TrackerOntology  * tracker_ontologies_get_ontology_by_uri  (const gchar      *namespace_uri);
-const gchar*       tracker_ontologies_get_uri_by_id        (gint              id);
-void               tracker_ontologies_add_id_uri_pair      (gint              id,
-                                                            const gchar      *uri);
-
-gboolean           tracker_ontologies_write_gvdb           (const gchar      *filename,
-                                                            GError          **error);
-gboolean           tracker_ontologies_load_gvdb            (const gchar      *filename,
-                                                            GError          **error);
-GVariant *         tracker_ontologies_get_namespace_value_gvdb  (const gchar      *uri,
-                                                                 const gchar      *predicate);
-const gchar *      tracker_ontologies_get_namespace_string_gvdb (const gchar      *uri,
-                                                                 const gchar      *predicate);
-GVariant *         tracker_ontologies_get_class_value_gvdb      (const gchar      *uri,
-                                                                 const gchar      *predicate);
-const gchar *      tracker_ontologies_get_class_string_gvdb     (const gchar      *uri,
-                                                                 const gchar      *predicate);
-GVariant *         tracker_ontologies_get_property_value_gvdb   (const gchar      *uri,
-                                                                 const gchar      *predicate);
-const gchar *      tracker_ontologies_get_property_string_gvdb  (const gchar      *uri,
-                                                                 const gchar      *predicate);
+void               tracker_ontologies_add_property         (TrackerOntologies *ontologies,
+                                                            TrackerProperty   *field);
+TrackerProperty *  tracker_ontologies_get_property_by_uri  (TrackerOntologies *ontologies,
+                                                            const gchar       *uri);
+void               tracker_ontologies_add_namespace        (TrackerOntologies *ontologies,
+                                                            TrackerNamespace  *namespace_);
+void               tracker_ontologies_add_ontology         (TrackerOntologies *ontologies,
+                                                            TrackerOntology   *ontology);
+TrackerNamespace * tracker_ontologies_get_namespace_by_uri (TrackerOntologies *ontologies,
+                                                            const gchar       *namespace_uri);
+TrackerOntology  * tracker_ontologies_get_ontology_by_uri  (TrackerOntologies *ontologies,
+                                                            const gchar       *namespace_uri);
+const gchar*       tracker_ontologies_get_uri_by_id        (TrackerOntologies *ontologies,
+                                                            gint               id);
+void               tracker_ontologies_add_id_uri_pair      (TrackerOntologies *ontologies,
+                                                            gint               id,
+                                                            const gchar       *uri);
+
+gboolean           tracker_ontologies_write_gvdb           (TrackerOntologies  *ontologies,
+                                                            const gchar        *filename,
+                                                            GError            **error);
+TrackerOntologies *tracker_ontologies_load_gvdb            (const gchar        *filename,
+                                                            GError            **error);
+GVariant *         tracker_ontologies_get_namespace_value_gvdb  (TrackerOntologies *ontologies,
+                                                                 const gchar       *uri,
+                                                                 const gchar       *predicate);
+const gchar *      tracker_ontologies_get_namespace_string_gvdb (TrackerOntologies *ontologies,
+                                                                 const gchar       *uri,
+                                                                 const gchar       *predicate);
+GVariant *         tracker_ontologies_get_class_value_gvdb      (TrackerOntologies *ontologies,
+                                                                 const gchar       *uri,
+                                                                 const gchar       *predicate);
+const gchar *      tracker_ontologies_get_class_string_gvdb     (TrackerOntologies *ontologies,
+                                                                 const gchar       *uri,
+                                                                 const gchar       *predicate);
+GVariant *         tracker_ontologies_get_property_value_gvdb   (TrackerOntologies *ontologies,
+                                                                 const gchar       *uri,
+                                                                 const gchar       *predicate);
+const gchar *      tracker_ontologies_get_property_string_gvdb  (TrackerOntologies *ontologies,
+                                                                 const gchar       *uri,
+                                                                 const gchar       *predicate);
 
 G_END_DECLS
 
diff --git a/src/libtracker-data/tracker-ontology.c b/src/libtracker-data/tracker-ontology.c
index b3c1dd5..ed2ef2d 100644
--- a/src/libtracker-data/tracker-ontology.c
+++ b/src/libtracker-data/tracker-ontology.c
@@ -36,6 +36,7 @@ struct _TrackerOntologyPrivate {
        gchar *uri;
        time_t last_modified;
        gboolean is_new;
+       TrackerOntologies *ontologies;
 };
 
 static void ontology_finalize     (GObject      *object);
@@ -162,3 +163,16 @@ tracker_ontology_set_is_new (TrackerOntology *ontology,
 
        priv->is_new = value;
 }
+
+void
+tracker_ontology_set_ontologies (TrackerOntology   *ontology,
+                                 TrackerOntologies *ontologies)
+{
+       TrackerOntologyPrivate *priv;
+
+       g_return_if_fail (TRACKER_IS_ONTOLOGY (ontology));
+       g_return_if_fail (ontologies != NULL);
+       priv = GET_PRIV (ontology);
+
+       priv->ontologies = ontologies;
+}
diff --git a/src/libtracker-data/tracker-ontology.h b/src/libtracker-data/tracker-ontology.h
index cc36ab3..b1978b9 100644
--- a/src/libtracker-data/tracker-ontology.h
+++ b/src/libtracker-data/tracker-ontology.h
@@ -23,6 +23,7 @@
 #define __LIBTRACKER_DATA_ONTOLOGY_H__
 
 #include <glib-object.h>
+#include "tracker-class.h"
 
 G_BEGIN_DECLS
 
@@ -60,6 +61,8 @@ void              tracker_ontology_set_uri           (TrackerOntology *ontology,
                                                       const gchar      *value);
 void              tracker_ontology_set_is_new        (TrackerOntology *ontology,
                                                       gboolean         value);
+void              tracker_ontology_set_ontologies    (TrackerOntology   *ontology,
+                                                      TrackerOntologies *ontologies);
 
 G_END_DECLS
 
diff --git a/src/libtracker-data/tracker-property.c b/src/libtracker-data/tracker-property.c
index 3f14c38..bd6c3dd 100644
--- a/src/libtracker-data/tracker-property.c
+++ b/src/libtracker-data/tracker-property.c
@@ -73,6 +73,8 @@ struct _TrackerPropertyPrivate {
        GArray        *last_super_properties;
        gboolean       cardinality_changed;
        gboolean       orig_multiple_values;
+
+       TrackerOntologies *ontologies;
 };
 
 static void property_finalize     (GObject      *object);
@@ -283,7 +285,7 @@ tracker_property_get_data_type (TrackerProperty *property)
        if (priv->use_gvdb) {
                const gchar *range_uri;
 
-               range_uri = tracker_ontologies_get_property_string_gvdb (priv->uri, "range");
+               range_uri = tracker_ontologies_get_property_string_gvdb (priv->ontologies, priv->uri, 
"range");
                if (strcmp (range_uri, XSD_STRING) == 0) {
                        priv->data_type = TRACKER_PROPERTY_TYPE_STRING;
                } else if (strcmp (range_uri, XSD_BOOLEAN) == 0) {
@@ -319,8 +321,8 @@ tracker_property_get_domain (TrackerProperty *property)
        if (!priv->domain && priv->use_gvdb) {
                const gchar *domain_uri;
 
-               domain_uri = tracker_ontologies_get_property_string_gvdb (priv->uri, "domain");
-               priv->domain = g_object_ref (tracker_ontologies_get_class_by_uri (domain_uri));
+               domain_uri = tracker_ontologies_get_property_string_gvdb (priv->ontologies, priv->uri, 
"domain");
+               priv->domain = g_object_ref (tracker_ontologies_get_class_by_uri (priv->ontologies, 
domain_uri));
        }
 
        return priv->domain;
@@ -344,14 +346,14 @@ tracker_property_get_domain_indexes (TrackerProperty *property)
 
                tracker_property_reset_domain_indexes (property);
 
-               variant = tracker_ontologies_get_property_value_gvdb (priv->uri, "domain-indexes");
+               variant = tracker_ontologies_get_property_value_gvdb (priv->ontologies, priv->uri, 
"domain-indexes");
                if (variant) {
                        GVariantIter iter;
                        const gchar *uri;
 
                        g_variant_iter_init (&iter, variant);
                        while (g_variant_iter_loop (&iter, "&s", &uri)) {
-                               domain_index = tracker_ontologies_get_class_by_uri (uri);
+                               domain_index = tracker_ontologies_get_class_by_uri (priv->ontologies, uri);
 
                                tracker_property_add_domain_index (property, domain_index);
                        }
@@ -406,8 +408,8 @@ tracker_property_get_range (TrackerProperty *property)
        if (!priv->range && priv->use_gvdb) {
                const gchar *range_uri;
 
-               range_uri = tracker_ontologies_get_property_string_gvdb (priv->uri, "range");
-               priv->range = g_object_ref (tracker_ontologies_get_class_by_uri (range_uri));
+               range_uri = tracker_ontologies_get_property_string_gvdb (priv->ontologies, priv->uri, 
"range");
+               priv->range = g_object_ref (tracker_ontologies_get_class_by_uri (priv->ontologies, 
range_uri));
        }
 
        return priv->range;
@@ -477,7 +479,7 @@ tracker_property_get_fulltext_indexed (TrackerProperty *property)
                GVariant *value;
                gboolean result;
 
-               value = tracker_ontologies_get_property_value_gvdb (priv->uri, "fulltext-indexed");
+               value = tracker_ontologies_get_property_value_gvdb (priv->ontologies, priv->uri, 
"fulltext-indexed");
                if (value != NULL) {
                        result = g_variant_get_boolean (value);
                        g_variant_unref (value);
@@ -589,7 +591,7 @@ tracker_property_get_multiple_values (TrackerProperty *property)
                GVariant *value;
                gboolean result;
 
-               value = tracker_ontologies_get_property_value_gvdb (priv->uri, "max-cardinality");
+               value = tracker_ontologies_get_property_value_gvdb (priv->ontologies, priv->uri, 
"max-cardinality");
                if (value != NULL) {
                        result = FALSE;
                        g_variant_unref (value);
@@ -640,7 +642,7 @@ tracker_property_get_is_inverse_functional_property (TrackerProperty *property)
                GVariant *value;
                gboolean result;
 
-               value = tracker_ontologies_get_property_value_gvdb (priv->uri, "inverse-functional");
+               value = tracker_ontologies_get_property_value_gvdb (priv->ontologies, priv->uri, 
"inverse-functional");
                if (value != NULL) {
                        result = g_variant_get_boolean (value);
                        g_variant_unref (value);
@@ -720,7 +722,7 @@ tracker_property_set_uri (TrackerProperty *property,
                        g_critical ("Unknown namespace of property %s", priv->uri);
                } else {
                        namespace_uri = g_strndup (priv->uri, hash - priv->uri + 1);
-                       namespace = tracker_ontologies_get_namespace_by_uri (namespace_uri);
+                       namespace = tracker_ontologies_get_namespace_by_uri (priv->ontologies, namespace_uri);
                        if (namespace == NULL) {
                                g_critical ("Unknown namespace %s of property %s", namespace_uri, priv->uri);
                        } else {
@@ -1152,3 +1154,16 @@ tracker_property_set_default_value (TrackerProperty *property,
        g_free (priv->default_value);
        priv->default_value = g_strdup (value);
 }
+
+void
+tracker_property_set_ontologies (TrackerProperty   *property,
+                                 TrackerOntologies *ontologies)
+{
+       TrackerPropertyPrivate *priv;
+
+       g_return_if_fail (TRACKER_IS_PROPERTY (property));
+       g_return_if_fail (ontologies != NULL);
+       priv = GET_PRIV (property);
+
+       priv->ontologies = ontologies;
+}
diff --git a/src/libtracker-data/tracker-property.h b/src/libtracker-data/tracker-property.h
index fdc6883..eb75adb 100644
--- a/src/libtracker-data/tracker-property.h
+++ b/src/libtracker-data/tracker-property.h
@@ -159,6 +159,9 @@ TrackerProperty   **tracker_property_get_last_super_properties
                                                              (TrackerProperty      *property);
 void                tracker_property_reset_super_properties  (TrackerProperty      *property);
 
+void                tracker_property_set_ontologies          (TrackerProperty      *property,
+                                                              TrackerOntologies    *ontologies);
+
 G_END_DECLS
 
 #endif /* __LIBTRACKER_DATA_PROPERTY_H__ */
diff --git a/src/libtracker-data/tracker-sparql-expression.vala 
b/src/libtracker-data/tracker-sparql-expression.vala
index d1b456d..bc74cdc 100644
--- a/src/libtracker-data/tracker-sparql-expression.vala
+++ b/src/libtracker-data/tracker-sparql-expression.vala
@@ -853,7 +853,8 @@ class Tracker.Sparql.Expression : Object {
                        return PropertyType.STRING;
                } else {
                        // support properties as functions
-                       var prop = Ontologies.get_property_by_uri (uri);
+                        var ontologies = Data.Manager.get_ontologies ();
+                       var prop = ontologies.get_property_by_uri (uri);
                        if (prop == null) {
                                throw get_error ("Unknown function");
                        }
diff --git a/src/libtracker-data/tracker-sparql-pattern.vala b/src/libtracker-data/tracker-sparql-pattern.vala
index 6a67679..9d2ae79 100644
--- a/src/libtracker-data/tracker-sparql-pattern.vala
+++ b/src/libtracker-data/tracker-sparql-pattern.vala
@@ -29,6 +29,7 @@ namespace Tracker.Sparql {
                public string get_sql_query (Query query) throws Sparql.Error {
                        try {
                                var sql = new StringBuilder ();
+                               var ontologies = Data.Manager.get_ontologies ();
 
                                if (subject != null) {
                                        // single subject
@@ -47,9 +48,9 @@ namespace Tracker.Sparql {
                                        bool first = true;
                                        if (cursor != null) {
                                                while (cursor.next ()) {
-                                                       var domain = Ontologies.get_class_by_uri 
(cursor.get_string (0));
+                                                       var domain = ontologies.get_class_by_uri 
(cursor.get_string (0));
 
-                                                       foreach (Property prop in Ontologies.get_properties 
()) {
+                                                       foreach (Property prop in ontologies.get_properties 
()) {
                                                                if (prop.domain == domain) {
                                                                        if (first) {
                                                                                first = false;
@@ -95,9 +96,9 @@ namespace Tracker.Sparql {
                                        bool first = true;
                                        if (cursor != null) {
                                                while (cursor.next ()) {
-                                                       var range = Ontologies.get_class_by_uri 
(cursor.get_string (0));
+                                                       var range = ontologies.get_class_by_uri 
(cursor.get_string (0));
 
-                                                       foreach (Property prop in Ontologies.get_properties 
()) {
+                                                       foreach (Property prop in ontologies.get_properties 
()) {
                                                                if (prop.range == range) {
                                                                        if (first) {
                                                                                first = false;
@@ -125,7 +126,7 @@ namespace Tracker.Sparql {
                                } else if (domain != null) {
                                        // any subject, predicates limited to a specific domain
                                        bool first = true;
-                                       foreach (Property prop in Ontologies.get_properties ()) {
+                                       foreach (Property prop in ontologies.get_properties ()) {
                                                if (prop.domain == domain) {
                                                        if (first) {
                                                                first = false;
@@ -878,7 +879,8 @@ class Tracker.Sparql.Pattern : Object {
                        } else {
                                return false;
                        }
-                       var prop = Ontologies.get_property_by_uri (predicate);
+                       var ontologies = Data.Manager.get_ontologies ();
+                       var prop = ontologies.get_property_by_uri (predicate);
                        if (prop == null) {
                                return false;
                        }
@@ -1351,15 +1353,17 @@ class Tracker.Sparql.Pattern : Object {
 
                Class subject_type = null;
 
+               var ontologies = Data.Manager.get_ontologies ();
+
                if (!current_predicate_is_var) {
-                       prop = Ontologies.get_property_by_uri (current_predicate);
+                       prop = ontologies.get_property_by_uri (current_predicate);
 
                        if (current_predicate == "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
                            && !object_is_var && current_graph == null) {
                                // rdf:type query
                                // avoid special casing if GRAPH is used as graph matching is not supported 
when using class tables
                                rdftype = true;
-                               var cl = Ontologies.get_class_by_uri (object);
+                               var cl = ontologies.get_class_by_uri (object);
                                if (cl == null) {
                                        throw new Sparql.Error.UNKNOWN_CLASS ("Unknown class `%s'".printf 
(object));
                                }
@@ -1380,7 +1384,7 @@ class Tracker.Sparql.Pattern : Object {
                                    && current_subject_is_var
                                    && !object_is_var) {
                                        // rdfs:domain
-                                       var domain = Ontologies.get_class_by_uri (object);
+                                       var domain = ontologies.get_class_by_uri (object);
                                        if (domain == null) {
                                                throw new Sparql.Error.UNKNOWN_CLASS ("Unknown class 
`%s'".printf (object));
                                        }
diff --git a/src/libtracker-data/tracker-sparql-query.vala b/src/libtracker-data/tracker-sparql-query.vala
index 7f9cb81..82f86e1 100644
--- a/src/libtracker-data/tracker-sparql-query.vala
+++ b/src/libtracker-data/tracker-sparql-query.vala
@@ -404,8 +404,9 @@ public class Tracker.Sparql.Query : Object {
 
                // declare fn prefix for XPath functions
                prefix_map.insert ("fn", FN_NS);
+               var ontologies = Data.Manager.get_ontologies ();
 
-               foreach (Namespace ns in Ontologies.get_namespaces ()) {
+               foreach (Namespace ns in ontologies.get_namespaces ()) {
                        if (ns.prefix == null) {
                                critical ("Namespace does not specify a prefix: %s", ns.uri);
                                continue;
@@ -448,8 +449,9 @@ public class Tracker.Sparql.Query : Object {
 
                // declare fn prefix for XPath functions
                prefix_map.insert ("fn", FN_NS);
+               var ontologies = Data.Manager.get_ontologies ();
 
-               foreach (Namespace ns in Ontologies.get_namespaces ()) {
+               foreach (Namespace ns in ontologies.get_namespaces ()) {
                        if (ns.prefix == null) {
                                critical ("Namespace does not specify a prefix: %s", ns.uri);
                                continue;
diff --git a/src/libtracker-fts/tracker-fts-tokenizer.c b/src/libtracker-fts/tracker-fts-tokenizer.c
index 474ab76..b7ddf7b 100644
--- a/src/libtracker-fts/tracker-fts-tokenizer.c
+++ b/src/libtracker-fts/tracker-fts-tokenizer.c
@@ -27,6 +27,7 @@
 #include <string.h>
 
 #include <libtracker-common/tracker-parser.h>
+#include <libtracker-data/tracker-data-manager.h>
 #include <libtracker-data/tracker-ontologies.h>
 
 #include "tracker-fts-tokenizer.h"
@@ -270,6 +271,7 @@ get_fts_weights (sqlite3_context *context)
        static GHashTable *weights = NULL;
        static GMutex mutex;
        int rc = SQLITE_DONE;
+       TrackerOntologies *ontologies;
 
        g_mutex_lock (&mutex);
 
@@ -287,6 +289,8 @@ get_fts_weights (sqlite3_context *context)
                                         "WHERE \"rdf:Property\".\"tracker:fulltextIndexed\" = 1 ",
                                         -1, &stmt, NULL);
 
+               ontologies = tracker_data_manager_get_ontologies ();
+
                while ((rc = sqlite3_step (stmt)) != SQLITE_DONE) {
                        if (rc == SQLITE_ROW) {
                                TrackerProperty *property;
@@ -295,7 +299,7 @@ get_fts_weights (sqlite3_context *context)
                                weight = sqlite3_column_int (stmt, 0);
                                uri = (gchar *)sqlite3_column_text (stmt, 1);
 
-                               property = tracker_ontologies_get_property_by_uri (uri);
+                               property = tracker_ontologies_get_property_by_uri (ontologies, uri);
                                g_hash_table_insert (weights,
                                                     (gpointer) tracker_property_get_name (property),
                                                     GUINT_TO_POINTER (weight));
diff --git a/src/tracker-store/tracker-events.c b/src/tracker-store/tracker-events.c
index 8c8f46d..27827fe 100644
--- a/src/tracker-store/tracker-events.c
+++ b/src/tracker-store/tracker-events.c
@@ -167,12 +167,14 @@ tracker_events_get_classes (guint *length)
 void
 tracker_events_init (void)
 {
+       TrackerOntologies *ontologies;
        TrackerClass **classes;
        guint length = 0, i;
 
        private = g_new0 (EventsPrivate, 1);
 
-       classes = tracker_ontologies_get_classes (&length);
+       ontologies = tracker_data_manager_get_ontologies ();
+       classes = tracker_ontologies_get_classes (ontologies, &length);
 
        private->notify_classes = g_ptr_array_sized_new (length);
        g_ptr_array_set_free_func (private->notify_classes, (GDestroyNotify) g_object_unref);
diff --git a/src/tracker-store/tracker-statistics.vala b/src/tracker-store/tracker-statistics.vala
index 0e2b45f..70f8daf 100644
--- a/src/tracker-store/tracker-statistics.vala
+++ b/src/tracker-store/tracker-statistics.vala
@@ -26,11 +26,12 @@ public class Tracker.Statistics : Object {
        [DBus (signature = "aas")]
        public new Variant get (BusName sender) throws GLib.Error {
                var request = DBusRequest.begin (sender, "Statistics.Get");
+               var ontologies = Data.Manager.get_ontologies ();
 
                if (!initialized) {
                        var iface = DBManager.get_db_interface ();
 
-                       foreach (var cl in Ontologies.get_classes ()) {
+                       foreach (var cl in ontologies.get_classes ()) {
                                /* xsd classes do not derive from rdfs:Resource and do not use separate 
tables */
                                if (!cl.name.has_prefix ("xsd:")) {
                                        /* update statistics */
@@ -52,7 +53,7 @@ public class Tracker.Statistics : Object {
 
                var builder = new VariantBuilder ((VariantType) "aas");
 
-               foreach (var cl in Ontologies.get_classes ()) {
+               foreach (var cl in ontologies.get_classes ()) {
                        if (cl.count == 0) {
                                /* skip classes without resources */
                                continue;
diff --git a/src/tracker-store/tracker-writeback.c b/src/tracker-store/tracker-writeback.c
index bdd02d5..4882cf1 100644
--- a/src/tracker-store/tracker-writeback.c
+++ b/src/tracker-store/tracker-writeback.c
@@ -137,6 +137,7 @@ free_private (gpointer user_data)
 void
 tracker_writeback_init (TrackerWritebackGetPredicatesFunc func)
 {
+       TrackerOntologies *ontologies;
        GStrv predicates_to_signal;
        gint i, count;
 
@@ -164,9 +165,10 @@ tracker_writeback_init (TrackerWritebackGetPredicatesFunc func)
        }
 
        count = g_strv_length (predicates_to_signal);
+       ontologies = tracker_data_manager_get_ontologies ();
 
        for (i = 0; i < count; i++) {
-               TrackerProperty *predicate = tracker_ontologies_get_property_by_uri (predicates_to_signal[i]);
+               TrackerProperty *predicate = tracker_ontologies_get_property_by_uri (ontologies, 
predicates_to_signal[i]);
                if (predicate) {
                        gint id = tracker_property_get_id (predicate);
                        g_message ("  Adding:'%s'", predicates_to_signal[i]);


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