[tracker/wip/carlosg/domain-ontologies: 4/55] libtracker-data: tracker-store: Initial infrastructure to support domain specific ontologies



commit 072049a49cfe99aa37307661055cc951b415b2d4
Author: Philip Van Hoof <philip codeminded be>
Date:   Thu Jan 26 22:36:15 2017 +0100

    libtracker-data: tracker-store: Initial infrastructure to support domain
    specific ontologies

 src/libtracker-data/libtracker-data.vapi           |    4 +-
 src/libtracker-data/tracker-data-backup.c          |    5 ++-
 src/libtracker-data/tracker-data-backup.h          |    2 +
 src/libtracker-data/tracker-data-manager.c         |   35 +++++++++++++--
 src/libtracker-data/tracker-data-manager.h         |    2 +
 src/libtracker-data/tracker-db-manager.c           |   46 +++++++++++++++----
 src/libtracker-data/tracker-db-manager.h           |    2 +
 src/libtracker-direct/tracker-direct.vala          |   30 ++++++++++++-
 src/tracker-store/tracker-backup.vala              |    3 +-
 src/tracker-store/tracker-main.vala                |    3 +-
 src/tracker/tracker-reset.c                        |    1 +
 src/tracker/tracker-sql.c                          |    2 +-
 tests/libtracker-data/tracker-backup-test.c        |    4 +-
 .../libtracker-data/tracker-ontology-change-test.c |    4 +-
 tests/libtracker-data/tracker-ontology-test.c      |    3 +
 tests/libtracker-data/tracker-sparql-blank-test.c  |    1 +
 tests/libtracker-data/tracker-sparql-test.c        |    1 +
 tests/libtracker-fts/tracker-fts-test.c            |    1 +
 18 files changed, 124 insertions(+), 25 deletions(-)
---
diff --git a/src/libtracker-data/libtracker-data.vapi b/src/libtracker-data/libtracker-data.vapi
index 540733d..4d2cf57 100644
--- a/src/libtracker-data/libtracker-data.vapi
+++ b/src/libtracker-data/libtracker-data.vapi
@@ -224,12 +224,12 @@ namespace Tracker {
                public delegate void BackupFinished (GLib.Error error);
 
                public void backup_save (GLib.File destination, owned BackupFinished callback);
-               public void backup_restore (GLib.File journal, [CCode (array_length = false)] string[]? 
test_schema, BusyCallback busy_callback) throws GLib.Error;
+               public void backup_restore (GLib.File journal, string? domain, string? ontology_name, [CCode 
(array_length = false)] string[]? test_schema, BusyCallback busy_callback) throws GLib.Error;
        }
 
        [CCode (cheader_filename = "libtracker-data/tracker-data-manager.h")]
        namespace Data.Manager {
-               public bool init (DBManagerFlags flags, [CCode (array_length = false)] string[]? test_schema, 
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 bool init (DBManagerFlags flags, string? domain, string? ontology_name, [CCode 
(array_length = false)] string[]? test_schema, 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 ();
        }
 
diff --git a/src/libtracker-data/tracker-data-backup.c b/src/libtracker-data/tracker-data-backup.c
index 3947dde..db82419 100644
--- a/src/libtracker-data/tracker-data-backup.c
+++ b/src/libtracker-data/tracker-data-backup.c
@@ -555,6 +555,8 @@ tracker_data_backup_save (GFile                     *destination,
 
 void
 tracker_data_backup_restore (GFile                *journal,
+                             const gchar          *domain,
+                             const gchar          *ontology,                             
                              const gchar         **test_schemas,
                              TrackerBusyCallback   busy_callback,
                              gpointer              busy_user_data,
@@ -694,7 +696,8 @@ tracker_data_backup_restore (GFile                *journal,
                }
 #endif /* DISABLE_JOURNAL */
 
-               tracker_data_manager_init (flags, test_schemas, &is_first, TRUE, TRUE,
+               tracker_data_manager_init (flags, domain, ontology, test_schemas,
+                                          &is_first, TRUE, TRUE,
                                           select_cache_size, update_cache_size,
                                           busy_callback, busy_user_data,
                                           "Restoring backup", &internal_error);
diff --git a/src/libtracker-data/tracker-data-backup.h b/src/libtracker-data/tracker-data-backup.h
index 92c0a4c..fb15427 100644
--- a/src/libtracker-data/tracker-data-backup.h
+++ b/src/libtracker-data/tracker-data-backup.h
@@ -48,6 +48,8 @@ void   tracker_data_backup_save        (GFile                     *destination,
                                         gpointer                   user_data,
                                         GDestroyNotify             destroy);
 void   tracker_data_backup_restore     (GFile                     *journal,
+                                        const gchar               *domain,
+                                        const gchar               *ontology,
                                         const gchar              **test_schema,
                                         TrackerBusyCallback        busy_callback,
                                         gpointer                   busy_user_data,
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 13fd0ad..575b49e 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -66,6 +66,8 @@
 #define ZLIBBUFSIZ 8192
 
 static gchar    *ontologies_dir;
+static gchar    *ontology_name_stored;
+static gchar    *domain_stored;
 static gboolean  initialized;
 static gboolean  reloading = FALSE;
 #ifndef DISABLE_JOURNAL
@@ -3531,6 +3533,7 @@ tracker_data_manager_reload (TrackerBusyCallback   busy_callback,
 
        /* And initialize it again, this actually triggers index recreation. */
        status = tracker_data_manager_init (flags,
+                                           domain_stored, ontology_name_stored,
                                            NULL,
                                            &is_first,
                                            TRUE,
@@ -3671,6 +3674,8 @@ tracker_data_manager_init_fts (TrackerDBInterface *iface,
 
 gboolean
 tracker_data_manager_init (TrackerDBManagerFlags   flags,
+                           const gchar            *domain,
+                           const gchar            *ontology_name,
                            const gchar           **test_schemas,
                            gboolean               *first_time,
                            gboolean                journal_check,
@@ -3728,7 +3733,8 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
        read_journal = FALSE;
 #endif
 
-       if (!tracker_db_manager_init (flags,
+    if (!tracker_db_manager_init (flags,
+                                  domain, ontology_name,
                                      &is_first_time_index,
                                      restoring_backup,
                                      FALSE,
@@ -3798,11 +3804,27 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 
        env_path = g_getenv ("TRACKER_DB_ONTOLOGIES_DIR");
 
+       g_free (domain_stored);
+       domain_stored = g_strdup(domain);
+       g_free (ontology_name_stored);
+       ontology_name_stored = g_strdup(ontology_name);
+       
        if (G_LIKELY (!env_path)) {
-               ontologies_dir = g_build_filename (SHAREDIR,
-                                                  "tracker",
-                                                  "ontologies",
-                                                  NULL);
+               if (ontology_name == NULL) {
+                       ontologies_dir = g_build_filename (SHAREDIR,
+                                                          "tracker",
+                                                          "ontologies",
+                                                      NULL);
+               } else {
+                       if (domain == NULL) {
+                               domain = "tracker";
+                       }
+                       ontologies_dir = g_build_filename (SHAREDIR,
+                                                          domain,
+                                                          "ontologies",
+                                                          ontology_name,
+                                                          NULL);
+               }
        } else {
                ontologies_dir = g_strdup (env_path);
        }
@@ -4260,6 +4282,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                                                tracker_data_manager_shutdown ();
 
                                                return tracker_data_manager_init (flags | 
TRACKER_DB_MANAGER_DO_NOT_CHECK_ONTOLOGY,
+                                                                                 domain, ontology_name,
                                                                                  test_schemas,
                                                                                  first_time,
                                                                                  journal_check,
@@ -4350,6 +4373,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                                        tracker_data_manager_shutdown ();
 
                                        return tracker_data_manager_init (flags | 
TRACKER_DB_MANAGER_DO_NOT_CHECK_ONTOLOGY,
+                                                                         domain, ontology_name,
                                                                          test_schemas,
                                                                          first_time,
                                                                          journal_check,
@@ -4457,6 +4481,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
                                tracker_data_manager_shutdown ();
 
                                return tracker_data_manager_init (flags | 
TRACKER_DB_MANAGER_DO_NOT_CHECK_ONTOLOGY,
+                                                                 domain, ontology_name,
                                                                  test_schemas,
                                                                  first_time,
                                                                  journal_check,
diff --git a/src/libtracker-data/tracker-data-manager.h b/src/libtracker-data/tracker-data-manager.h
index 4ffecca..e18c45b 100644
--- a/src/libtracker-data/tracker-data-manager.h
+++ b/src/libtracker-data/tracker-data-manager.h
@@ -46,6 +46,8 @@ typedef enum {
 
 GQuark   tracker_data_ontology_error_quark           (void);
 gboolean tracker_data_manager_init                   (TrackerDBManagerFlags   flags,
+                                                      const gchar            *domain,
+                                                      const gchar            *ontology_name,
                                                       const gchar           **test_schema,
                                                       gboolean               *first_time,
                                                       gboolean                journal_check,
diff --git a/src/libtracker-data/tracker-db-manager.c b/src/libtracker-data/tracker-db-manager.c
index 0d9abcf..d717392 100644
--- a/src/libtracker-data/tracker-db-manager.c
+++ b/src/libtracker-data/tracker-db-manager.c
@@ -156,6 +156,8 @@ static gboolean              locations_initialized;
 static gchar                *data_dir = NULL;
 static gchar                *user_data_dir = NULL;
 static gchar                *in_use_filename = NULL;
+static gchar                *in_use_domain = NULL;
+static gchar                *in_use_ontology_name = NULL;
 static gpointer              db_type_enum_class_pointer;
 static TrackerDBManagerFlags old_flags = 0;
 static guint                 s_cache_size;
@@ -855,6 +857,8 @@ perform_recreate (gboolean *first_time, GError **error)
 
 static gboolean
 db_manager_init_unlocked (TrackerDBManagerFlags   flags,
+                          const gchar            *domain,
+                          const gchar            *ontology_name,
                           gboolean               *first_time,
                           gboolean                restoring_backup,
                           gboolean                shared_cache,
@@ -905,11 +909,30 @@ db_manager_init_unlocked (TrackerDBManagerFlags   flags,
        tracker_db_manager_init_locations ();
 
        g_free (in_use_filename);
-       in_use_filename = g_build_filename (g_get_user_data_dir (),
-                                           "tracker",
-                                           "data",
-                                           IN_USE_FILENAME,
-                                           NULL);
+    g_free (in_use_domain);
+    g_free (in_use_ontology_name);
+
+    if (domain == NULL) {
+        domain = "tracker";
+
+    }
+    in_use_domain = g_strdup (domain);
+
+    if (ontology_name == NULL) {
+        in_use_ontology_name = NULL;
+        in_use_filename = g_build_filename (g_get_user_data_dir (),
+                                            domain,
+                                            "data",
+                                            IN_USE_FILENAME,
+                                            NULL);
+    } else {
+        in_use_ontology_name = g_strdup (ontology_name);
+        in_use_filename = g_build_filename (g_get_user_data_dir (),
+                                            domain, ontology_name,
+                                            "data",
+                                            IN_USE_FILENAME,
+                                            NULL);
+    }
 
        /* Don't do need_reindex checks for readonly (direct-access) */
        if ((flags & TRACKER_DB_MANAGER_READONLY) == 0) {
@@ -1247,6 +1270,8 @@ db_manager_init_unlocked (TrackerDBManagerFlags   flags,
 
 gboolean
 tracker_db_manager_init (TrackerDBManagerFlags   flags,
+                         const gchar            *domain,
+                         const gchar            *ontology_name,
                          gboolean               *first_time,
                          gboolean                restoring_backup,
                          gboolean                shared_cache,
@@ -1261,11 +1286,12 @@ tracker_db_manager_init (TrackerDBManagerFlags   flags,
 
        g_mutex_lock (&init_mutex);
 
-       retval = db_manager_init_unlocked (flags, first_time, restoring_backup,
-                                          shared_cache,
-                                          select_cache_size, update_cache_size,
-                                          busy_callback, busy_user_data,
-                                          busy_operation, error);
+       retval = db_manager_init_unlocked (flags, domain, ontology_name,
+                                          first_time, restoring_backup,
+                                          shared_cache,
+                                          select_cache_size, update_cache_size,
+                                          busy_callback, busy_user_data,
+                                          busy_operation, error);
 
        g_mutex_unlock (&init_mutex);
 
diff --git a/src/libtracker-data/tracker-db-manager.h b/src/libtracker-data/tracker-db-manager.h
index 86af426..a763b45 100644
--- a/src/libtracker-data/tracker-db-manager.h
+++ b/src/libtracker-data/tracker-db-manager.h
@@ -53,6 +53,8 @@ typedef enum {
 
 GType               tracker_db_get_type                       (void) G_GNUC_CONST;
 gboolean            tracker_db_manager_init                   (TrackerDBManagerFlags   flags,
+                                                               const gchar            *domain,
+                                                               const gchar            *ontology_name,
                                                                gboolean               *first_time,
                                                                gboolean                restoring_backup,
                                                                gboolean                shared_cache,
diff --git a/src/libtracker-direct/tracker-direct.vala b/src/libtracker-direct/tracker-direct.vala
index ca37330..f978586 100644
--- a/src/libtracker-direct/tracker-direct.vala
+++ b/src/libtracker-direct/tracker-direct.vala
@@ -37,7 +37,9 @@ public class Tracker.Direct.Connection : Tracker.Sparql.Connection {
                                        select_cache_size = int.parse (env_cache_size);
                                }
 
-                               Data.Manager.init (DBManagerFlags.READONLY | DBManagerFlags.ENABLE_MUTEXES, 
null, null, false, false, select_cache_size, 0, null, null);
+                               Data.Manager.init (DBManagerFlags.READONLY | DBManagerFlags.ENABLE_MUTEXES,
+                                                  null /* domain */ , null /* ontology */,
+                                                  null, null, false, false, select_cache_size, 0, null, 
null);
                        }
 
                        use_count++;
@@ -47,6 +49,32 @@ public class Tracker.Direct.Connection : Tracker.Sparql.Connection {
                }
        }
 
+        public Connection.custom_ontology (string domain, string ontology_name) throws Sparql.Error, 
IOError, DBusError {
+               try {
+                       if (use_count == 0) {
+                               // make sure that current locale vs db locale are the same,
+                               // otherwise return an error
+                               Locale.init ();
+                               DBManager.locale_changed ();
+
+                               uint select_cache_size = 100;
+                               string env_cache_size = Environment.get_variable 
("TRACKER_SPARQL_CACHE_SIZE");
+
+                               if (env_cache_size != null) {
+                                       select_cache_size = int.parse (env_cache_size);
+                               }
+
+                               Data.Manager.init (DBManagerFlags.READONLY | DBManagerFlags.ENABLE_MUTEXES,
+                                                  domain, ontology_name,
+                                                  null, null, false, false, select_cache_size, 0, null, 
null);
+                       }
+
+                       use_count++;
+                       initialized = true;
+               } catch (Error e) {
+                       throw new Sparql.Error.INTERNAL (e.message);
+               }
+       }
        ~Connection () {
                if (!initialized) {
                        // use_count did not get increased if initialization failed
diff --git a/src/tracker-store/tracker-backup.vala b/src/tracker-store/tracker-backup.vala
index a98e725..77a812f 100644
--- a/src/tracker-store/tracker-backup.vala
+++ b/src/tracker-store/tracker-backup.vala
@@ -84,7 +84,8 @@ public class Tracker.Backup : Object {
                        var notifier = (Status) (Tracker.DBus.get_object (typeof (Status)));
                        var busy_callback = notifier.get_callback ();
 
-                       Data.backup_restore (journal, null, busy_callback);
+                       // TODO: set domain and ontology_name here from store session
+                       Data.backup_restore (journal, null, null, null, busy_callback);
 
                        request.end ();
                } catch (Error e) {
diff --git a/src/tracker-store/tracker-main.vala b/src/tracker-store/tracker-main.vala
index 32faead..380b6ac 100644
--- a/src/tracker-store/tracker-main.vala
+++ b/src/tracker-store/tracker-main.vala
@@ -260,7 +260,8 @@ License which can be viewed at:
                bool is_first_time_index;
 
                try {
-                       Tracker.Data.Manager.init (flags,
+                       // TODO: Set domain and ontology name here
+                       Tracker.Data.Manager.init (flags, null, null,
                                                   null,
                                                   out is_first_time_index,
                                                   true,
diff --git a/src/tracker/tracker-reset.c b/src/tracker/tracker-reset.c
index d4821cd..de1d097 100644
--- a/src/tracker/tracker-reset.c
+++ b/src/tracker/tracker-reset.c
@@ -292,6 +292,7 @@ reset_run (void)
 
                /* Clean up (select_cache_size and update_cache_size don't matter here) */
                if (!tracker_db_manager_init (TRACKER_DB_MANAGER_REMOVE_ALL,
+                                      NULL, NULL, /* domain and ontology-name */
                                              NULL,
                                              FALSE,
                                              FALSE,
diff --git a/src/tracker/tracker-sql.c b/src/tracker/tracker-sql.c
index 8385093..2616ce4 100644
--- a/src/tracker/tracker-sql.c
+++ b/src/tracker/tracker-sql.c
@@ -97,7 +97,7 @@ sql_by_query (void)
        gboolean first_time = FALSE;
        gint n_rows = 0;
 
-       if (!tracker_data_manager_init (0,
+       if (!tracker_data_manager_init (0, NULL, NULL,
                                        NULL,
                                        &first_time,
                                        FALSE,
diff --git a/tests/libtracker-data/tracker-backup-test.c b/tests/libtracker-data/tracker-backup-test.c
index 91645bd..d09b064 100644
--- a/tests/libtracker-data/tracker-backup-test.c
+++ b/tests/libtracker-data/tracker-backup-test.c
@@ -124,6 +124,7 @@ test_backup_and_restore_helper (gboolean journal)
        tracker_db_journal_set_rotating (FALSE, G_MAXSIZE, NULL);
 
        tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
+                                  NULL, NULL,
                                   (const gchar **) test_schemas,
                                   NULL, FALSE, FALSE,
                                   100, 100, NULL, NULL, NULL, &error);
@@ -188,6 +189,7 @@ test_backup_and_restore_helper (gboolean journal)
 #endif /* DISABLE_JOURNAL */
 
        tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
+                                  NULL, NULL,
                                   (const gchar **) test_schemas,
                                   NULL, FALSE, FALSE,
                                   100, 100, NULL, NULL, NULL, &error);
@@ -196,7 +198,7 @@ test_backup_and_restore_helper (gboolean journal)
 
        check_content_in_db (0, 0);
 
-       tracker_data_backup_restore (backup_file, (const gchar **) test_schemas, NULL, NULL, &error);
+       tracker_data_backup_restore (backup_file, NULL, NULL,(const gchar **) test_schemas, NULL, NULL, 
&error);
        g_assert_no_error (error);
        check_content_in_db (3, 1);
 
diff --git a/tests/libtracker-data/tracker-ontology-change-test.c 
b/tests/libtracker-data/tracker-ontology-change-test.c
index 1f15efd..806c18f 100644
--- a/tests/libtracker-data/tracker-ontology-change-test.c
+++ b/tests/libtracker-data/tracker-ontology-change-test.c
@@ -228,7 +228,7 @@ test_ontology_change (void)
                g_assert_no_error (error);
                g_chmod (ontology_file, 0666);
 
-               tracker_data_manager_init (0, (const gchar **) test_schemas,
+               tracker_data_manager_init (0, NULL, NULL, (const gchar **) test_schemas,
                                           NULL, FALSE, FALSE,
                                           100, 100, NULL, NULL, NULL, &error);
 
@@ -272,7 +272,7 @@ test_ontology_change (void)
 
        delete_db (FALSE);
 
-       tracker_data_manager_init (0, (const gchar **) test_schemas,
+       tracker_data_manager_init (0, NULL, NULL, (const gchar **) test_schemas,
                                   NULL, TRUE, FALSE,
                                   100, 100, NULL, NULL, NULL, &error);
 
diff --git a/tests/libtracker-data/tracker-ontology-test.c b/tests/libtracker-data/tracker-ontology-test.c
index ce5bce8..1abc3f8 100644
--- a/tests/libtracker-data/tracker-ontology-test.c
+++ b/tests/libtracker-data/tracker-ontology-test.c
@@ -187,6 +187,7 @@ test_ontology_init (TestInfo      *test_info,
 
        /* first-time initialization */
        tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
+                                  NULL, NULL,
                                   NULL,
                                   NULL,
                                   FALSE,
@@ -206,6 +207,7 @@ test_ontology_init (TestInfo      *test_info,
 
        /* initialization from existing database */
        tracker_data_manager_init (0,
+                                  NULL, NULL,
                                   NULL,
                                   NULL,
                                   FALSE,
@@ -241,6 +243,7 @@ test_query (TestInfo      *test_info,
 
        /* initialization */
        tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
+                                  NULL, NULL, /* domain and ontology_name */
                                   NULL,
                                   NULL,
                                   FALSE,
diff --git a/tests/libtracker-data/tracker-sparql-blank-test.c 
b/tests/libtracker-data/tracker-sparql-blank-test.c
index da6c8bd..69f3ba4 100644
--- a/tests/libtracker-data/tracker-sparql-blank-test.c
+++ b/tests/libtracker-data/tracker-sparql-blank-test.c
@@ -56,6 +56,7 @@ test_blank (TestInfo      *info,
 
        /* initialization */
        tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
+                                  NULL, NULL, /* domain and ontology_name */
                                   NULL,
                                   NULL,
                                   FALSE,
diff --git a/tests/libtracker-data/tracker-sparql-test.c b/tests/libtracker-data/tracker-sparql-test.c
index 6be3c06..0f87985 100644
--- a/tests/libtracker-data/tracker-sparql-test.c
+++ b/tests/libtracker-data/tracker-sparql-test.c
@@ -268,6 +268,7 @@ test_sparql_query (TestInfo      *test_info,
        tracker_db_journal_set_rotating (FALSE, G_MAXSIZE, NULL);
 
        tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
+                                  NULL, NULL, /* domain and ontology_name */
                                   test_schemas,
                                   NULL, FALSE, FALSE,
                                   100, 100, NULL, NULL, NULL, &error);
diff --git a/tests/libtracker-fts/tracker-fts-test.c b/tests/libtracker-fts/tracker-fts-test.c
index 3712cd1..f9ca792 100644
--- a/tests/libtracker-fts/tracker-fts-test.c
+++ b/tests/libtracker-fts/tracker-fts-test.c
@@ -69,6 +69,7 @@ test_sparql_query (gconstpointer test_data)
        test_schemas[0] = data_prefix;
        tracker_db_journal_set_rotating (FALSE, G_MAXSIZE, NULL);
        tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
+                                  NULL, NULL,
                                   test_schemas,
                                   NULL, FALSE, FALSE,
                                   100, 100, NULL, NULL, NULL, &error);


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