[tracker/wip/carlosg/domain-ontologies: 53/55] libtracker-data: Make TrackerDataManager a non singleton
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/domain-ontologies: 53/55] libtracker-data: Make TrackerDataManager a non singleton
- Date: Sun, 11 Jun 2017 15:07:45 +0000 (UTC)
commit d3324f9e8fc93444236ab35d683958dee897493a
Author: Carlos Garnacho <carlosg gnome org>
Date: Sat Jun 10 16:31:56 2017 +0200
libtracker-data: Make TrackerDataManager a non singleton
There can now be multiple instances looking into separate database
and journal locations. TrackerDataManager has been made an initable
too, and busy handling has been lifted to a signal, in order to
reduce the arguments at new() a bit.
src/libtracker-data/libtracker-data.vapi | 12 +-
src/libtracker-data/tracker-data-backup.c | 28 +-
src/libtracker-data/tracker-data-backup.h | 3 +-
src/libtracker-data/tracker-data-manager.c | 1178 ++++++++++----------
src/libtracker-data/tracker-data-manager.h | 55 +-
src/libtracker-data/tracker-data-query.c | 19 +-
src/libtracker-data/tracker-data-query.h | 12 +-
src/libtracker-data/tracker-data-update.c | 160 ++-
src/libtracker-data/tracker-data-update.h | 19 +-
src/libtracker-data/tracker-db-manager.c | 8 +
src/libtracker-data/tracker-db-manager.h | 1 +
src/libtracker-data/tracker-sparql-expression.vala | 5 +-
src/libtracker-data/tracker-sparql-pattern.vala | 27 +-
src/libtracker-data/tracker-sparql-query.vala | 21 +-
src/libtracker-data/tracker-turtle-reader.vala | 3 +-
src/libtracker-direct/tracker-direct.vala | 34 +-
src/libtracker-fts/tracker-fts-tokenizer.c | 11 +-
src/tracker-store/tracker-backup.vala | 7 +-
src/tracker-store/tracker-events.c | 4 +-
src/tracker-store/tracker-events.h | 2 +-
src/tracker-store/tracker-events.vapi | 2 +-
src/tracker-store/tracker-main.vala | 36 +-
src/tracker-store/tracker-resources.vala | 27 +-
src/tracker-store/tracker-statistics.vala | 5 +-
src/tracker-store/tracker-status.vala | 2 +-
src/tracker-store/tracker-steroids.vala | 13 +-
src/tracker-store/tracker-store.vala | 38 +-
src/tracker-store/tracker-writeback.c | 5 +-
src/tracker-store/tracker-writeback.h | 3 +-
src/tracker-store/tracker-writeback.vapi | 2 +-
src/tracker/tracker-reset.c | 1 +
src/tracker/tracker-sql.c | 20 +-
tests/libtracker-data/tracker-backup-test.c | 44 +-
.../libtracker-data/tracker-ontology-change-test.c | 30 +-
tests/libtracker-data/tracker-ontology-test.c | 69 +-
tests/libtracker-data/tracker-sparql-blank-test.c | 22 +-
tests/libtracker-data/tracker-sparql-test.c | 22 +-
tests/libtracker-fts/tracker-fts-test.c | 18 +-
38 files changed, 998 insertions(+), 970 deletions(-)
---
diff --git a/src/libtracker-data/libtracker-data.vapi b/src/libtracker-data/libtracker-data.vapi
index 4030c0d..8dd7ad4 100644
--- a/src/libtracker-data/libtracker-data.vapi
+++ b/src/libtracker-data/libtracker-data.vapi
@@ -69,6 +69,7 @@ namespace Tracker {
[CCode (cheader_filename = "libtracker-data/tracker-db-interface-sqlite.h")]
public void sqlite_wal_hook (DBWalCallback callback);
public void sqlite_wal_checkpoint (bool blocking) throws DBInterfaceError;
+ public unowned GLib.Object get_user_data ();
}
[CCode (cheader_filename = "libtracker-data/tracker-data-update.h")]
@@ -221,20 +222,19 @@ namespace Tracker {
[CCode (cheader_filename = "libtracker-data/tracker-data-backup.h")]
namespace Data {
- public int query_resource_id (string uri);
- public DBCursor query_sparql_cursor (string query) throws Sparql.Error;
+ public int query_resource_id (Data.Manager manager, string uri);
+ public DBCursor query_sparql_cursor (Data.Manager manager, string query) throws Sparql.Error;
public void backup_save (GLib.File destination, GLib.File data_location, owned BackupFinished
callback);
- public void backup_restore (GLib.File journal, string? cache_location, string? data_location,
GLib.File? ontology_location, BusyCallback busy_callback) throws GLib.Error;
+ public void backup_restore (Data.Manager manager, GLib.File journal, string? cache_location,
string? data_location, GLib.File? ontology_location, BusyCallback busy_callback) throws GLib.Error;
[CCode (cheader_filename = "libtracker-data/tracker-data-backup.h")]
public delegate void BackupFinished (GLib.Error error);
}
[CCode (cheader_filename = "libtracker-data/tracker-data-manager.h")]
- 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 class Data.Manager : GLib.Object, GLib.Initable {
+ public Manager (DBManagerFlags flags, GLib.File cache_location, GLib.File data_location,
GLib.File ontology_location, bool journal_check, bool restoring_backup, uint select_cache_size, uint
update_cache_size);
public unowned Ontologies get_ontologies ();
public unowned DBInterface get_db_interface ();
public unowned Data.Update get_data ();
diff --git a/src/libtracker-data/tracker-data-backup.c b/src/libtracker-data/tracker-data-backup.c
index f291ecb..9cd3300 100644
--- a/src/libtracker-data/tracker-data-backup.c
+++ b/src/libtracker-data/tracker-data-backup.c
@@ -543,7 +543,8 @@ tracker_data_backup_save (GFile *destination,
}
void
-tracker_data_backup_restore (GFile *journal,
+tracker_data_backup_restore (TrackerDataManager *manager,
+ GFile *journal,
GFile *cache_location,
GFile *data_location,
GFile *ontology_location,
@@ -563,7 +564,7 @@ tracker_data_backup_restore (GFile *journal,
return;
}
- db_manager = tracker_data_manager_get_db_manager ();
+ db_manager = tracker_data_manager_get_db_manager (manager);
info = g_new0 (BackupSaveInfo, 1);
#ifndef DISABLE_JOURNAL
info->destination = g_file_get_child (data_location, TRACKER_DB_JOURNAL_FILENAME);
@@ -577,7 +578,6 @@ tracker_data_backup_restore (GFile *journal,
TrackerDBManagerFlags flags;
TrackerDBJournal *journal_writer;
guint select_cache_size, update_cache_size;
- gboolean is_first;
#ifndef DISABLE_JOURNAL
GError *n_error = NULL;
GFile *parent = g_file_get_parent (info->destination);
@@ -590,7 +590,7 @@ tracker_data_backup_restore (GFile *journal,
flags = tracker_db_manager_get_flags (db_manager, &select_cache_size, &update_cache_size);
- tracker_data_manager_shutdown ();
+ //tracker_data_manager_shutdown ();
move_to_temp (cache_location, data_location);
@@ -691,24 +691,18 @@ tracker_data_backup_restore (GFile *journal,
}
#endif /* DISABLE_JOURNAL */
- tracker_data_manager_init (flags, cache_location, data_location, ontology_location,
- &is_first, TRUE, TRUE,
- select_cache_size, update_cache_size,
- busy_callback, busy_user_data,
- "Restoring backup", &internal_error);
+ manager = tracker_data_manager_new (flags, cache_location, data_location, ontology_location,
+ TRUE, TRUE, select_cache_size, update_cache_size);
+ g_initable_init (G_INITABLE (manager), NULL, &internal_error);
#ifdef DISABLE_JOURNAL
if (internal_error) {
restore_from_temp ();
+ g_object_unref (manager);
- tracker_data_manager_init (flags,
- cache_location,
- data_location,
- ontology_location,
- &is_first, TRUE, TRUE,
- select_cache_size, update_cache_size,
- busy_callback, busy_user_data,
- "Restoring backup", &internal_error);
+ manager = tracker_data_manager_new (flags, cache_location, data_location,
ontology_location,
+ TRUE, TRUE, select_cache_size, update_cache_size);
+ g_initable_init (G_INITABLE (manager), NULL, &internal_error);
} else {
remove_temp ();
}
diff --git a/src/libtracker-data/tracker-data-backup.h b/src/libtracker-data/tracker-data-backup.h
index 856d9c6..6b861bf 100644
--- a/src/libtracker-data/tracker-data-backup.h
+++ b/src/libtracker-data/tracker-data-backup.h
@@ -48,7 +48,8 @@ void tracker_data_backup_save (GFile *destination,
TrackerDataBackupFinished callback,
gpointer user_data,
GDestroyNotify destroy);
-void tracker_data_backup_restore (GFile *journal,
+void tracker_data_backup_restore (TrackerDataManager *manager,
+ GFile *journal,
GFile *cache_location,
GFile *data_location,
GFile *ontology_location,
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 4ffcccd..a76c8f2 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -65,21 +65,37 @@
#define ZLIBBUFSIZ 8192
-static GFile *ontologies_dir = NULL;
-static GFile *ontology_location_stored = NULL;
-static GFile *cache_location_stored = NULL;
-static GFile *data_location_stored = NULL;
-static gboolean initialized;
-static gboolean reloading = FALSE;
+struct _TrackerDataManager {
+ GObject parent_instance;
+
+ GFile *ontology_location;
+ GFile *cache_location;
+ GFile *data_location;
+ guint initialized : 1;
+ guint journal_check : 1;
+ guint restoring_backup : 1;
+ guint first_time_index : 1;
+ guint flags;
+
+ gint select_cache_size;
+ gint update_cache_size;
+
#ifndef DISABLE_JOURNAL
-static gboolean in_journal_replay;
-static TrackerDBJournal *journal_writer = NULL;
-static TrackerDBJournal *ontology_writer = NULL;
+ gboolean in_journal_replay;
+ TrackerDBJournal *journal_writer;
+ TrackerDBJournal *ontology_writer;
#endif
-static TrackerDBManager *db_manager = NULL;
-static TrackerOntologies *ontologies = NULL;
-static TrackerData *data_update = NULL;
+ TrackerDBManager *db_manager;
+ TrackerOntologies *ontologies;
+ TrackerData *data_update;
+
+ gchar *status;
+};
+
+struct _TrackerDataManagerClass {
+ GObjectClass parent_instance;
+};
typedef struct {
const gchar *from;
@@ -113,6 +129,22 @@ static Conversion allowed_range_conversions[] = {
{ NULL, NULL }
};
+enum {
+ PROP_0,
+ PROP_STATUS,
+ N_PROPS
+};
+
+static void tracker_data_manager_initable_iface_init (GInitableIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (TrackerDataManager, tracker_data_manager, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, tracker_data_manager_initable_iface_init))
+
+static void
+tracker_data_manager_init (TrackerDataManager *manager)
+{
+}
+
GQuark
tracker_data_ontology_error_quark (void)
{
@@ -120,16 +152,17 @@ tracker_data_ontology_error_quark (void)
}
static void
-handle_unsupported_ontology_change (const gchar *ontology_path,
- const gchar *subject,
- const gchar *change,
- const gchar *old,
- const gchar *attempted_new,
- GError **error)
+handle_unsupported_ontology_change (TrackerDataManager *manager,
+ const gchar *ontology_path,
+ const gchar *subject,
+ const gchar *change,
+ const gchar *old,
+ const gchar *attempted_new,
+ GError **error)
{
#ifndef DISABLE_JOURNAL
/* force reindex on restart */
- tracker_db_manager_remove_version_file (db_manager);
+ tracker_db_manager_remove_version_file (manager->db_manager);
#endif /* DISABLE_JOURNAL */
g_set_error (error, TRACKER_DATA_ONTOLOGY_ERROR,
@@ -353,11 +386,12 @@ is_allowed_conversion (const gchar *oldv,
}
static gboolean
-check_unsupported_property_value_change (const gchar *ontology_path,
- const gchar *kind,
- const gchar *subject,
- const gchar *predicate,
- const gchar *object)
+check_unsupported_property_value_change (TrackerDataManager *manager,
+ const gchar *ontology_path,
+ const gchar *kind,
+ const gchar *subject,
+ const gchar *predicate,
+ const gchar *object)
{
GError *error = NULL;
gboolean needed = TRUE;
@@ -368,7 +402,7 @@ check_unsupported_property_value_change (const gchar *ontology_path,
"<%s> %s ?old_value "
"}", subject, kind);
- cursor = tracker_data_query_sparql_cursor (query, &error);
+ cursor = tracker_data_query_sparql_cursor (manager, query, &error);
if (cursor && tracker_db_cursor_iter_next (cursor, NULL, NULL)) {
if (g_strcmp0 (object, tracker_db_cursor_get_string (cursor, 0, NULL)) == 0) {
@@ -399,15 +433,16 @@ check_unsupported_property_value_change (const gchar *ontology_path,
}
static gboolean
-update_property_value (const gchar *ontology_path,
- const gchar *kind,
- const gchar *subject,
- const gchar *predicate,
- const gchar *object,
- Conversion allowed[],
- TrackerClass *class,
- TrackerProperty *property,
- GError **error_in)
+update_property_value (TrackerDataManager *manager,
+ const gchar *ontology_path,
+ const gchar *kind,
+ const gchar *subject,
+ const gchar *predicate,
+ const gchar *object,
+ Conversion allowed[],
+ TrackerClass *class,
+ TrackerProperty *property,
+ GError **error_in)
{
GError *error = NULL;
gboolean needed = TRUE;
@@ -427,7 +462,7 @@ update_property_value (const gchar *ontology_path,
"<%s> %s ?old_value "
"}", subject, kind);
- cursor = tracker_data_query_sparql_cursor (query, &error);
+ cursor = tracker_data_query_sparql_cursor (manager, query, &error);
if (cursor && tracker_db_cursor_iter_next (cursor, NULL, NULL)) {
const gchar *str = NULL;
@@ -440,7 +475,8 @@ update_property_value (const gchar *ontology_path,
gboolean unsup_onto_err = FALSE;
if (allowed && !is_allowed_conversion (str, object, allowed)) {
- handle_unsupported_ontology_change (ontology_path,
+ handle_unsupported_ontology_change (manager,
+ ontology_path,
subject,
kind,
str,
@@ -451,9 +487,9 @@ update_property_value (const gchar *ontology_path,
}
if (!unsup_onto_err) {
- tracker_data_delete_statement (data_update, NULL, subject, predicate,
str, &error);
+ tracker_data_delete_statement (manager->data_update, NULL, subject,
predicate, str, &error);
if (!error)
- tracker_data_update_buffer_flush (data_update, &error);
+ tracker_data_update_buffer_flush (manager->data_update,
&error);
}
}
@@ -474,11 +510,11 @@ update_property_value (const gchar *ontology_path,
if (!error && needed && object) {
- tracker_data_insert_statement (data_update, NULL, subject,
+ tracker_data_insert_statement (manager->data_update, NULL, subject,
predicate, object,
&error);
if (!error)
- tracker_data_update_buffer_flush (data_update, &error);
+ tracker_data_update_buffer_flush (manager->data_update, &error);
}
if (error) {
@@ -490,11 +526,12 @@ update_property_value (const gchar *ontology_path,
}
static void
-check_range_conversion_is_allowed (const gchar *ontology_path,
- const gchar *subject,
- const gchar *predicate,
- const gchar *object,
- GError **error)
+check_range_conversion_is_allowed (TrackerDataManager *manager,
+ const gchar *ontology_path,
+ const gchar *subject,
+ const gchar *predicate,
+ const gchar *object,
+ GError **error)
{
TrackerDBCursor *cursor;
gchar *query;
@@ -503,7 +540,7 @@ check_range_conversion_is_allowed (const gchar *ontology_path,
"<%s> rdfs:range ?old_value "
"}", subject);
- cursor = tracker_data_query_sparql_cursor (query, NULL);
+ cursor = tracker_data_query_sparql_cursor (manager, query, NULL);
g_free (query);
@@ -514,7 +551,8 @@ check_range_conversion_is_allowed (const gchar *ontology_path,
if (g_strcmp0 (object, str) != 0) {
if (!is_allowed_conversion (str, object, allowed_range_conversions)) {
- handle_unsupported_ontology_change (ontology_path,
+ handle_unsupported_ontology_change (manager,
+ ontology_path,
subject,
"rdfs:range",
str,
@@ -530,9 +568,10 @@ check_range_conversion_is_allowed (const gchar *ontology_path,
}
static void
-fix_indexed (TrackerProperty *property,
- gboolean recreate,
- GError **error)
+fix_indexed (TrackerDataManager *manager,
+ TrackerProperty *property,
+ gboolean recreate,
+ GError **error)
{
GError *internal_error = NULL;
TrackerDBInterface *iface;
@@ -540,7 +579,7 @@ fix_indexed (TrackerProperty *property,
const gchar *service_name;
const gchar *field_name;
- iface = tracker_db_manager_get_db_interface (db_manager);
+ iface = tracker_db_manager_get_db_interface (manager->db_manager);
class = tracker_property_get_domain (property);
field_name = tracker_property_get_name (property);
@@ -586,23 +625,26 @@ fix_indexed (TrackerProperty *property,
static void
-tracker_data_ontology_load_statement (const gchar *ontology_path,
- gint subject_id,
- const gchar *subject,
- const gchar *predicate,
- const gchar *object,
- gint *max_id,
- gboolean in_update,
- GHashTable *classes,
- GHashTable *properties,
- GPtrArray *seen_classes,
- GPtrArray *seen_properties,
- GError **error)
+tracker_data_ontology_load_statement (TrackerDataManager *manager,
+ const gchar *ontology_path,
+ gint subject_id,
+ const gchar *subject,
+ const gchar *predicate,
+ const gchar *object,
+ gint *max_id,
+ gboolean in_update,
+ GHashTable *classes,
+ GHashTable *properties,
+ GPtrArray *seen_classes,
+ GPtrArray *seen_properties,
+ GError **error)
{
+ TrackerOntologies *ontologies = manager->ontologies;
+
if (g_strcmp0 (predicate, RDF_TYPE) == 0) {
if (g_strcmp0 (object, RDFS_CLASS) == 0) {
TrackerClass *class;
- class = tracker_ontologies_get_class_by_uri (ontologies, subject);
+ class = tracker_ontologies_get_class_by_uri (manager->ontologies, subject);
if (class != NULL) {
if (seen_classes)
@@ -623,12 +665,12 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
}
class = tracker_class_new (FALSE);
- tracker_class_set_ontologies (class, ontologies);
+ tracker_class_set_ontologies (class, manager->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 (ontologies, class);
- tracker_ontologies_add_id_uri_pair (ontologies, subject_id, subject);
+ tracker_ontologies_add_class (manager->ontologies, class);
+ tracker_ontologies_add_id_uri_pair (manager->ontologies, subject_id, subject);
if (seen_classes)
g_ptr_array_add (seen_classes, g_object_ref (class));
@@ -642,7 +684,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 (ontologies, subject);
+ property = tracker_ontologies_get_property_by_uri (manager->ontologies, subject);
if (property != NULL) {
if (seen_properties)
g_ptr_array_add (seen_properties, g_object_ref (property));
@@ -670,13 +712,13 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
}
property = tracker_property_new (FALSE);
- tracker_property_set_ontologies (property, ontologies);
+ tracker_property_set_ontologies (property, manager->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 (ontologies, property);
- tracker_ontologies_add_id_uri_pair (ontologies, subject_id, subject);
+ tracker_ontologies_add_property (manager->ontologies, property);
+ tracker_ontologies_add_id_uri_pair (manager->ontologies, subject_id, subject);
if (seen_properties)
g_ptr_array_add (seen_properties, g_object_ref (property));
@@ -690,7 +732,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 (ontologies, subject);
+ property = tracker_ontologies_get_property_by_uri (manager->ontologies, subject);
if (property == NULL) {
g_critical ("%s: Unknown property %s", ontology_path, subject);
return;
@@ -700,33 +742,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 (ontologies, subject) != NULL) {
+ if (tracker_ontologies_get_namespace_by_uri (manager->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_ontologies (namespace, manager->ontologies);
tracker_namespace_set_is_new (namespace, in_update);
tracker_namespace_set_uri (namespace, subject);
- tracker_ontologies_add_namespace (ontologies, namespace);
+ tracker_ontologies_add_namespace (manager->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 (ontologies, subject) != NULL) {
+ if (tracker_ontologies_get_ontology_by_uri (manager->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_ontologies (ontology, manager->ontologies);
tracker_ontology_set_is_new (ontology, in_update);
tracker_ontology_set_uri (ontology, subject);
- tracker_ontologies_add_ontology (ontologies, ontology);
+ tracker_ontologies_add_ontology (manager->ontologies, ontology);
g_object_unref (ontology);
}
@@ -734,7 +776,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
TrackerClass *class, *super_class;
gboolean is_new;
- class = tracker_ontologies_get_class_by_uri (ontologies, subject);
+ class = tracker_ontologies_get_class_by_uri (manager->ontologies, subject);
if (class == NULL) {
g_critical ("%s: Unknown class %s", ontology_path, subject);
return;
@@ -748,7 +790,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 (ontologies, object);
+ super_class = tracker_ontologies_get_class_by_uri (manager->ontologies,
object);
if (super_class == NULL) {
g_critical ("%s: Unknown class %s", ontology_path, object);
return;
@@ -781,7 +823,8 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
if (!ignore && !had) {
- handle_unsupported_ontology_change (ontology_path,
+ handle_unsupported_ontology_change (manager,
+ ontology_path,
tracker_class_get_name (class),
"rdfs:subClassOf",
"-",
@@ -791,14 +834,14 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
}
if (!ignore) {
- super_class = tracker_ontologies_get_class_by_uri (ontologies, object);
+ super_class = tracker_ontologies_get_class_by_uri (manager->ontologies,
object);
tracker_class_add_super_class (class, super_class);
}
return;
}
- super_class = tracker_ontologies_get_class_by_uri (ontologies, object);
+ super_class = tracker_ontologies_get_class_by_uri (manager->ontologies, object);
if (super_class == NULL) {
g_critical ("%s: Unknown class %s", ontology_path, object);
return;
@@ -809,7 +852,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 (ontologies, subject);
+ class = tracker_ontologies_get_class_by_uri (manager->ontologies, subject);
if (class == NULL) {
g_critical ("%s: Unknown class %s", ontology_path, subject);
@@ -825,14 +868,14 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
gboolean had = FALSE;
guint n_props, i;
- class = tracker_ontologies_get_class_by_uri (ontologies, subject);
+ class = tracker_ontologies_get_class_by_uri (manager->ontologies, subject);
if (class == NULL) {
g_critical ("%s: Unknown class %s", ontology_path, subject);
return;
}
- property = tracker_ontologies_get_property_by_uri (ontologies, object);
+ property = tracker_ontologies_get_property_by_uri (manager->ontologies, object);
if (property == NULL) {
@@ -861,7 +904,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
return;
}
- properties = tracker_ontologies_get_properties (ontologies, &n_props);
+ properties = tracker_ontologies_get_properties (manager->ontologies, &n_props);
for (i = 0; i < n_props; i++) {
if (tracker_property_get_domain (properties[i]) == class &&
properties[i] == property) {
@@ -906,7 +949,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 (ontologies, subject);
+ property = tracker_ontologies_get_property_by_uri (manager->ontologies, subject);
if (property == NULL) {
g_critical ("%s: Unknown property %s", ontology_path, subject);
@@ -917,7 +960,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 (ontologies, subject);
+ property = tracker_ontologies_get_property_by_uri (manager->ontologies, subject);
if (property == NULL) {
g_critical ("%s: Unknown property %s", ontology_path, subject);
@@ -929,7 +972,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
TrackerProperty *property, *super_property;
gboolean is_new;
- property = tracker_ontologies_get_property_by_uri (ontologies, subject);
+ property = tracker_ontologies_get_property_by_uri (manager->ontologies, subject);
if (property == NULL) {
g_critical ("%s: Unknown property %s", ontology_path, subject);
return;
@@ -943,7 +986,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 (ontologies, object);
+ super_property = tracker_ontologies_get_property_by_uri (manager->ontologies,
object);
if (super_property == NULL) {
g_critical ("%s: Unknown property %s", ontology_path, object);
return;
@@ -975,7 +1018,8 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
* tracker_data_ontology_process_changes_pre_db stuff */
if (!ignore && !had) {
- handle_unsupported_ontology_change (ontology_path,
+ handle_unsupported_ontology_change (manager,
+ ontology_path,
tracker_property_get_name
(property),
"rdfs:subPropertyOf",
"-",
@@ -985,14 +1029,14 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
}
if (!ignore) {
- super_property = tracker_ontologies_get_property_by_uri (ontologies, object);
+ super_property = tracker_ontologies_get_property_by_uri (manager->ontologies,
object);
tracker_property_add_super_property (property, super_property);
}
return;
}
- super_property = tracker_ontologies_get_property_by_uri (ontologies, object);
+ super_property = tracker_ontologies_get_property_by_uri (manager->ontologies, object);
if (super_property == NULL) {
g_critical ("%s: Unknown property %s", ontology_path, object);
return;
@@ -1004,13 +1048,13 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
TrackerClass *domain;
gboolean is_new;
- property = tracker_ontologies_get_property_by_uri (ontologies, subject);
+ property = tracker_ontologies_get_property_by_uri (manager->ontologies, subject);
if (property == NULL) {
g_critical ("%s: Unknown property %s", ontology_path, subject);
return;
}
- domain = tracker_ontologies_get_class_by_uri (ontologies, object);
+ domain = tracker_ontologies_get_class_by_uri (manager->ontologies, object);
if (domain == NULL) {
g_critical ("%s: Unknown class %s", ontology_path, object);
return;
@@ -1022,7 +1066,8 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
if (in_update == TRUE && is_new == FALSE) {
TrackerClass *old_domain = tracker_property_get_domain (property);
if (old_domain != domain) {
- handle_unsupported_ontology_change (ontology_path,
+ handle_unsupported_ontology_change (manager,
+ ontology_path,
tracker_property_get_name
(property),
"rdfs:domain",
tracker_class_get_name
(old_domain),
@@ -1038,7 +1083,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
TrackerProperty *property;
TrackerClass *range;
- property = tracker_ontologies_get_property_by_uri (ontologies, subject);
+ property = tracker_ontologies_get_property_by_uri (manager->ontologies, subject);
if (property == NULL) {
g_critical ("%s: Unknown property %s", ontology_path, subject);
return;
@@ -1046,7 +1091,8 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
if (tracker_property_get_is_new (property) != in_update) {
GError *err = NULL;
- check_range_conversion_is_allowed (ontology_path,
+ check_range_conversion_is_allowed (manager,
+ ontology_path,
subject,
predicate,
object,
@@ -1057,7 +1103,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
}
}
- range = tracker_ontologies_get_class_by_uri (ontologies, object);
+ range = tracker_ontologies_get_class_by_uri (manager->ontologies, object);
if (range == NULL) {
g_critical ("%s: Unknown class %s", ontology_path, object);
return;
@@ -1067,7 +1113,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 (ontologies, subject);
+ property = tracker_ontologies_get_property_by_uri (manager->ontologies, subject);
if (property == NULL) {
g_critical ("%s: Unknown property %s", ontology_path, subject);
return;
@@ -1084,7 +1130,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 (ontologies, subject);
+ property = tracker_ontologies_get_property_by_uri (manager->ontologies, subject);
if (property == NULL) {
g_critical ("%s: Unknown property %s", ontology_path, subject);
return;
@@ -1094,13 +1140,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 (ontologies, subject);
+ property = tracker_ontologies_get_property_by_uri (manager->ontologies, subject);
if (property == NULL) {
g_critical ("%s: Unknown property %s", ontology_path, subject);
return;
}
- secondary_index = tracker_ontologies_get_property_by_uri (ontologies, object);
+ secondary_index = tracker_ontologies_get_property_by_uri (manager->ontologies, object);
if (secondary_index == NULL) {
g_critical ("%s: Unknown property %s", ontology_path, object);
return;
@@ -1111,7 +1157,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
TrackerProperty *property;
gboolean is_new;
- property = tracker_ontologies_get_property_by_uri (ontologies, subject);
+ property = tracker_ontologies_get_property_by_uri (manager->ontologies, subject);
if (property == NULL) {
g_critical ("%s: Unknown property %s", ontology_path, subject);
return;
@@ -1124,12 +1170,14 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
* or creating the table in the-non memdisk db file, but afaik this
* isn't supported right now */
if (in_update == TRUE && is_new == FALSE) {
- if (check_unsupported_property_value_change (ontology_path,
+ if (check_unsupported_property_value_change (manager,
+ ontology_path,
"tracker:transient",
subject,
predicate,
object)) {
- handle_unsupported_ontology_change (ontology_path,
+ handle_unsupported_ontology_change (manager,
+ ontology_path,
tracker_property_get_name
(property),
"tracker:transient",
tracker_property_get_transient
(property) ? "true" : "false",
@@ -1146,7 +1194,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 (ontologies, subject);
+ property = tracker_ontologies_get_property_by_uri (manager->ontologies, subject);
if (property == NULL) {
g_critical ("%s: Unknown property %s", ontology_path, subject);
return;
@@ -1157,7 +1205,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 (ontologies, subject);
+ property = tracker_ontologies_get_property_by_uri (manager->ontologies, subject);
if (property == NULL) {
g_critical ("%s: Unknown property %s", ontology_path, subject);
return;
@@ -1167,7 +1215,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 (ontologies, subject);
+ namespace = tracker_ontologies_get_namespace_by_uri (manager->ontologies, subject);
if (namespace == NULL) {
g_critical ("%s: Unknown namespace %s", ontology_path, subject);
return;
@@ -1181,7 +1229,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 (ontologies, subject);
+ ontology = tracker_ontologies_get_ontology_by_uri (manager->ontologies, subject);
if (ontology == NULL) {
g_critical ("%s: Unknown ontology %s", ontology_path, subject);
return;
@@ -1197,7 +1245,8 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
static void
-check_for_deleted_domain_index (TrackerClass *class)
+check_for_deleted_domain_index (TrackerDataManager *manager,
+ TrackerClass *class)
{
TrackerProperty **last_domain_indexes;
GSList *hfound = NULL, *deleted = NULL;
@@ -1240,7 +1289,7 @@ check_for_deleted_domain_index (TrackerClass *class)
tracker_class_set_db_schema_changed (class, TRUE);
- properties = tracker_ontologies_get_properties (ontologies, &n_props);
+ properties = tracker_ontologies_get_properties (manager->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])) {
@@ -1269,7 +1318,7 @@ check_for_deleted_domain_index (TrackerClass *class)
tracker_property_del_domain_index (prop, class);
tracker_class_del_domain_index (class, prop);
- tracker_data_delete_statement (data_update, NULL,
+ tracker_data_delete_statement (manager->data_update, NULL,
tracker_class_get_uri (class),
TRACKER_PREFIX_TRACKER "domainIndex",
tracker_property_get_uri (prop),
@@ -1279,7 +1328,7 @@ check_for_deleted_domain_index (TrackerClass *class)
g_critical ("Ontology change, %s", error->message);
g_clear_error (&error);
} else {
- tracker_data_update_buffer_flush (data_update, &error);
+ tracker_data_update_buffer_flush (manager->data_update, &error);
if (error) {
g_critical ("Ontology change, %s", error->message);
g_clear_error (&error);
@@ -1294,8 +1343,9 @@ check_for_deleted_domain_index (TrackerClass *class)
}
static void
-check_for_deleted_super_classes (TrackerClass *class,
- GError **error)
+check_for_deleted_super_classes (TrackerDataManager *manager,
+ TrackerClass *class,
+ GError **error)
{
TrackerClass **last_super_classes;
@@ -1331,7 +1381,8 @@ check_for_deleted_super_classes (TrackerClass *class,
const gchar *ontology_path = "Unknown";
const gchar *subject = tracker_class_get_uri (class);
- handle_unsupported_ontology_change (ontology_path,
+ handle_unsupported_ontology_change (manager,
+ ontology_path,
subject,
"rdfs:subClassOf", "-", "-",
error);
@@ -1343,8 +1394,9 @@ check_for_deleted_super_classes (TrackerClass *class,
}
static void
-check_for_max_cardinality_change (TrackerProperty *property,
- GError **error)
+check_for_max_cardinality_change (TrackerDataManager *manager,
+ TrackerProperty *property,
+ GError **error)
{
gboolean orig_multiple_values = tracker_property_get_orig_multiple_values (property);
gboolean new_multiple_values = tracker_property_get_multiple_values (property);
@@ -1357,7 +1409,8 @@ check_for_max_cardinality_change (TrackerProperty *property,
const gchar *ontology_path = "Unknown";
const gchar *subject = tracker_property_get_uri (property);
- handle_unsupported_ontology_change (ontology_path,
+ handle_unsupported_ontology_change (manager,
+ ontology_path,
subject,
"nrl:maxCardinality", "none", "1",
&n_error);
@@ -1370,7 +1423,7 @@ check_for_max_cardinality_change (TrackerProperty *property,
orig_multiple_values == FALSE) {
const gchar *subject = tracker_property_get_uri (property);
- if (update_property_value (ontology_path,
+ if (update_property_value (manager, ontology_path,
"nrl:maxCardinality",
subject,
TRACKER_PREFIX_NRL "maxCardinality",
@@ -1393,8 +1446,9 @@ check_for_max_cardinality_change (TrackerProperty *property,
}
static void
-check_for_deleted_super_properties (TrackerProperty *property,
- GError **error)
+check_for_deleted_super_properties (TrackerDataManager *manager,
+ TrackerProperty *property,
+ GError **error)
{
TrackerProperty **last_super_properties;
GList *to_remove = NULL;
@@ -1440,12 +1494,12 @@ check_for_deleted_super_properties (TrackerProperty *property,
tracker_property_del_super_property (property, prop_to_remove);
- tracker_data_delete_statement (data_update, NULL, subject,
+ tracker_data_delete_statement (manager->data_update, NULL, subject,
TRACKER_PREFIX_RDFS "subPropertyOf",
object, &n_error);
if (!n_error) {
- tracker_data_update_buffer_flush (data_update, &n_error);
+ tracker_data_update_buffer_flush (manager->data_update, &n_error);
}
if (n_error) {
@@ -1460,9 +1514,10 @@ check_for_deleted_super_properties (TrackerProperty *property,
}
static void
-tracker_data_ontology_process_changes_pre_db (GPtrArray *seen_classes,
- GPtrArray *seen_properties,
- GError **error)
+tracker_data_ontology_process_changes_pre_db (TrackerDataManager *manager,
+ GPtrArray *seen_classes,
+ GPtrArray *seen_properties,
+ GError **error)
{
gint i;
if (seen_classes) {
@@ -1470,8 +1525,8 @@ tracker_data_ontology_process_changes_pre_db (GPtrArray *seen_classes,
GError *n_error = NULL;
TrackerClass *class = g_ptr_array_index (seen_classes, i);
- check_for_deleted_domain_index (class);
- check_for_deleted_super_classes (class, &n_error);
+ check_for_deleted_domain_index (manager, class);
+ check_for_deleted_super_classes (manager, class, &n_error);
if (n_error) {
g_propagate_error (error, n_error);
@@ -1485,14 +1540,14 @@ tracker_data_ontology_process_changes_pre_db (GPtrArray *seen_classes,
GError *n_error = NULL;
TrackerProperty *property = g_ptr_array_index (seen_properties, i);
- check_for_max_cardinality_change (property, &n_error);
+ check_for_max_cardinality_change (manager, property, &n_error);
if (n_error) {
g_propagate_error (error, n_error);
return;
}
- check_for_deleted_super_properties (property, &n_error);
+ check_for_deleted_super_properties (manager, property, &n_error);
if (n_error) {
g_propagate_error (error, n_error);
@@ -1503,9 +1558,10 @@ tracker_data_ontology_process_changes_pre_db (GPtrArray *seen_classes,
}
static void
-tracker_data_ontology_process_changes_post_db (GPtrArray *seen_classes,
- GPtrArray *seen_properties,
- GError **error)
+tracker_data_ontology_process_changes_post_db (TrackerDataManager *manager,
+ GPtrArray *seen_classes,
+ GPtrArray *seen_properties,
+ GError **error)
{
gint i;
/* TODO: Collect the ontology-paths of the seen events for proper error reporting */
@@ -1524,14 +1580,14 @@ tracker_data_ontology_process_changes_post_db (GPtrArray *seen_classes,
subject = tracker_class_get_uri (class);
if (tracker_class_get_notify (class)) {
- update_property_value (ontology_path,
+ update_property_value (manager, ontology_path,
"tracker:notify",
subject,
TRACKER_PREFIX_TRACKER "notify",
"true", allowed_boolean_conversions,
class, NULL, &n_error);
} else {
- update_property_value (ontology_path,
+ update_property_value (manager, ontology_path,
"tracker:notify",
subject,
TRACKER_PREFIX_TRACKER "notify",
@@ -1562,7 +1618,7 @@ tracker_data_ontology_process_changes_post_db (GPtrArray *seen_classes,
in_onto = tracker_property_get_is_inverse_functional_property (property);
query = g_strdup_printf ("ASK { <%s> a nrl:InverseFunctionalProperty }", subject);
- cursor = TRACKER_SPARQL_CURSOR (tracker_data_query_sparql_cursor (query, &n_error));
+ cursor = TRACKER_SPARQL_CURSOR (tracker_data_query_sparql_cursor (manager, query,
&n_error));
g_free (query);
if (n_error) {
@@ -1572,7 +1628,8 @@ tracker_data_ontology_process_changes_post_db (GPtrArray *seen_classes,
if (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
if (tracker_sparql_cursor_get_boolean (cursor, 0) != in_onto) {
- handle_unsupported_ontology_change (ontology_path,
+ handle_unsupported_ontology_change (manager,
+ ontology_path,
subject,
"nrl:InverseFunctionalProperty",
"-", "-",
&n_error);
@@ -1591,14 +1648,14 @@ tracker_data_ontology_process_changes_post_db (GPtrArray *seen_classes,
/* Check for possibly supported changes */
if (tracker_property_get_writeback (property)) {
- update_property_value (ontology_path,
+ update_property_value (manager, ontology_path,
"tracker:writeback",
subject,
TRACKER_PREFIX_TRACKER "writeback",
"true", allowed_boolean_conversions,
NULL, property, &n_error);
} else {
- update_property_value (ontology_path,
+ update_property_value (manager, ontology_path,
"tracker:writeback",
subject,
TRACKER_PREFIX_TRACKER "writeback",
@@ -1612,23 +1669,23 @@ tracker_data_ontology_process_changes_post_db (GPtrArray *seen_classes,
}
if (tracker_property_get_indexed (property)) {
- if (update_property_value (ontology_path,
+ if (update_property_value (manager, ontology_path,
"tracker:indexed",
subject,
TRACKER_PREFIX_TRACKER "indexed",
"true", allowed_boolean_conversions,
NULL, property, &n_error)) {
- fix_indexed (property, TRUE, &n_error);
+ fix_indexed (manager, property, TRUE, &n_error);
indexed_set = TRUE;
}
} else {
- if (update_property_value (ontology_path,
+ if (update_property_value (manager, ontology_path,
"tracker:indexed",
subject,
TRACKER_PREFIX_TRACKER "indexed",
"false", allowed_boolean_conversions,
NULL, property, &n_error)) {
- fix_indexed (property, TRUE, &n_error);
+ fix_indexed (manager, property, TRUE, &n_error);
indexed_set = TRUE;
}
}
@@ -1641,25 +1698,25 @@ tracker_data_ontology_process_changes_post_db (GPtrArray *seen_classes,
secondary_index = tracker_property_get_secondary_index (property);
if (secondary_index) {
- if (update_property_value (ontology_path,
+ if (update_property_value (manager, ontology_path,
"tracker:secondaryIndex",
subject,
TRACKER_PREFIX_TRACKER "secondaryIndex",
tracker_property_get_uri (secondary_index), NULL,
NULL, property, &n_error)) {
if (!indexed_set) {
- fix_indexed (property, TRUE, &n_error);
+ fix_indexed (manager, property, TRUE, &n_error);
}
}
} else {
- if (update_property_value (ontology_path,
+ if (update_property_value (manager, ontology_path,
"tracker:secondaryIndex",
subject,
TRACKER_PREFIX_TRACKER "secondaryIndex",
NULL, NULL,
NULL, property, &n_error)) {
if (!indexed_set) {
- fix_indexed (property, TRUE, &n_error);
+ fix_indexed (manager, property, TRUE, &n_error);
}
}
}
@@ -1669,7 +1726,7 @@ tracker_data_ontology_process_changes_post_db (GPtrArray *seen_classes,
return;
}
- if (update_property_value (ontology_path,
+ if (update_property_value (manager, ontology_path,
"rdfs:range", subject, TRACKER_PREFIX_RDFS "range",
tracker_class_get_uri (tracker_property_get_range
(property)),
allowed_range_conversions,
@@ -1686,7 +1743,7 @@ tracker_data_ontology_process_changes_post_db (GPtrArray *seen_classes,
return;
}
- if (update_property_value (ontology_path,
+ if (update_property_value (manager, ontology_path,
"tracker:defaultValue", subject, TRACKER_PREFIX_TRACKER
"defaultValue",
tracker_property_get_default_value (property),
NULL, NULL, property, &n_error)) {
@@ -1721,13 +1778,14 @@ tracker_data_ontology_free_seen (GPtrArray *seen)
}
static void
-load_ontology_file (GFile *file,
- gint *max_id,
- gboolean in_update,
- GPtrArray *seen_classes,
- GPtrArray *seen_properties,
- GHashTable *uri_id_map,
- GError **error)
+load_ontology_file (TrackerDataManager *manager,
+ GFile *file,
+ gint *max_id,
+ gboolean in_update,
+ GPtrArray *seen_classes,
+ GPtrArray *seen_properties,
+ GHashTable *uri_id_map,
+ GError **error)
{
TrackerTurtleReader *reader;
GError *ttl_error = NULL;
@@ -1758,7 +1816,8 @@ load_ontology_file (GFile *file,
subject_id = GPOINTER_TO_INT (g_hash_table_lookup (uri_id_map, subject));
}
- tracker_data_ontology_load_statement (ontology_uri, subject_id, subject, predicate, object,
+ tracker_data_ontology_load_statement (manager, ontology_uri,
+ subject_id, subject, predicate, object,
max_id, in_update, NULL, NULL,
seen_classes, seen_properties, &ontology_error);
@@ -1778,7 +1837,8 @@ load_ontology_file (GFile *file,
static TrackerOntology*
-get_ontology_from_file (GFile *file)
+get_ontology_from_file (TrackerDataManager *manager,
+ GFile *file)
{
TrackerTurtleReader *reader;
GError *error = NULL;
@@ -1810,7 +1870,7 @@ get_ontology_from_file (GFile *file)
TrackerOntology *ontology;
ontology = tracker_ontology_new ();
- tracker_ontology_set_ontologies (ontology, ontologies);
+ tracker_ontology_set_ontologies (ontology, manager->ontologies);
tracker_ontology_set_uri (ontology, subject);
/* Passes ownership */
@@ -1888,13 +1948,14 @@ load_ontology_ids_from_journal (TrackerDBJournalReader *reader,
#endif /* DISABLE_JOURNAL */
static void
-tracker_data_ontology_process_statement (const gchar *graph,
- const gchar *subject,
- const gchar *predicate,
- const gchar *object,
- gboolean is_uri,
- gboolean in_update,
- gboolean ignore_nao_last_modified)
+tracker_data_ontology_process_statement (TrackerDataManager *manager,
+ const gchar *graph,
+ const gchar *subject,
+ const gchar *predicate,
+ const gchar *object,
+ gboolean is_uri,
+ gboolean in_update,
+ gboolean ignore_nao_last_modified)
{
GError *error = NULL;
@@ -1902,7 +1963,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 (ontologies, subject);
+ class = tracker_ontologies_get_class_by_uri (manager->ontologies, subject);
if (class && tracker_class_get_is_new (class) != in_update) {
return;
@@ -1910,7 +1971,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 (ontologies, subject);
+ prop = tracker_ontologies_get_property_by_uri (manager->ontologies, subject);
if (prop && tracker_property_get_is_new (prop) != in_update) {
return;
@@ -1918,7 +1979,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 (ontologies, subject);
+ namespace = tracker_ontologies_get_namespace_by_uri (manager->ontologies, subject);
if (namespace && tracker_namespace_get_is_new (namespace) != in_update) {
return;
@@ -1926,7 +1987,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 (ontologies, subject);
+ ontology = tracker_ontologies_get_ontology_by_uri (manager->ontologies, subject);
if (ontology && tracker_ontology_get_is_new (ontology) != in_update) {
return;
@@ -1935,7 +1996,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 (ontologies, subject);
+ class = tracker_ontologies_get_class_by_uri (manager->ontologies, subject);
if (class && tracker_class_get_is_new (class) != in_update) {
return;
@@ -1949,7 +2010,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 (ontologies, subject);
+ prop = tracker_ontologies_get_property_by_uri (manager->ontologies, subject);
if (prop && tracker_property_get_is_new (prop) != in_update) {
return;
@@ -1957,7 +2018,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 (ontologies, subject);
+ namespace = tracker_ontologies_get_namespace_by_uri (manager->ontologies, subject);
if (namespace && tracker_namespace_get_is_new (namespace) != in_update) {
return;
@@ -1965,7 +2026,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 (ontologies, subject);
+ ontology = tracker_ontologies_get_ontology_by_uri (manager->ontologies, subject);
if (ontology && tracker_ontology_get_is_new (ontology) != in_update) {
return;
@@ -1977,7 +2038,7 @@ tracker_data_ontology_process_statement (const gchar *graph,
}
if (is_uri) {
- tracker_data_insert_statement_with_uri (data_update, graph, subject,
+ tracker_data_insert_statement_with_uri (manager->data_update, graph, subject,
predicate, object,
&error);
@@ -1988,7 +2049,7 @@ tracker_data_ontology_process_statement (const gchar *graph,
}
} else {
- tracker_data_insert_statement_with_string (data_update, graph, subject,
+ tracker_data_insert_statement_with_string (manager->data_update, graph, subject,
predicate, object,
&error);
@@ -2001,9 +2062,10 @@ tracker_data_ontology_process_statement (const gchar *graph,
}
static void
-import_ontology_file (GFile *file,
- gboolean in_update,
- gboolean ignore_nao_last_modified)
+import_ontology_file (TrackerDataManager *manager,
+ GFile *file,
+ gboolean in_update,
+ gboolean ignore_nao_last_modified)
{
GError *error = NULL;
TrackerTurtleReader* reader;
@@ -2023,7 +2085,8 @@ import_ontology_file (GFile *file,
const gchar *predicate = tracker_turtle_reader_get_predicate (reader);
const gchar *object = tracker_turtle_reader_get_object (reader);
- tracker_data_ontology_process_statement (graph, subject, predicate, object,
+ tracker_data_ontology_process_statement (manager,
+ graph, subject, predicate, object,
tracker_turtle_reader_get_object_is_uri (reader),
in_update, ignore_nao_last_modified);
@@ -2039,6 +2102,7 @@ import_ontology_file (GFile *file,
static void
class_add_super_classes_from_db (TrackerDBInterface *iface,
+ TrackerDataManager *manager,
TrackerClass *class)
{
TrackerDBStatement *stmt;
@@ -2066,7 +2130,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 (ontologies, super_class_uri);
+ super_class = tracker_ontologies_get_class_by_uri (manager->ontologies,
super_class_uri);
tracker_class_add_super_class (class, super_class);
}
@@ -2077,6 +2141,7 @@ class_add_super_classes_from_db (TrackerDBInterface *iface,
static void
class_add_domain_indexes_from_db (TrackerDBInterface *iface,
+ TrackerDataManager *manager,
TrackerClass *class)
{
TrackerDBStatement *stmt;
@@ -2104,7 +2169,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 (ontologies, domain_index_uri);
+ domain_index = tracker_ontologies_get_property_by_uri (manager->ontologies,
domain_index_uri);
tracker_class_add_domain_index (class, domain_index);
tracker_property_add_domain_index (domain_index, class);
}
@@ -2115,7 +2180,8 @@ class_add_domain_indexes_from_db (TrackerDBInterface *iface,
static void
property_add_super_properties_from_db (TrackerDBInterface *iface,
- TrackerProperty *property)
+ TrackerDataManager *manager,
+ TrackerProperty *property)
{
TrackerDBStatement *stmt;
TrackerDBCursor *cursor;
@@ -2142,7 +2208,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 (ontologies,
super_property_uri);
+ super_property = tracker_ontologies_get_property_by_uri (manager->ontologies,
super_property_uri);
tracker_property_add_super_property (property, super_property);
}
@@ -2152,6 +2218,7 @@ property_add_super_properties_from_db (TrackerDBInterface *iface,
static void
db_get_static_data (TrackerDBInterface *iface,
+ TrackerDataManager *manager,
GError **error)
{
TrackerDBStatement *stmt;
@@ -2177,7 +2244,7 @@ db_get_static_data (TrackerDBInterface *iface,
time_t last_mod;
ontology = tracker_ontology_new ();
- tracker_ontology_set_ontologies (ontology, ontologies);
+ tracker_ontology_set_ontologies (ontology, manager->ontologies);
uri = tracker_db_cursor_get_string (cursor, 0, NULL);
last_mod = (time_t) tracker_db_cursor_get_int (cursor, 1);
@@ -2185,7 +2252,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 (ontologies, ontology);
+ tracker_ontologies_add_ontology (manager->ontologies, ontology);
g_object_unref (ontology);
}
@@ -2219,11 +2286,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_ontologies (namespace, manager->ontologies);
tracker_namespace_set_is_new (namespace, FALSE);
tracker_namespace_set_uri (namespace, uri);
tracker_namespace_set_prefix (namespace, prefix);
- tracker_ontologies_add_namespace (ontologies, namespace);
+ tracker_ontologies_add_namespace (manager->ontologies, namespace);
g_object_unref (namespace);
@@ -2272,19 +2339,18 @@ db_get_static_data (TrackerDBInterface *iface,
notify = FALSE;
}
- tracker_class_set_ontologies (class, ontologies);
+ tracker_class_set_ontologies (class, manager->ontologies);
tracker_class_set_db_schema_changed (class, FALSE);
tracker_class_set_is_new (class, FALSE);
tracker_class_set_uri (class, uri);
tracker_class_set_notify (class, notify);
- class_add_super_classes_from_db (iface, class);
+ class_add_super_classes_from_db (iface, manager, class);
- /* We do this later, we first need to load the properties too
- class_add_domain_indexes_from_db (iface, class); */
+ /* We add domain indexes later , we first need to load the properties */
- tracker_ontologies_add_class (ontologies, class);
- tracker_ontologies_add_id_uri_pair (ontologies, id, uri);
+ tracker_ontologies_add_class (manager->ontologies, class);
+ tracker_ontologies_add_id_uri_pair (manager->ontologies, id, uri);
tracker_class_set_id (class, id);
g_object_unref (class);
@@ -2415,15 +2481,15 @@ db_get_static_data (TrackerDBInterface *iface,
default_value = tracker_db_cursor_get_string (cursor, 12, NULL);
- 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_ontologies (property, manager->ontologies);
+ tracker_property_set_is_new_domain_index (property,
tracker_ontologies_get_class_by_uri (manager->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
(ontologies, domain_uri));
- tracker_property_set_range (property, tracker_ontologies_get_class_by_uri
(ontologies, range_uri));
+ tracker_property_set_domain (property, tracker_ontologies_get_class_by_uri
(manager->ontologies, domain_uri));
+ tracker_property_set_range (property, tracker_ontologies_get_class_by_uri
(manager->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);
@@ -2434,7 +2500,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 (ontologies, secondary_index_uri));
+ tracker_property_set_secondary_index (property,
tracker_ontologies_get_property_by_uri (manager->ontologies, secondary_index_uri));
}
tracker_property_set_orig_fulltext_indexed (property, fulltext_indexed);
@@ -2442,12 +2508,12 @@ db_get_static_data (TrackerDBInterface *iface,
tracker_property_set_is_inverse_functional_property (property,
is_inverse_functional_property);
/* super properties are only used in updates, never for queries */
- if ((tracker_db_manager_get_flags (db_manager, NULL, NULL) &
TRACKER_DB_MANAGER_READONLY) == 0) {
- property_add_super_properties_from_db (iface, property);
+ if ((tracker_db_manager_get_flags (manager->db_manager, NULL, NULL) &
TRACKER_DB_MANAGER_READONLY) == 0) {
+ property_add_super_properties_from_db (iface, manager, property);
}
- tracker_ontologies_add_property (ontologies, property);
- tracker_ontologies_add_id_uri_pair (ontologies, id, uri);
+ tracker_ontologies_add_property (manager->ontologies, property);
+ tracker_ontologies_add_id_uri_pair (manager->ontologies, id, uri);
g_object_unref (property);
@@ -2458,9 +2524,9 @@ db_get_static_data (TrackerDBInterface *iface,
}
/* Now that the properties are loaded we can do this foreach class */
- classes = tracker_ontologies_get_classes (ontologies, &n_classes);
+ classes = tracker_ontologies_get_classes (manager->ontologies, &n_classes);
for (i = 0; i < n_classes; i++) {
- class_add_domain_indexes_from_db (iface, classes[i]);
+ class_add_domain_indexes_from_db (iface, manager, classes[i]);
}
if (internal_error) {
@@ -2470,7 +2536,8 @@ db_get_static_data (TrackerDBInterface *iface,
}
static void
-insert_uri_in_resource_table (TrackerDBInterface *iface,
+insert_uri_in_resource_table (TrackerDataManager *manager,
+ TrackerDBInterface *iface,
const gchar *uri,
gint id,
GError **error)
@@ -2500,8 +2567,8 @@ insert_uri_in_resource_table (TrackerDBInterface *iface,
}
#ifndef DISABLE_JOURNAL
- if (!in_journal_replay) {
- tracker_db_journal_append_resource (ontology_writer, id, uri);
+ if (!manager->in_journal_replay) {
+ tracker_db_journal_append_resource (manager->ontology_writer, id, uri);
}
#endif /* DISABLE_JOURNAL */
@@ -2834,7 +2901,8 @@ schedule_copy (GPtrArray *schedule,
}
static void
-create_decomposed_metadata_tables (TrackerDBInterface *iface,
+create_decomposed_metadata_tables (TrackerDataManager *manager,
+ TrackerDBInterface *iface,
TrackerClass *service,
gboolean in_update,
gboolean in_change,
@@ -2894,7 +2962,7 @@ create_decomposed_metadata_tables (TrackerDBInterface *iface,
}
}
- properties = tracker_ontologies_get_properties (ontologies, &n_props);
+ properties = tracker_ontologies_get_properties (manager->ontologies, &n_props);
domain_indexes = tracker_class_get_domain_indexes (service);
for (i = 0; i < n_props; i++) {
@@ -3288,13 +3356,14 @@ error_out:
}
static void
-clean_decomposed_transient_metadata (TrackerDBInterface *iface)
+clean_decomposed_transient_metadata (TrackerDataManager *manager,
+ TrackerDBInterface *iface)
{
TrackerProperty **properties;
TrackerProperty *property;
guint i, n_props;
- properties = tracker_ontologies_get_properties (ontologies, &n_props);
+ properties = tracker_ontologies_get_properties (manager->ontologies, &n_props);
for (i = 0; i < n_props; i++) {
property = properties[i];
@@ -3333,14 +3402,14 @@ clean_decomposed_transient_metadata (TrackerDBInterface *iface)
}
static void
-tracker_data_ontology_import_finished (void)
+tracker_data_ontology_import_finished (TrackerDataManager *manager)
{
TrackerClass **classes;
TrackerProperty **properties;
guint i, n_props, n_classes;
- classes = tracker_ontologies_get_classes (ontologies, &n_classes);
- properties = tracker_ontologies_get_properties (ontologies, &n_props);
+ classes = tracker_ontologies_get_classes (manager->ontologies, &n_classes);
+ properties = tracker_ontologies_get_properties (manager->ontologies, &n_props);
for (i = 0; i < n_classes; i++) {
tracker_class_set_is_new (classes[i], FALSE);
@@ -3356,8 +3425,9 @@ tracker_data_ontology_import_finished (void)
}
static void
-tracker_data_ontology_import_into_db (gboolean in_update,
- GError **error)
+tracker_data_ontology_import_into_db (TrackerDataManager *manager,
+ gboolean in_update,
+ GError **error)
{
TrackerDBInterface *iface;
@@ -3365,17 +3435,17 @@ tracker_data_ontology_import_into_db (gboolean in_update,
TrackerProperty **properties;
guint i, n_props, n_classes;
- iface = tracker_db_manager_get_db_interface (db_manager);
+ iface = tracker_db_manager_get_db_interface (manager->db_manager);
- classes = tracker_ontologies_get_classes (ontologies, &n_classes);
- properties = tracker_ontologies_get_properties (ontologies, &n_props);
+ classes = tracker_ontologies_get_classes (manager->ontologies, &n_classes);
+ properties = tracker_ontologies_get_properties (manager->ontologies, &n_props);
/* create tables */
for (i = 0; i < n_classes; i++) {
GError *internal_error = NULL;
/* Also !is_new classes are processed, they might have new properties */
- create_decomposed_metadata_tables (iface, classes[i], in_update,
+ create_decomposed_metadata_tables (manager, iface, classes[i], in_update,
tracker_class_get_db_schema_changed (classes[i]),
&internal_error);
@@ -3390,7 +3460,8 @@ tracker_data_ontology_import_into_db (gboolean in_update,
if (tracker_class_get_is_new (classes[i]) == in_update) {
GError *internal_error = NULL;
- insert_uri_in_resource_table (iface, tracker_class_get_uri (classes[i]),
+ insert_uri_in_resource_table (manager, iface,
+ tracker_class_get_uri (classes[i]),
tracker_class_get_id (classes[i]),
&internal_error);
@@ -3406,7 +3477,8 @@ tracker_data_ontology_import_into_db (gboolean in_update,
if (tracker_property_get_is_new (properties[i]) == in_update) {
GError *internal_error = NULL;
- insert_uri_in_resource_table (iface, tracker_property_get_uri (properties[i]),
+ insert_uri_in_resource_table (manager, iface,
+ tracker_property_get_uri (properties[i]),
tracker_property_get_id (properties[i]),
&internal_error);
@@ -3436,8 +3508,9 @@ compare_file_names (GFile *file_a,
}
static GList*
-get_ontologies (GFile *ontologies,
- GError **error)
+get_ontologies (TrackerDataManager *manager,
+ GFile *ontologies,
+ GError **error)
{
GFileEnumerator *enumerator;
GList *sorted = NULL;
@@ -3493,9 +3566,6 @@ get_new_service_id (TrackerDBInterface *iface)
/* Don't intermix this thing with tracker_data_update_get_new_service_id,
* if you use this, know what you are doing! */
-
- iface = tracker_db_manager_get_db_interface (db_manager);
-
stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
"SELECT MAX(ID) AS A FROM Resource WHERE ID <= %d",
TRACKER_ONTOLOGIES_MAX_ID);
@@ -3519,17 +3589,33 @@ get_new_service_id (TrackerDBInterface *iface)
}
static void
-tracker_data_manager_recreate_indexes (TrackerBusyCallback busy_callback,
- gpointer busy_user_data,
- const gchar *busy_status,
- GError **error)
+tracker_data_manager_update_status (TrackerDataManager *manager,
+ const gchar *status)
+{
+ g_free (manager->status);
+ manager->status = g_strdup (status);
+ g_object_notify (G_OBJECT (manager), "status");
+}
+
+static void
+busy_callback (const gchar *status,
+ gdouble progress,
+ gpointer user_data)
+{
+ tracker_data_manager_update_status (user_data, status);
+}
+
+
+static void
+tracker_data_manager_recreate_indexes (TrackerDataManager *manager,
+ GError **error)
{
GError *internal_error = NULL;
TrackerProperty **properties;
guint n_properties;
guint i;
- properties = tracker_ontologies_get_properties (ontologies, &n_properties);
+ properties = tracker_ontologies_get_properties (manager->ontologies, &n_properties);
if (!properties) {
g_critical ("Couldn't get all properties to recreate indexes");
return;
@@ -3537,7 +3623,7 @@ tracker_data_manager_recreate_indexes (TrackerBusyCallback busy_callback,
g_debug ("Dropping all indexes...");
for (i = 0; i < n_properties; i++) {
- fix_indexed (properties [i], FALSE, &internal_error);
+ fix_indexed (manager, properties [i], FALSE, &internal_error);
if (internal_error) {
g_propagate_error (error, internal_error);
@@ -3547,7 +3633,7 @@ tracker_data_manager_recreate_indexes (TrackerBusyCallback busy_callback,
g_debug ("Starting index re-creation...");
for (i = 0; i < n_properties; i++) {
- fix_indexed (properties [i], TRUE, &internal_error);
+ fix_indexed (manager, properties [i], TRUE, &internal_error);
if (internal_error) {
g_critical ("Unable to create index for %s: %s",
@@ -3556,29 +3642,28 @@ tracker_data_manager_recreate_indexes (TrackerBusyCallback busy_callback,
g_clear_error (&internal_error);
}
- if (busy_callback) {
- busy_callback (busy_status,
- (gdouble) ((gdouble) i / (gdouble) n_properties),
- busy_user_data);
- }
+ busy_callback ("Recreating indexes",
+ (gdouble) ((gdouble) i / (gdouble) n_properties),
+ manager);
}
g_debug (" Finished index re-creation...");
}
static gboolean
-write_ontologies_gvdb (gboolean overwrite,
- GError **error)
+write_ontologies_gvdb (TrackerDataManager *manager,
+ gboolean overwrite,
+ GError **error)
{
gboolean retval = TRUE;
gchar *filename;
GFile *child;
- child = g_file_get_child (cache_location_stored, "ontologies.gvdb");
+ child = g_file_get_child (manager->cache_location, "ontologies.gvdb");
filename = g_file_get_path (child);
g_object_unref (child);
if (overwrite || !g_file_test (filename, G_FILE_TEST_EXISTS)) {
- retval = tracker_ontologies_write_gvdb (ontologies, filename, error);
+ retval = tracker_ontologies_write_gvdb (manager->ontologies, filename, error);
}
g_free (filename);
@@ -3587,32 +3672,34 @@ write_ontologies_gvdb (gboolean overwrite,
}
static void
-load_ontologies_gvdb (GError **error)
+load_ontologies_gvdb (TrackerDataManager *manager,
+ GError **error)
{
gchar *filename;
GFile *child;
- child = g_file_get_child (cache_location_stored, "ontologies.gvdb");
+ child = g_file_get_child (manager->cache_location, "ontologies.gvdb");
filename = g_file_get_path (child);
g_object_unref (child);
- g_object_unref (ontologies);
- ontologies = tracker_ontologies_load_gvdb (filename, error);
+ g_object_unref (manager->ontologies);
+ manager->ontologies = tracker_ontologies_load_gvdb (filename, error);
g_free (filename);
}
#if HAVE_TRACKER_FTS
static gboolean
-ontology_get_fts_properties (gboolean only_new,
- GHashTable **fts_properties,
- GHashTable **multivalued)
+ontology_get_fts_properties (TrackerDataManager *manager,
+ gboolean only_new,
+ GHashTable **fts_properties,
+ GHashTable **multivalued)
{
TrackerProperty **properties;
gboolean has_changed = FALSE;
guint i, len;
- properties = tracker_ontologies_get_properties (ontologies, &len);
+ properties = tracker_ontologies_get_properties (manager->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);
@@ -3652,14 +3739,15 @@ ontology_get_fts_properties (gboolean only_new,
}
static void
-rebuild_fts_tokens (TrackerDBInterface *iface)
+rebuild_fts_tokens (TrackerDataManager *manager,
+ TrackerDBInterface *iface)
{
g_debug ("Rebuilding FTS tokens, this may take a moment...");
tracker_db_interface_sqlite_fts_rebuild_tokens (iface);
g_debug ("FTS tokens rebuilt");
/* Update the stamp file */
- tracker_db_manager_tokenizer_update (db_manager);
+ tracker_db_manager_tokenizer_update (manager->db_manager);
}
#endif
@@ -3669,8 +3757,10 @@ tracker_data_manager_init_fts (TrackerDBInterface *iface,
{
#if HAVE_TRACKER_FTS
GHashTable *fts_props, *multivalued;
+ TrackerDataManager *manager;
- ontology_get_fts_properties (FALSE, &fts_props, &multivalued);
+ manager = tracker_db_interface_get_user_data (iface);
+ ontology_get_fts_properties (manager, FALSE, &fts_props, &multivalued);
tracker_db_interface_sqlite_fts_init (iface, fts_props,
multivalued, create);
g_hash_table_unref (fts_props);
@@ -3682,31 +3772,56 @@ tracker_data_manager_init_fts (TrackerDBInterface *iface,
#endif
}
-GFile * tracker_data_manager_get_cache_location()
+GFile *
+tracker_data_manager_get_cache_location (TrackerDataManager *manager)
{
- return cache_location_stored ? g_object_ref (cache_location_stored) : NULL;
+ return manager->cache_location ? g_object_ref (manager->cache_location) : NULL;
}
-GFile * tracker_data_manager_get_data_location ()
+GFile *
+tracker_data_manager_get_data_location (TrackerDataManager *manager)
{
- return data_location_stored ? g_object_ref (data_location_stored) : NULL;
+ return manager->data_location ? g_object_ref (manager->data_location) : NULL;
}
-gboolean
-tracker_data_manager_init (TrackerDBManagerFlags flags,
- GFile *cache_location,
- GFile *data_location,
- GFile *ontology_location,
- gboolean *first_time,
- gboolean journal_check,
- gboolean restoring_backup,
- guint select_cache_size,
- guint update_cache_size,
- TrackerBusyCallback busy_callback,
- gpointer busy_user_data,
- const gchar *busy_operation,
- GError **error)
+TrackerDataManager *
+tracker_data_manager_new (TrackerDBManagerFlags flags,
+ GFile *cache_location,
+ GFile *data_location,
+ GFile *ontology_location,
+ gboolean journal_check,
+ gboolean restoring_backup,
+ guint select_cache_size,
+ guint update_cache_size)
{
+ TrackerDataManager *manager;
+
+ if (!cache_location || !data_location || !ontology_location) {
+ g_warning ("All data storage and ontology locations must be provided");
+ return NULL;
+ }
+
+ manager = g_object_new (TRACKER_TYPE_DATA_MANAGER, NULL);
+
+ /* TODO: Make these properties */
+ g_set_object (&manager->cache_location, cache_location);
+ g_set_object (&manager->ontology_location, ontology_location);
+ g_set_object (&manager->data_location, data_location);
+ manager->flags = flags;
+ manager->journal_check = journal_check;
+ manager->restoring_backup = restoring_backup;
+ manager->select_cache_size = select_cache_size;
+ manager->update_cache_size = update_cache_size;
+
+ return manager;
+}
+
+static gboolean
+tracker_data_manager_initable_init (GInitable *initable,
+ GCancellable *cancellable,
+ GError **error)
+{
+ TrackerDataManager *manager = TRACKER_DATA_MANAGER (initable);
TrackerDBInterface *iface;
gboolean is_first_time_index, check_ontology;
TrackerDBCursor *cursor;
@@ -3716,22 +3831,17 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
gint max_id = 0;
gboolean read_only;
GHashTable *uri_id_map = NULL;
- gchar *busy_status;
GError *internal_error = NULL;
#ifndef DISABLE_JOURNAL
gboolean read_journal;
#endif
- if (!cache_location || !data_location || !ontology_location) {
- g_set_error (error,
- TRACKER_DATA_ONTOLOGY_ERROR,
- TRACKER_DATA_UNSUPPORTED_LOCATION,
- "All data storage and ontology locations must be provided");
- return FALSE;
+ if (manager->initialized) {
+ return TRUE;
}
- if (!g_file_is_native (cache_location) ||
- !g_file_is_native (data_location)) {
+ if (!g_file_is_native (manager->cache_location) ||
+ !g_file_is_native (manager->data_location)) {
g_set_error (error,
TRACKER_DATA_ONTOLOGY_ERROR,
TRACKER_DATA_UNSUPPORTED_LOCATION,
@@ -3739,72 +3849,43 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
return FALSE;
}
- read_only = (flags & TRACKER_DB_MANAGER_READONLY) ? TRUE : FALSE;
- data_update = tracker_data_new ();
-
- /* First set defaults for return values */
- if (first_time) {
- *first_time = FALSE;
- }
-
- if (initialized) {
- return TRUE;
- }
-
- /* Make sure we initialize all other modules we depend on */
- ontologies = tracker_ontologies_new ();
-
- if (!reloading) {
- tracker_locale_sanity_check ();
- }
-
+ read_only = (manager->flags & TRACKER_DB_MANAGER_READONLY) ? TRUE : FALSE;
#ifndef DISABLE_JOURNAL
read_journal = FALSE;
#endif
- db_manager = tracker_db_manager_new (flags,
- cache_location,
- data_location,
- &is_first_time_index,
- restoring_backup,
- FALSE,
- select_cache_size,
- update_cache_size,
- busy_callback,
- busy_user_data,
- busy_operation,
- &internal_error);
- if (!db_manager) {
+ /* Make sure we initialize all other modules we depend on */
+ manager->data_update = tracker_data_new (manager);
+ manager->ontologies = tracker_ontologies_new ();
+
+ manager->db_manager = tracker_db_manager_new (manager->flags,
+ manager->cache_location,
+ manager->data_location,
+ &is_first_time_index,
+ manager->restoring_backup,
+ FALSE,
+ manager->select_cache_size,
+ manager->update_cache_size,
+ busy_callback, manager, "",
+ G_OBJECT (manager),
+ &internal_error);
+ if (!manager->db_manager) {
g_propagate_error (error, internal_error);
-
- g_clear_object (&ontologies);
- g_clear_object (&data_update);
-
return FALSE;
}
- /* Report OPERATION - STATUS */
- if (busy_callback) {
- busy_status = g_strdup_printf ("%s - %s",
- busy_operation,
- "Initializing data manager");
- busy_callback (busy_status, 0, busy_user_data);
- g_free (busy_status);
- }
+ manager->first_time_index = is_first_time_index;
+ tracker_data_manager_update_status (manager, "Initializing data manager");
- if (first_time != NULL) {
- *first_time = is_first_time_index;
- }
-
- iface = tracker_db_manager_get_db_interface (db_manager);
+ iface = tracker_db_manager_get_db_interface (manager->db_manager);
#ifndef DISABLE_JOURNAL
- if (journal_check && is_first_time_index) {
+ if (manager->journal_check && is_first_time_index) {
TrackerDBJournalReader *journal_reader;
/* Call may fail without notice (it's handled) */
- journal_reader = tracker_db_journal_reader_new (data_location, &internal_error);
+ journal_reader = tracker_db_journal_reader_new (manager->data_location, &internal_error);
if (journal_reader) {
if (tracker_db_journal_reader_next (journal_reader, NULL)) {
@@ -3819,11 +3900,6 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
TRACKER_DB_JOURNAL_ERROR,
TRACKER_DB_JOURNAL_ERROR_BEGIN_OF_JOURNAL)) {
g_propagate_error (error, internal_error);
-
- g_clear_pointer (&db_manager, tracker_db_manager_free);
- g_clear_object (&ontologies);
- g_clear_object (&data_update);
-
return FALSE;
} else {
g_clear_error (&internal_error);
@@ -3832,23 +3908,14 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
}
#endif /* DISABLE_JOURNAL */
- g_set_object (&cache_location_stored, cache_location);
- g_set_object (&ontology_location_stored, ontology_location);
- g_set_object (&data_location_stored, data_location);
-
- ontologies_dir = g_object_ref (ontology_location);
-
- if (g_file_query_file_type (ontologies_dir, G_FILE_QUERY_INFO_NONE, NULL) != G_FILE_TYPE_DIRECTORY) {
+ if (g_file_query_file_type (manager->ontology_location, G_FILE_QUERY_INFO_NONE, NULL) !=
G_FILE_TYPE_DIRECTORY) {
gchar *uri;
- uri = g_file_get_uri (ontologies_dir);
+ uri = g_file_get_uri (manager->ontology_location);
g_set_error (error, TRACKER_DATA_ONTOLOGY_ERROR,
TRACKER_DATA_ONTOLOGY_NOT_FOUND,
"'%s' is not a ontology location", uri);
g_free (uri);
- g_clear_pointer (&db_manager, tracker_db_manager_free);
- g_clear_object (&ontologies);
- g_clear_object (&data_update);
return FALSE;
}
@@ -3856,8 +3923,8 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
if (read_journal) {
TrackerDBJournalReader *journal_reader;
- in_journal_replay = TRUE;
- journal_reader = tracker_db_journal_reader_ontology_new (data_location, &internal_error);
+ manager->in_journal_replay = TRUE;
+ journal_reader = tracker_db_journal_reader_ontology_new (manager->data_location,
&internal_error);
if (journal_reader) {
/* Load ontology IDs from journal into memory */
@@ -3869,11 +3936,6 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
TRACKER_DB_JOURNAL_ERROR,
TRACKER_DB_JOURNAL_ERROR_BEGIN_OF_JOURNAL)) {
g_propagate_error (error, internal_error);
-
- g_clear_pointer (&db_manager, tracker_db_manager_free);
- g_clear_object (&ontologies);
- g_clear_object (&data_update);
-
return FALSE;
} else {
g_clear_error (&internal_error);
@@ -3883,14 +3945,14 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
/* do not trigger journal replay if ontology journal
does not exist or is not valid,
same as with regular journal further above */
- in_journal_replay = FALSE;
+ manager->in_journal_replay = FALSE;
read_journal = FALSE;
}
}
#endif /* DISABLE_JOURNAL */
if (is_first_time_index && !read_only) {
- sorted = get_ontologies (ontologies_dir, &internal_error);
+ sorted = get_ontologies (manager, manager->ontology_location, &internal_error);
if (internal_error) {
g_propagate_error (error, internal_error);
@@ -3898,15 +3960,10 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
}
#ifndef DISABLE_JOURNAL
- ontology_writer = tracker_db_journal_ontology_new (data_location, &internal_error);
+ manager->ontology_writer = tracker_db_journal_ontology_new (manager->data_location,
&internal_error);
if (internal_error) {
g_propagate_error (error, internal_error);
-
- g_clear_pointer (&db_manager, tracker_db_manager_free);
- g_clear_object (&ontologies);
- g_clear_object (&data_update);
-
return FALSE;
}
#endif /* DISABLE_JOURNAL */
@@ -3920,7 +3977,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
g_debug ("Loading ontology %s", uri);
- load_ontology_file (ontology_file,
+ load_ontology_file (manager, ontology_file,
&max_id,
FALSE,
NULL,
@@ -3935,37 +3992,19 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
g_free (uri);
}
- tracker_data_begin_ontology_transaction (data_update, &internal_error);
+ tracker_data_begin_ontology_transaction (manager->data_update, &internal_error);
if (internal_error) {
g_propagate_error (error, internal_error);
-
-#ifndef DISABLE_JOURNAL
- tracker_db_journal_free (ontology_writer, NULL);
- ontology_writer = NULL;
-#endif /* DISABLE_JOURNAL */
- g_clear_pointer (&db_manager, tracker_db_manager_free);
- g_clear_object (&ontologies);
- g_clear_object (&data_update);
-
return FALSE;
}
- tracker_data_ontology_import_into_db (FALSE,
+ tracker_data_ontology_import_into_db (manager, FALSE,
&internal_error);
tracker_data_manager_init_fts (iface, TRUE);
if (internal_error) {
g_propagate_error (error, internal_error);
-
-#ifndef DISABLE_JOURNAL
- tracker_db_journal_free (ontology_writer, NULL);
- ontology_writer = NULL;
-#endif /* DISABLE_JOURNAL */
- g_clear_pointer (&db_manager, tracker_db_manager_free);
- g_clear_object (&ontologies);
- g_clear_object (&data_update);
-
return FALSE;
}
@@ -3977,19 +4016,12 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
g_hash_table_iter_init (&iter, uri_id_map);
while (g_hash_table_iter_next (&iter, &key, &value)) {
- insert_uri_in_resource_table (iface,
+ insert_uri_in_resource_table (manager, iface,
key,
GPOINTER_TO_INT (value),
&internal_error);
if (internal_error) {
g_propagate_error (error, internal_error);
-
- tracker_db_journal_free (ontology_writer, NULL);
- ontology_writer = NULL;
- g_clear_pointer (&db_manager, tracker_db_manager_free);
- g_clear_object (&ontologies);
- g_clear_object (&data_update);
-
return FALSE;
}
}
@@ -3998,25 +4030,17 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
/* store ontology in database */
for (l = sorted; l; l = l->next) {
- import_ontology_file (l->data, FALSE, !journal_check);
+ import_ontology_file (manager, l->data, FALSE, !manager->journal_check);
}
- tracker_data_commit_transaction (data_update, &internal_error);
+ tracker_data_commit_transaction (manager->data_update, &internal_error);
if (internal_error) {
g_propagate_error (error, internal_error);
- g_clear_pointer (&db_manager, tracker_db_manager_free);
- g_clear_object (&ontologies);
-#ifndef DISABLE_JOURNAL
- tracker_db_journal_free (ontology_writer, NULL);
- ontology_writer = NULL;
-#endif /* DISABLE_JOURNAL */
- g_clear_object (&data_update);
-
return FALSE;
}
- write_ontologies_gvdb (TRUE /* overwrite */, NULL);
+ write_ontologies_gvdb (manager, TRUE /* overwrite */, NULL);
g_list_free_full (sorted, g_object_unref);
sorted = NULL;
@@ -4025,44 +4049,39 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
check_ontology = FALSE;
#ifndef DISABLE_JOURNAL
- tracker_db_journal_free (ontology_writer, NULL);
- ontology_writer = NULL;
+ tracker_db_journal_free (manager->ontology_writer, NULL);
+ manager->ontology_writer = NULL;
#endif /* DISABLE_JOURNAL */
} else {
if (!read_only) {
#ifndef DISABLE_JOURNAL
- ontology_writer = tracker_db_journal_ontology_new (data_location, &internal_error);
+ manager->ontology_writer = tracker_db_journal_ontology_new (manager->data_location,
&internal_error);
if (internal_error) {
g_propagate_error (error, internal_error);
-
- g_clear_pointer (&db_manager, tracker_db_manager_free);
- g_clear_object (&ontologies);
- g_clear_object (&data_update);
-
return FALSE;
}
#endif /* DISABLE_JOURNAL */
/* Load ontology from database into memory */
- db_get_static_data (iface, &internal_error);
- check_ontology = (flags & TRACKER_DB_MANAGER_DO_NOT_CHECK_ONTOLOGY) == 0;
+ db_get_static_data (iface, manager, &internal_error);
+ check_ontology = (manager->flags & TRACKER_DB_MANAGER_DO_NOT_CHECK_ONTOLOGY) == 0;
if (internal_error) {
g_propagate_error (error, internal_error);
return FALSE;
}
- write_ontologies_gvdb (FALSE /* overwrite */, NULL);
+ write_ontologies_gvdb (manager, FALSE /* overwrite */, NULL);
/* Skipped in the read-only case as it can't work with direct access and
it reduces initialization time */
- clean_decomposed_transient_metadata (iface);
+ clean_decomposed_transient_metadata (manager, iface);
} else {
GError *gvdb_error = NULL;
- load_ontologies_gvdb (&gvdb_error);
+ load_ontologies_gvdb (manager, &gvdb_error);
check_ontology = FALSE;
if (gvdb_error) {
@@ -4071,7 +4090,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
g_clear_error (&gvdb_error);
/* fall back to loading ontology from database into memory */
- db_get_static_data (iface, &internal_error);
+ db_get_static_data (iface, manager, &internal_error);
if (internal_error) {
g_propagate_error (error, internal_error);
return FALSE;
@@ -4094,8 +4113,8 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
seen_classes = g_ptr_array_new ();
seen_properties = g_ptr_array_new ();
- /* Get all the ontology files from ontologies_dir */
- ontos = get_ontologies (ontologies_dir, &internal_error);
+ /* Get all the ontology files from ontology_location */
+ ontos = get_ontologies (manager, manager->ontology_location, &internal_error);
if (internal_error) {
g_propagate_error (error, internal_error);
@@ -4105,7 +4124,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
/* check ontology against database */
/* Get a map of tracker:Ontology v. nao:lastModified so that we can test
- * for all the ontology files in ontologies_dir whether the last-modified
+ * for all the ontology files in ontology_location whether the last-modified
* has changed since we dealt with the file last time. */
stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT,
&n_error,
@@ -4153,7 +4172,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
gint last_mod;
/* Parse a TrackerOntology from ontology_file */
- ontology = get_ontology_from_file (ontology_file);
+ ontology = get_ontology_from_file (manager, ontology_file);
if (!ontology) {
/* TODO: cope with full custom .ontology files: deal with this
@@ -4187,18 +4206,9 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
g_free (uri);
if (!transaction_started) {
- tracker_data_begin_ontology_transaction (data_update,
&internal_error);
+ tracker_data_begin_ontology_transaction
(manager->data_update, &internal_error);
if (internal_error) {
g_propagate_error (error, internal_error);
-
-#ifndef DISABLE_JOURNAL
- tracker_db_journal_free (ontology_writer, NULL);
- ontology_writer = NULL;
-#endif /* DISABLE_JOURNAL */
- g_clear_pointer (&db_manager,
tracker_db_manager_free);
- g_clear_object (&ontologies);
- g_clear_object (&data_update);
-
return FALSE;
}
transaction_started = TRUE;
@@ -4210,7 +4220,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
}
/* load ontology from files into memory, set all new's
* is_new to TRUE */
- load_ontology_file (ontology_file,
+ load_ontology_file (manager, ontology_file,
&max_id,
TRUE,
seen_classes,
@@ -4226,11 +4236,11 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
tracker_data_ontology_free_seen (seen_classes);
tracker_data_ontology_free_seen (seen_properties);
- tracker_data_ontology_import_finished ();
+ tracker_data_ontology_import_finished (manager);
/* as we're processing an ontology change,
transaction is guaranteed to be started */
- tracker_data_rollback_transaction (data_update);
+ tracker_data_rollback_transaction (manager->data_update);
if (ontos_table) {
g_hash_table_unref (ontos_table);
@@ -4238,27 +4248,12 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
if (ontos) {
g_list_free_full (ontos, g_object_unref);
}
- g_object_unref (ontologies_dir);
+ g_object_unref (manager->ontology_location);
if (uri_id_map) {
g_hash_table_unref (uri_id_map);
}
- initialized = TRUE;
-
- tracker_data_manager_shutdown ();
-
- return tracker_data_manager_init (flags |
TRACKER_DB_MANAGER_DO_NOT_CHECK_ONTOLOGY,
- cache_location,
- data_location,
- ontology_location,
- first_time,
- journal_check,
- restoring_backup,
- select_cache_size,
- update_cache_size,
- busy_callback,
- busy_user_data,
- busy_operation,
- error);
+
+ goto skip_ontology_check;
}
if (ontology_error) {
@@ -4277,18 +4272,9 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
g_free (uri);
if (!transaction_started) {
- tracker_data_begin_ontology_transaction (data_update,
&internal_error);
+ tracker_data_begin_ontology_transaction (manager->data_update,
&internal_error);
if (internal_error) {
g_propagate_error (error, internal_error);
-
-#ifndef DISABLE_JOURNAL
- tracker_db_journal_free (ontology_writer, NULL);
- ontology_writer = NULL;
-#endif /* DISABLE_JOURNAL */
- g_clear_pointer (&db_manager, tracker_db_manager_free);
- g_clear_object (&ontologies);
- g_clear_object (&data_update);
-
return FALSE;
}
transaction_started = TRUE;
@@ -4300,7 +4286,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
}
/* load ontology from files into memory, set all new's
* is_new to TRUE */
- load_ontology_file (ontology_file,
+ load_ontology_file (manager, ontology_file,
&max_id,
TRUE,
seen_classes,
@@ -4316,11 +4302,11 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
tracker_data_ontology_free_seen (seen_classes);
tracker_data_ontology_free_seen (seen_properties);
- tracker_data_ontology_import_finished ();
+ tracker_data_ontology_import_finished (manager);
/* as we're processing an ontology change,
transaction is guaranteed to be started */
- tracker_data_rollback_transaction (data_update);
+ tracker_data_rollback_transaction (manager->data_update);
if (ontos_table) {
g_hash_table_unref (ontos_table);
@@ -4328,27 +4314,11 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
if (ontos) {
g_list_free_full (ontos, g_object_unref);
}
- g_clear_object (&ontologies_dir);
if (uri_id_map) {
g_hash_table_unref (uri_id_map);
}
- initialized = TRUE;
-
- tracker_data_manager_shutdown ();
-
- return tracker_data_manager_init (flags |
TRACKER_DB_MANAGER_DO_NOT_CHECK_ONTOLOGY,
- cache_location,
- data_location,
- ontology_location,
- first_time,
- journal_check,
- restoring_backup,
- select_cache_size,
- update_cache_size,
- busy_callback,
- busy_user_data,
- busy_operation,
- error);
+
+ goto skip_ontology_check;
}
if (ontology_error) {
@@ -4364,7 +4334,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
#if HAVE_TRACKER_FTS
GHashTable *fts_properties, *multivalued;
- if (ontology_get_fts_properties (TRUE, &fts_properties, &multivalued)) {
+ if (ontology_get_fts_properties (manager, TRUE, &fts_properties,
&multivalued)) {
tracker_db_interface_sqlite_fts_alter_table (iface, fts_properties,
multivalued);
}
@@ -4399,17 +4369,19 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
if (to_reload) {
GError *ontology_error = NULL;
- tracker_data_ontology_process_changes_pre_db (seen_classes,
+ tracker_data_ontology_process_changes_pre_db (manager,
+ seen_classes,
seen_properties,
&ontology_error);
if (!ontology_error) {
/* Perform ALTER-TABLE and CREATE-TABLE calls for all that are is_new */
- tracker_data_ontology_import_into_db (TRUE,
+ tracker_data_ontology_import_into_db (manager, TRUE,
&ontology_error);
if (!ontology_error) {
- tracker_data_ontology_process_changes_post_db (seen_classes,
+ tracker_data_ontology_process_changes_post_db (manager,
+ seen_classes,
seen_properties,
&ontology_error);
}
@@ -4423,11 +4395,11 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
tracker_data_ontology_free_seen (seen_classes);
tracker_data_ontology_free_seen (seen_properties);
- tracker_data_ontology_import_finished ();
+ tracker_data_ontology_import_finished (manager);
/* as we're processing an ontology change,
transaction is guaranteed to be started */
- tracker_data_rollback_transaction (data_update);
+ tracker_data_rollback_transaction (manager->data_update);
if (ontos_table) {
g_hash_table_unref (ontos_table);
@@ -4435,81 +4407,46 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
if (ontos) {
g_list_free_full (ontos, g_object_unref);
}
- g_clear_object (&ontologies_dir);
if (uri_id_map) {
g_hash_table_unref (uri_id_map);
}
- initialized = TRUE;
-
- tracker_data_manager_shutdown ();
-
- return tracker_data_manager_init (flags |
TRACKER_DB_MANAGER_DO_NOT_CHECK_ONTOLOGY,
- cache_location,
- data_location,
- ontology_location,
- first_time,
- journal_check,
- restoring_backup,
- select_cache_size,
- update_cache_size,
- busy_callback,
- busy_user_data,
- busy_operation,
- error);
+
+ goto skip_ontology_check;
}
if (ontology_error) {
- g_critical ("Fatal error dealing with ontology changes: %s",
ontology_error->message);
g_propagate_error (error, ontology_error);
-
-#ifndef DISABLE_JOURNAL
- tracker_db_journal_free (ontology_writer, NULL);
- ontology_writer = NULL;
-#endif /* DISABLE_JOURNAL */
- g_clear_pointer (&db_manager, tracker_db_manager_free);
- g_clear_object (&ontologies);
- g_clear_object (&data_update);
-
return FALSE;
}
for (l = to_reload; l; l = l->next) {
GFile *ontology_file = l->data;
/* store ontology in database */
- import_ontology_file (ontology_file, TRUE, !journal_check);
+ import_ontology_file (manager, ontology_file, TRUE, !manager->journal_check);
}
g_list_free (to_reload);
tracker_data_ontology_process_changes_post_import (seen_classes, seen_properties);
- write_ontologies_gvdb (TRUE /* overwrite */, NULL);
+ write_ontologies_gvdb (manager, TRUE /* overwrite */, NULL);
}
tracker_data_ontology_free_seen (seen_classes);
tracker_data_ontology_free_seen (seen_properties);
/* Reset the is_new flag for all classes and properties */
- tracker_data_ontology_import_finished ();
+ tracker_data_ontology_import_finished (manager);
if (transaction_started) {
- tracker_data_commit_transaction (data_update, &internal_error);
+ tracker_data_commit_transaction (manager->data_update, &internal_error);
if (internal_error) {
g_propagate_error (error, internal_error);
-
-#ifndef DISABLE_JOURNAL
- tracker_db_journal_free (ontology_writer, NULL);
- ontology_writer = NULL;
-#endif /* DISABLE_JOURNAL */
- g_clear_pointer (&db_manager, tracker_db_manager_free);
- g_clear_object (&ontologies);
- g_clear_object (&data_update);
-
return FALSE;
}
#ifndef DISABLE_JOURNAL
- tracker_db_journal_free (ontology_writer, NULL);
- ontology_writer = NULL;
+ tracker_db_journal_free (manager->ontology_writer, NULL);
+ manager->ontology_writer = NULL;
#endif /* DISABLE_JOURNAL */
}
@@ -4517,26 +4454,22 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
g_list_free_full (ontos, g_object_unref);
}
+skip_ontology_check:
+
#ifndef DISABLE_JOURNAL
if (read_journal) {
- /* Report OPERATION - STATUS */
- busy_status = g_strdup_printf ("%s - %s",
- busy_operation,
- "Replaying journal");
/* Start replay */
- tracker_data_replay_journal (data_update,
+ tracker_data_replay_journal (manager->data_update,
busy_callback,
- busy_user_data,
- busy_status,
+ manager,
+ "Replaying journal",
&internal_error);
- g_free (busy_status);
if (internal_error) {
-
if (g_error_matches (internal_error, TRACKER_DB_INTERFACE_ERROR,
TRACKER_DB_NO_SPACE)) {
GError *n_error = NULL;
- tracker_db_manager_remove_all (db_manager);
- g_clear_pointer (&db_manager, tracker_db_manager_free);
+ tracker_db_manager_remove_all (manager->db_manager);
+ g_clear_pointer (&manager->db_manager, tracker_db_manager_free);
/* Call may fail without notice, we're in error handling already.
* When fails it means that close() of journal file failed. */
if (n_error) {
@@ -4548,149 +4481,164 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
g_hash_table_unref (uri_id_map);
g_propagate_error (error, internal_error);
-
- g_clear_pointer (&db_manager, tracker_db_manager_free);
- g_clear_object (&ontologies);
- g_clear_object (&data_update);
-
return FALSE;
}
- in_journal_replay = FALSE;
+ manager->in_journal_replay = FALSE;
g_hash_table_unref (uri_id_map);
}
/* open journal for writing */
- journal_writer = tracker_db_journal_new (data_location, FALSE, &internal_error);
+ manager->journal_writer = tracker_db_journal_new (manager->data_location, FALSE, &internal_error);
if (internal_error) {
g_propagate_error (error, internal_error);
-
- g_clear_pointer (&db_manager, tracker_db_manager_free);
- g_clear_object (&ontologies);
- g_clear_object (&data_update);
-
return FALSE;
}
#endif /* DISABLE_JOURNAL */
/* If locale changed, re-create indexes */
- if (!read_only && tracker_db_manager_locale_changed (db_manager, NULL)) {
- /* Report OPERATION - STATUS */
- busy_status = g_strdup_printf ("%s - %s",
- busy_operation,
- "Recreating indexes");
+ if (!read_only && tracker_db_manager_locale_changed (manager->db_manager, NULL)) {
/* No need to reset the collator in the db interface,
* as this is only executed during startup, which should
* already have the proper locale set in the collator */
- tracker_data_manager_recreate_indexes (busy_callback,
- busy_user_data,
- busy_status,
- &internal_error);
- g_free (busy_status);
+ tracker_data_manager_recreate_indexes (manager, &internal_error);
if (internal_error) {
g_propagate_error (error, internal_error);
-
-#ifndef DISABLE_JOURNAL
- tracker_db_journal_free (journal_writer, NULL);
-#endif /* DISABLE_JOURNAL */
- g_clear_pointer (&db_manager, tracker_db_manager_free);
- g_clear_object (&ontologies);
- g_clear_object (&data_update);
-
return FALSE;
}
- tracker_db_manager_set_current_locale (db_manager);
+ tracker_db_manager_set_current_locale (manager->db_manager);
#if HAVE_TRACKER_FTS
- rebuild_fts_tokens (iface);
- } else if (!read_only && tracker_db_manager_get_tokenizer_changed (db_manager)) {
- rebuild_fts_tokens (iface);
+ rebuild_fts_tokens (manager, iface);
+ } else if (!read_only && tracker_db_manager_get_tokenizer_changed (manager->db_manager)) {
+ rebuild_fts_tokens (manager, iface);
#endif
}
if (!read_only) {
- tracker_ontologies_sort (ontologies);
+ tracker_ontologies_sort (manager->ontologies);
}
- initialized = TRUE;
-
- g_clear_object (&ontologies_dir);
+ manager->initialized = TRUE;
/* This is the only one which doesn't show the 'OPERATION' part */
- if (busy_callback) {
- busy_callback ("Idle", 1, busy_user_data);
- }
+ tracker_data_manager_update_status (manager, "Idle");
return TRUE;
}
void
-tracker_data_manager_shutdown (void)
+tracker_data_manager_finalize (GObject *object)
{
+ TrackerDataManager *manager = TRACKER_DATA_MANAGER (object);
#ifndef DISABLE_JOURNAL
GError *error = NULL;
-#endif /* DISABLE_JOURNAL */
-
- g_return_if_fail (initialized == TRUE);
-#ifndef DISABLE_JOURNAL
/* Make sure we shutdown all other modules we depend on */
- if (journal_writer) {
- tracker_db_journal_free (journal_writer, &error);
+ if (manager->journal_writer) {
+ tracker_db_journal_free (manager->journal_writer, &error);
+ manager->journal_writer = NULL;
+ if (error) {
+ g_warning ("While shutting down journal %s", error->message);
+ g_clear_error (&error);
+ }
+ }
+ if (manager->ontology_writer) {
+ tracker_db_journal_free (manager->ontology_writer, &error);
+ manager->ontology_writer = NULL;
if (error) {
- /* TODO: propagate error */
- g_warning ("While shutting down journal %s",
- error->message ? error->message : "No error given");
- g_error_free (error);
+ g_warning ("While shutting down ontology journal %s", error->message);
+ g_clear_error (&error);
}
}
#endif /* DISABLE_JOURNAL */
- g_clear_pointer (&db_manager, tracker_db_manager_free);
- g_clear_object (&ontologies);
- g_clear_object (&data_update);
+ g_clear_pointer (&manager->db_manager, tracker_db_manager_free);
+ g_clear_object (&manager->ontologies);
+ g_clear_object (&manager->data_update);
+
+ G_OBJECT_CLASS (tracker_data_manager_parent_class)->finalize (object);
+}
+
+static void
+tracker_data_manager_initable_iface_init (GInitableIface *iface)
+{
+ iface->init = tracker_data_manager_initable_init;
+}
+
+static void
+tracker_data_manager_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerDataManager *manager = TRACKER_DATA_MANAGER (object);
+
+ switch (prop_id) {
+ case PROP_STATUS:
+ g_value_set_string (value, manager->status);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
- initialized = FALSE;
+static void
+tracker_data_manager_class_init (TrackerDataManagerClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->get_property = tracker_data_manager_get_property;
+ object_class->finalize = tracker_data_manager_finalize;
+
+ g_object_class_install_property (object_class,
+ PROP_STATUS,
+ g_param_spec_string ("status",
+ "Status",
+ "Status",
+ NULL,
+ G_PARAM_READABLE));
}
#ifndef DISABLE_JOURNAL
TrackerDBJournal *
-tracker_data_manager_get_journal_writer (void)
+tracker_data_manager_get_journal_writer (TrackerDataManager *manager)
{
- return journal_writer;
+ return manager->journal_writer;
}
TrackerDBJournal *
-tracker_data_manager_get_ontology_writer (void)
+tracker_data_manager_get_ontology_writer (TrackerDataManager *manager)
{
- return ontology_writer;
+ return manager->ontology_writer;
}
#endif
TrackerOntologies *
-tracker_data_manager_get_ontologies (void)
+tracker_data_manager_get_ontologies (TrackerDataManager *manager)
{
- return ontologies;
+ return manager->ontologies;
}
TrackerDBManager *
-tracker_data_manager_get_db_manager (void)
+tracker_data_manager_get_db_manager (TrackerDataManager *manager)
{
- return db_manager;
+ return manager->db_manager;
}
TrackerDBInterface *
-tracker_data_manager_get_db_interface (void)
+tracker_data_manager_get_db_interface (TrackerDataManager *manager)
{
- return tracker_db_manager_get_db_interface (db_manager);
+ return tracker_db_manager_get_db_interface (manager->db_manager);
}
TrackerData *
-tracker_data_manager_get_data (void)
+tracker_data_manager_get_data (TrackerDataManager *manager)
{
- return data_update;
+ return manager->data_update;
}
diff --git a/src/libtracker-data/tracker-data-manager.h b/src/libtracker-data/tracker-data-manager.h
index 61244dc..c09e677 100644
--- a/src/libtracker-data/tracker-data-manager.h
+++ b/src/libtracker-data/tracker-data-manager.h
@@ -23,8 +23,17 @@
#ifndef __LIBTRACKER_DATA_MANAGER_H__
#define __LIBTRACKER_DATA_MANAGER_H__
+#if !defined (__LIBTRACKER_DATA_INSIDE__) && !defined (TRACKER_COMPILATION)
+#error "only <libtracker-data/tracker-data.h> must be included directly."
+#endif
+
#include <glib.h>
+G_BEGIN_DECLS
+
+typedef struct _TrackerDataManager TrackerDataManager;
+typedef struct _TrackerDataManagerClass TrackerDataManagerClass;
+
#include <libtracker-common/tracker-common.h>
#include <libtracker-sparql/tracker-sparql.h>
@@ -33,46 +42,42 @@
#include <libtracker-data/tracker-db-manager.h>
#include <libtracker-data/tracker-db-journal.h>
-G_BEGIN_DECLS
-
-#if !defined (__LIBTRACKER_DATA_INSIDE__) && !defined (TRACKER_COMPILATION)
-#error "only <libtracker-data/tracker-data.h> must be included directly."
-#endif
-
#define TRACKER_DATA_ONTOLOGY_ERROR (tracker_data_ontology_error_quark ())
+#define TRACKER_TYPE_DATA_MANAGER (tracker_data_manager_get_type ())
+#define TRACKER_DATA_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_DATA_MANAGER,
TrackerDataManager))
+#define TRACKER_DATA_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), TRACKER_TYPE_DATA_MANAGER,
TrackerDataManagerClass))
+#define TRACKER_IS_DATA_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_DATA_MANAGER))
+#define TRACKER_IS_DATA_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TRACKER_TYPE_DATA_MANAGER))
+#define TRACKER_DATA_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_DATA_MANAGER,
TrackerDataManagerClass))
+
typedef enum {
TRACKER_DATA_UNSUPPORTED_ONTOLOGY_CHANGE,
TRACKER_DATA_ONTOLOGY_NOT_FOUND,
TRACKER_DATA_UNSUPPORTED_LOCATION
} TrackerDataOntologyError;
+GType tracker_data_manager_get_type (void) G_GNUC_CONST;
+
GQuark tracker_data_ontology_error_quark (void);
-gboolean tracker_data_manager_init (TrackerDBManagerFlags flags,
+TrackerDataManager * tracker_data_manager_new (TrackerDBManagerFlags flags,
GFile *cache_location,
GFile *data_location,
GFile *ontology_location,
- gboolean *first_time,
gboolean journal_check,
gboolean restoring_backup,
guint select_cache_size,
- guint update_cache_size,
- TrackerBusyCallback busy_callback,
- gpointer busy_user_data,
- const gchar *busy_operation,
- GError **error);
-
-void tracker_data_manager_shutdown (void);
-
-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);
-
-TrackerDBManager * tracker_data_manager_get_db_manager (void);
-TrackerDBInterface * tracker_data_manager_get_db_interface (void);
-TrackerData * tracker_data_manager_get_data (void);
+ guint update_cache_size);
+
+GFile * tracker_data_manager_get_cache_location (TrackerDataManager *manager);
+GFile * tracker_data_manager_get_data_location (TrackerDataManager *manager);
+TrackerDBJournal * tracker_data_manager_get_journal_writer (TrackerDataManager *manager);
+TrackerDBJournal * tracker_data_manager_get_ontology_writer (TrackerDataManager *manager);
+TrackerOntologies * tracker_data_manager_get_ontologies (TrackerDataManager *manager);
+
+TrackerDBManager * tracker_data_manager_get_db_manager (TrackerDataManager *manager);
+TrackerDBInterface * tracker_data_manager_get_db_interface (TrackerDataManager *manager);
+TrackerData * tracker_data_manager_get_data (TrackerDataManager *manager);
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 7de71ea..042613f 100644
--- a/src/libtracker-data/tracker-data-query.c
+++ b/src/libtracker-data/tracker-data-query.c
@@ -34,7 +34,8 @@
#include "tracker-sparql-query.h"
GPtrArray*
-tracker_data_query_rdf_type (gint id)
+tracker_data_query_rdf_type (TrackerDataManager *manager,
+ gint id)
{
TrackerDBCursor *cursor = NULL;
TrackerDBInterface *iface;
@@ -43,8 +44,8 @@ tracker_data_query_rdf_type (gint id)
GError *error = NULL;
TrackerOntologies *ontologies;
- iface = tracker_data_manager_get_db_interface ();
- ontologies = tracker_data_manager_get_ontologies ();
+ iface = tracker_data_manager_get_db_interface (manager);
+ ontologies = tracker_data_manager_get_ontologies (manager);
stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
"SELECT (SELECT Uri FROM Resource WHERE ID =
\"rdf:type\") "
@@ -93,7 +94,8 @@ tracker_data_query_rdf_type (gint id)
}
gint
-tracker_data_query_resource_id (const gchar *uri)
+tracker_data_query_resource_id (TrackerDataManager *manager,
+ const gchar *uri)
{
TrackerDBCursor *cursor = NULL;
TrackerDBInterface *iface;
@@ -103,7 +105,7 @@ tracker_data_query_resource_id (const gchar *uri)
g_return_val_if_fail (uri != NULL, 0);
- iface = tracker_data_manager_get_db_interface ();
+ iface = tracker_data_manager_get_db_interface (manager);
stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
"SELECT ID FROM Resource WHERE Uri = ?");
@@ -132,15 +134,16 @@ tracker_data_query_resource_id (const gchar *uri)
TrackerDBCursor *
-tracker_data_query_sparql_cursor (const gchar *query,
- GError **error)
+tracker_data_query_sparql_cursor (TrackerDataManager *manager,
+ const gchar *query,
+ GError **error)
{
TrackerSparqlQuery *sparql_query;
TrackerDBCursor *cursor;
g_return_val_if_fail (query != NULL, NULL);
- sparql_query = tracker_sparql_query_new (query);
+ sparql_query = tracker_sparql_query_new (manager, query);
cursor = tracker_sparql_query_execute_cursor (sparql_query, error);
diff --git a/src/libtracker-data/tracker-data-query.h b/src/libtracker-data/tracker-data-query.h
index d42cf4c..c05f2b2 100644
--- a/src/libtracker-data/tracker-data-query.h
+++ b/src/libtracker-data/tracker-data-query.h
@@ -26,6 +26,7 @@
#include <glib.h>
#include "tracker-db-interface.h"
+#include "tracker-data-manager.h"
G_BEGIN_DECLS
@@ -33,11 +34,14 @@ G_BEGIN_DECLS
#error "only <libtracker-data/tracker-data.h> must be included directly."
#endif
-gint tracker_data_query_resource_id (const gchar *uri);
-TrackerDBCursor *tracker_data_query_sparql_cursor (const gchar *query,
- GError **error);
+gint tracker_data_query_resource_id (TrackerDataManager *manager,
+ const gchar *uri);
+TrackerDBCursor *tracker_data_query_sparql_cursor (TrackerDataManager *manager,
+ const gchar *query,
+ GError **error);
-GPtrArray* tracker_data_query_rdf_type (gint id);
+GPtrArray* tracker_data_query_rdf_type (TrackerDataManager *manager,
+ gint id);
G_END_DECLS
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 0e2882b..2b18a40 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -137,6 +137,8 @@ typedef struct {
struct _TrackerData {
GObject parent_instance;
+ TrackerDataManager *manager;
+
gboolean in_transaction;
gboolean in_ontology_transaction;
gboolean in_journal_replay;
@@ -163,6 +165,11 @@ struct _TrackerDataClass {
GObjectClass parent_class;
};
+enum {
+ PROP_0,
+ PROP_MANAGER
+};
+
G_DEFINE_TYPE (TrackerData, tracker_data, G_TYPE_OBJECT);
static gint ensure_resource_id (TrackerData *data,
@@ -359,7 +366,7 @@ tracker_data_update_get_new_service_id (TrackerData *data)
return ++data->max_ontology_id;
}
- iface = tracker_data_manager_get_db_interface ();
+ iface = tracker_data_manager_get_db_interface (data->manager);
stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT,
&error,
"SELECT MAX(ID) AS A FROM Resource WHERE ID <=
%d", TRACKER_ONTOLOGIES_MAX_ID);
@@ -390,7 +397,7 @@ tracker_data_update_get_new_service_id (TrackerData *data)
data->max_service_id = TRACKER_ONTOLOGIES_MAX_ID;
- iface = tracker_data_manager_get_db_interface ();
+ iface = tracker_data_manager_get_db_interface (data->manager);
stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT,
&error,
"SELECT MAX(ID) AS A FROM Resource");
@@ -426,7 +433,7 @@ tracker_data_update_get_next_modseq (TrackerData *data)
GError *error = NULL;
gint max_modseq = 0;
- temp_iface = tracker_data_manager_get_db_interface ();
+ temp_iface = tracker_data_manager_get_db_interface (data->manager);
stmt = tracker_db_interface_create_statement (temp_iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT,
&error,
"SELECT MAX(\"tracker:modified\") AS A FROM
\"rdfs:Resource\"");
@@ -458,14 +465,65 @@ tracker_data_init (TrackerData *data)
}
static void
-tracker_data_class_init (TrackerDataClass *class)
+tracker_data_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerData *data = TRACKER_DATA (object);
+
+ switch (prop_id) {
+ case PROP_MANAGER:
+ data->manager = g_value_get_object (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+tracker_data_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
+ TrackerData *data = TRACKER_DATA (object);
+
+ switch (prop_id) {
+ case PROP_MANAGER:
+ g_value_set_object (value, data->manager);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+tracker_data_class_init (TrackerDataClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->set_property = tracker_data_set_property;
+ object_class->get_property = tracker_data_get_property;
+
+ g_object_class_install_property (object_class,
+ PROP_MANAGER,
+ g_param_spec_object ("manager",
+ "manager",
+ "manager",
+ TRACKER_TYPE_DATA_MANAGER,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY));
}
TrackerData *
-tracker_data_new (void)
+tracker_data_new (TrackerDataManager *manager)
{
- return g_object_new (TRACKER_TYPE_DATA, NULL);
+ return g_object_new (TRACKER_TYPE_DATA,
+ "manager", manager,
+ NULL);
}
static gint
@@ -628,7 +686,7 @@ query_resource_id (TrackerData *data,
id = GPOINTER_TO_INT (g_hash_table_lookup (data->update_buffer.resource_cache, uri));
if (id == 0) {
- id = tracker_data_query_resource_id (uri);
+ id = tracker_data_query_resource_id (data->manager, uri);
if (id) {
g_hash_table_insert (data->update_buffer.resource_cache, g_strdup (uri),
GINT_TO_POINTER (id));
@@ -655,7 +713,7 @@ ensure_resource_id (TrackerData *data,
}
if (id == 0) {
- iface = tracker_data_manager_get_db_interface ();
+ iface = tracker_data_manager_get_db_interface (data->manager);
id = tracker_data_update_get_new_service_id (data);
stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE,
&error,
@@ -747,7 +805,7 @@ tracker_data_resource_buffer_flush (TrackerData *data,
gint i, param;
GError *actual_error = NULL;
- iface = tracker_data_manager_get_db_interface ();
+ iface = tracker_data_manager_get_db_interface (data->manager);
g_hash_table_iter_init (&iter, data->resource_buffer->tables);
while (g_hash_table_iter_next (&iter, (gpointer*) &table_name, (gpointer*) &table)) {
@@ -1134,7 +1192,7 @@ tracker_data_blank_buffer_flush (TrackerData *data,
blank_uri = g_strdup_printf ("urn:uuid:%.8s-%.4s-%.4s-%.4s-%.12s",
sha1, sha1 + 8, sha1 + 12, sha1 + 16, sha1 + 20);
- id = tracker_data_query_resource_id (blank_uri);
+ id = tracker_data_query_resource_id (data->manager, blank_uri);
if (id == 0) {
/* uri not found
@@ -1208,7 +1266,7 @@ cache_create_service_decomposed (TrackerData *data,
* class_id = ensure_resource_id (tracker_class_get_uri (cl), NULL); */
class_id = tracker_class_get_id (cl);
- ontologies = tracker_data_manager_get_ontologies ();
+ ontologies = tracker_data_manager_get_ontologies (data->manager);
g_value_set_int64 (&gvalue, class_id);
cache_insert_value (data, "rdfs:Resource_rdf:type", "rdf:type",
@@ -1405,7 +1463,7 @@ get_property_values (TrackerData *data,
table_name = tracker_property_get_table_name (property);
field_name = tracker_property_get_name (property);
- iface = tracker_data_manager_get_db_interface ();
+ iface = tracker_data_manager_get_db_interface (data->manager);
stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT,
&error,
"SELECT \"%s\" FROM \"%s\" WHERE ID = ?",
@@ -1476,7 +1534,7 @@ get_old_property_values (TrackerData *data,
if (tracker_property_get_fulltext_indexed (property)) {
TrackerDBInterface *iface;
- iface = tracker_data_manager_get_db_interface ();
+ iface = tracker_data_manager_get_db_interface (data->manager);
if (!data->resource_buffer->fts_updated && !data->resource_buffer->create) {
TrackerOntologies *ontologies;
@@ -1486,7 +1544,7 @@ get_old_property_values (TrackerData *data,
/* first fulltext indexed property to be modified
* retrieve values of all fulltext indexed properties
*/
- ontologies = tracker_data_manager_get_ontologies ();
+ ontologies = tracker_data_manager_get_ontologies (data->manager);
properties = tracker_ontologies_get_properties (ontologies, &n_props);
for (i = 0; i < n_props; i++) {
@@ -1856,7 +1914,7 @@ delete_first_object (TrackerData *data,
TrackerProperty *damaged;
TrackerOntologies *ontologies;
- ontologies = tracker_data_manager_get_ontologies ();
+ ontologies = tracker_data_manager_get_ontologies (data->manager);
damaged = tracker_ontologies_get_property_by_uri (ontologies,
TRACKER_PREFIX_TRACKER "damaged");
tracker_db_journal_append_insert_statement (data->journal_writer,
@@ -2127,8 +2185,8 @@ cache_delete_resource_type_full (TrackerData *data,
GError *error = NULL;
TrackerOntologies *ontologies;
- iface = tracker_data_manager_get_db_interface ();
- ontologies = tracker_data_manager_get_ontologies ();
+ iface = tracker_data_manager_get_db_interface (data->manager);
+ ontologies = tracker_data_manager_get_ontologies (data->manager);
if (!single_type) {
if (strcmp (tracker_class_get_uri (class), TRACKER_PREFIX_RDFS "Resource") == 0 &&
@@ -2381,7 +2439,7 @@ resource_buffer_switch (TrackerData *data,
if (resource_buffer->create) {
resource_buffer->types = g_ptr_array_new ();
} else {
- resource_buffer->types = tracker_data_query_rdf_type (resource_buffer->id);
+ resource_buffer->types = tracker_data_query_rdf_type (data->manager,
resource_buffer->id);
}
resource_buffer->predicates = g_hash_table_new_full (g_direct_hash, g_direct_equal,
g_object_unref, (GDestroyNotify) g_array_unref);
resource_buffer->tables = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
(GDestroyNotify) cache_table_free);
@@ -2427,7 +2485,7 @@ tracker_data_delete_statement (TrackerData *data,
}
resource_buffer_switch (data, graph, subject, subject_id);
- ontologies = tracker_data_manager_get_ontologies ();
+ ontologies = tracker_data_manager_get_ontologies (data->manager);
if (object && g_strcmp0 (predicate, TRACKER_PREFIX_RDF "type") == 0) {
class = tracker_ontologies_get_class_by_uri (ontologies, object);
@@ -2440,7 +2498,7 @@ tracker_data_delete_statement (TrackerData *data,
data->journal_writer,
(graph != NULL ? query_resource_id (data, graph) : 0),
data->resource_buffer->id,
- tracker_data_query_resource_id (predicate),
+ tracker_data_query_resource_id (data->manager, predicate),
tracker_class_get_id (class));
}
#endif /* DISABLE_JOURNAL */
@@ -2515,7 +2573,7 @@ tracker_data_delete_statement (TrackerData *data,
if (!tried) {
graph_id = (graph != NULL ? query_resource_id (data, graph) : 0);
if (field == NULL) {
- pred_id = tracker_data_query_resource_id (predicate);
+ pred_id = tracker_data_query_resource_id (data->manager, predicate);
} else {
pred_id = tracker_property_get_id (field);
}
@@ -2562,7 +2620,7 @@ delete_all_objects (TrackerData *data,
}
resource_buffer_switch (data, graph, subject, subject_id);
- ontologies = tracker_data_manager_get_ontologies ();
+ ontologies = tracker_data_manager_get_ontologies (data->manager);
field = tracker_ontologies_get_property_by_uri (ontologies, predicate);
if (field != NULL) {
@@ -2661,7 +2719,7 @@ tracker_data_insert_statement (TrackerData *data,
g_return_if_fail (object != NULL);
g_return_if_fail (data->in_transaction);
- ontologies = tracker_data_manager_get_ontologies ();
+ ontologies = tracker_data_manager_get_ontologies (data->manager);
property = tracker_ontologies_get_property_by_uri (ontologies, predicate);
if (property != NULL) {
@@ -2748,7 +2806,7 @@ tracker_data_insert_statement_with_uri (TrackerData *data,
g_return_if_fail (object != NULL);
g_return_if_fail (data->in_transaction);
- ontologies = tracker_data_manager_get_ontologies ();
+ ontologies = tracker_data_manager_get_ontologies (data->manager);
property = tracker_ontologies_get_property_by_uri (ontologies, predicate);
if (property == NULL) {
@@ -2803,7 +2861,7 @@ tracker_data_insert_statement_with_uri (TrackerData *data,
if (!data->in_journal_replay && !tracker_property_get_transient (property)) {
graph_id = (graph != NULL ? query_resource_id (data, graph) : 0);
- final_prop_id = (prop_id != 0) ? prop_id : tracker_data_query_resource_id (predicate);
+ final_prop_id = (prop_id != 0) ? prop_id : tracker_data_query_resource_id
(data->manager, predicate);
object_id = query_resource_id (data, object);
}
@@ -2818,7 +2876,7 @@ tracker_data_insert_statement_with_uri (TrackerData *data,
if (change) {
graph_id = (graph != NULL ? query_resource_id (data, graph) : 0);
- final_prop_id = (prop_id != 0) ? prop_id : tracker_data_query_resource_id (predicate);
+ final_prop_id = (prop_id != 0) ? prop_id : tracker_data_query_resource_id
(data->manager, predicate);
object_id = query_resource_id (data, object);
if (data->insert_callbacks) {
@@ -2872,7 +2930,7 @@ tracker_data_insert_statement_with_string (TrackerData *data,
g_return_if_fail (object != NULL);
g_return_if_fail (data->in_transaction);
- ontologies = tracker_data_manager_get_ontologies ();
+ ontologies = tracker_data_manager_get_ontologies (data->manager);
property = tracker_ontologies_get_property_by_uri (ontologies, predicate);
if (property == NULL) {
@@ -2912,7 +2970,7 @@ tracker_data_insert_statement_with_string (TrackerData *data,
guint n;
graph_id = (graph != NULL ? query_resource_id (data, graph) : 0);
- pred_id = (pred_id != 0) ? pred_id : tracker_data_query_resource_id (predicate);
+ pred_id = (pred_id != 0) ? pred_id : tracker_data_query_resource_id (data->manager,
predicate);
#ifndef DISABLE_JOURNAL
tried = TRUE;
#endif
@@ -2933,7 +2991,7 @@ tracker_data_insert_statement_with_string (TrackerData *data,
if (!data->in_journal_replay && change && !tracker_property_get_transient (property)) {
if (!tried) {
graph_id = (graph != NULL ? query_resource_id (data, graph) : 0);
- pred_id = (pred_id != 0) ? pred_id : tracker_data_query_resource_id (predicate);
+ pred_id = (pred_id != 0) ? pred_id : tracker_data_query_resource_id (data->manager,
predicate);
}
if (!tracker_property_get_force_journal (property) &&
g_strcmp0 (graph, TRACKER_OWN_GRAPH_URN) == 0) {
@@ -2977,7 +3035,7 @@ tracker_data_update_statement_with_uri (TrackerData *data,
g_return_if_fail (predicate != NULL);
g_return_if_fail (data->in_transaction);
- ontologies = tracker_data_manager_get_ontologies ();
+ ontologies = tracker_data_manager_get_ontologies (data->manager);
property = tracker_ontologies_get_property_by_uri (ontologies, predicate);
if (property == NULL) {
@@ -3034,7 +3092,7 @@ tracker_data_update_statement_with_uri (TrackerData *data,
if (!data->in_journal_replay && !tracker_property_get_transient (property)) {
graph_id = (graph != NULL ? query_resource_id (data, graph) : 0);
- final_prop_id = (prop_id != 0) ? prop_id : tracker_data_query_resource_id (predicate);
+ final_prop_id = (prop_id != 0) ? prop_id : tracker_data_query_resource_id
(data->manager, predicate);
object_id = query_resource_id (data, object);
}
@@ -3117,7 +3175,7 @@ tracker_data_update_statement_with_uri (TrackerData *data,
if (change) {
graph_id = (graph != NULL ? query_resource_id (data, graph) : 0);
- final_prop_id = (prop_id != 0) ? prop_id : tracker_data_query_resource_id (predicate);
+ final_prop_id = (prop_id != 0) ? prop_id : tracker_data_query_resource_id
(data->manager, predicate);
object_id = query_resource_id (data, object);
if (!multiple_values && data->delete_callbacks) {
@@ -3190,7 +3248,7 @@ tracker_data_update_statement_with_string (TrackerData *data,
g_return_if_fail (predicate != NULL);
g_return_if_fail (data->in_transaction);
- ontologies = tracker_data_manager_get_ontologies ();
+ ontologies = tracker_data_manager_get_ontologies (data->manager);
property = tracker_ontologies_get_property_by_uri (ontologies, predicate);
if (property == NULL) {
@@ -3249,7 +3307,7 @@ tracker_data_update_statement_with_string (TrackerData *data,
if (((!multiple_values && data->delete_callbacks) || data->insert_callbacks) && change) {
graph_id = (graph != NULL ? query_resource_id (data, graph) : 0);
- pred_id = (pred_id != 0) ? pred_id : tracker_data_query_resource_id (predicate);
+ pred_id = (pred_id != 0) ? pred_id : tracker_data_query_resource_id (data->manager,
predicate);
#ifndef DISABLE_JOURNAL
tried = TRUE;
#endif
@@ -3289,7 +3347,7 @@ tracker_data_update_statement_with_string (TrackerData *data,
if (!data->in_journal_replay && change && !tracker_property_get_transient (property)) {
if (!tried) {
graph_id = (graph != NULL ? query_resource_id (data, graph) : 0);
- pred_id = (pred_id != 0) ? pred_id : tracker_data_query_resource_id (predicate);
+ pred_id = (pred_id != 0) ? pred_id : tracker_data_query_resource_id (data->manager,
predicate);
}
if (!tracker_property_get_force_journal (property) &&
g_strcmp0 (graph, TRACKER_OWN_GRAPH_URN) == 0) {
@@ -3328,7 +3386,7 @@ tracker_data_update_statement (TrackerData *data,
g_return_if_fail (predicate != NULL);
g_return_if_fail (data->in_transaction);
- ontologies = tracker_data_manager_get_ontologies ();
+ ontologies = tracker_data_manager_get_ontologies (data->manager);
property = tracker_ontologies_get_property_by_uri (ontologies, predicate);
if (property != NULL) {
@@ -3380,7 +3438,7 @@ tracker_data_begin_transaction (TrackerData *data,
g_return_if_fail (!data->in_transaction);
- db_manager = tracker_data_manager_get_db_manager ();
+ db_manager = tracker_data_manager_get_db_manager (data->manager);
if (!tracker_db_manager_has_enough_space (db_manager)) {
g_set_error (error, TRACKER_SPARQL_ERROR, TRACKER_SPARQL_ERROR_NO_SPACE,
@@ -3405,7 +3463,7 @@ tracker_data_begin_transaction (TrackerData *data,
data->blank_buffer.table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
}
- iface = tracker_data_manager_get_db_interface ();
+ iface = tracker_data_manager_get_db_interface (data->manager);
tracker_db_interface_execute_query (iface, NULL, "PRAGMA cache_size = %d",
TRACKER_DB_CACHE_SIZE_UPDATE);
@@ -3416,8 +3474,8 @@ tracker_data_begin_transaction (TrackerData *data,
g_assert (data->journal_writer == NULL);
/* Pick the right journal writer for this transaction */
data->journal_writer = data->in_ontology_transaction ?
- tracker_data_manager_get_ontology_writer () :
- tracker_data_manager_get_journal_writer ();
+ tracker_data_manager_get_ontology_writer (data->manager) :
+ tracker_data_manager_get_journal_writer (data->manager);
tracker_db_journal_start_transaction (data->journal_writer, data->resource_time);
}
@@ -3453,7 +3511,7 @@ tracker_data_commit_transaction (TrackerData *data,
g_return_if_fail (data->in_transaction);
- iface = tracker_data_manager_get_db_interface ();
+ iface = tracker_data_manager_get_db_interface (data->manager);
tracker_data_update_buffer_flush (data, &actual_error);
if (actual_error) {
@@ -3548,7 +3606,7 @@ tracker_data_rollback_transaction (TrackerData *data)
data->in_transaction = FALSE;
data->in_ontology_transaction = FALSE;
- iface = tracker_data_manager_get_db_interface ();
+ iface = tracker_data_manager_get_db_interface (data->manager);
tracker_data_update_buffer_clear (data);
@@ -3599,7 +3657,7 @@ update_sparql (TrackerData *data,
return NULL;
}
- sparql_query = tracker_sparql_query_new_update (update);
+ sparql_query = tracker_sparql_query_new_update (data->manager, update);
blank_nodes = tracker_sparql_query_execute_update (sparql_query, blank, &actual_error);
g_object_unref (sparql_query);
@@ -3641,7 +3699,7 @@ tracker_data_load_turtle_file (TrackerData *data,
{
g_return_if_fail (G_IS_FILE (file));
- tracker_turtle_reader_load (file, error);
+ tracker_turtle_reader_load (file, data, error);
}
void
@@ -3650,11 +3708,11 @@ tracker_data_sync (TrackerData *data)
#ifndef DISABLE_JOURNAL
TrackerDBJournal *writer;
- writer = tracker_data_manager_get_journal_writer ();
+ writer = tracker_data_manager_get_journal_writer (data->manager);
if (writer)
tracker_db_journal_fsync (writer);
- writer = tracker_data_manager_get_ontology_writer ();
+ writer = tracker_data_manager_get_ontology_writer (data->manager);
if (writer)
tracker_db_journal_fsync (writer);
#endif
@@ -3678,10 +3736,10 @@ tracker_data_replay_journal (TrackerData *data,
TrackerDBJournalReader *reader;
TrackerOntologies *ontologies;
- ontologies = tracker_data_manager_get_ontologies ();
+ ontologies = tracker_data_manager_get_ontologies (data->manager);
rdf_type = tracker_ontologies_get_rdf_type (ontologies);
- data_location = tracker_data_manager_get_data_location ();
+ data_location = tracker_data_manager_get_data_location (data->manager);
reader = tracker_db_journal_reader_new (data_location, &n_error);
g_object_unref (data_location);
@@ -3706,7 +3764,7 @@ tracker_data_replay_journal (TrackerData *data,
tracker_db_journal_reader_get_resource (reader, &id, &uri);
- iface = tracker_data_manager_get_db_interface ();
+ iface = tracker_data_manager_get_db_interface (data->manager);
stmt = tracker_db_interface_create_statement (iface,
TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &new_error,
"INSERT INTO Resource (ID, Uri) VALUES
(?, ?)");
@@ -3950,8 +4008,8 @@ tracker_data_replay_journal (TrackerData *data,
size = tracker_db_journal_reader_get_size_of_correct (reader);
tracker_db_journal_reader_free (reader);
- cache_location = tracker_data_manager_get_cache_location();
- data_location = tracker_data_manager_get_data_location();
+ cache_location = tracker_data_manager_get_cache_location(data->manager);
+ data_location = tracker_data_manager_get_data_location (data->manager);
writer = tracker_db_journal_new (data_location, FALSE, &n_error);
g_object_unref (cache_location);
diff --git a/src/libtracker-data/tracker-data-update.h b/src/libtracker-data/tracker-data-update.h
index ce1687b..7544487 100644
--- a/src/libtracker-data/tracker-data-update.h
+++ b/src/libtracker-data/tracker-data-update.h
@@ -21,18 +21,21 @@
#ifndef __LIBTRACKER_DATA_UPDATE_H__
#define __LIBTRACKER_DATA_UPDATE_H__
+#if !defined (__LIBTRACKER_DATA_INSIDE__) && !defined (TRACKER_COMPILATION)
+#error "only <libtracker-data/tracker-data.h> must be included directly."
+#endif
+
#include <glib.h>
#include <gio/gio.h>
-#include <libtracker-sparql/tracker-sparql.h>
-
-#include "tracker-db-interface.h"
-
G_BEGIN_DECLS
-#if !defined (__LIBTRACKER_DATA_INSIDE__) && !defined (TRACKER_COMPILATION)
-#error "only <libtracker-data/tracker-data.h> must be included directly."
-#endif
+typedef struct _TrackerData TrackerData;
+typedef struct _TrackerDataClass TrackerDataClass;
+
+#include <libtracker-sparql/tracker-sparql.h>
+#include "tracker-db-interface.h"
+#include "tracker-data-manager.h"
#define TRACKER_TYPE_DATA (tracker_data_get_type ())
#define TRACKER_DATA(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_DATA, TrackerData))
@@ -159,7 +162,7 @@ void tracker_data_remove_rollback_statement_callback (TrackerData
gpointer user_data);
GType tracker_data_get_type (void) G_GNUC_CONST;
-TrackerData * tracker_data_new (void);
+TrackerData * tracker_data_new (TrackerDataManager *manager);
G_END_DECLS
diff --git a/src/libtracker-data/tracker-db-manager.c b/src/libtracker-data/tracker-db-manager.c
index 18b0f73..4604b4c 100644
--- a/src/libtracker-data/tracker-db-manager.c
+++ b/src/libtracker-data/tracker-db-manager.c
@@ -129,6 +129,8 @@ struct _TrackerDBManager {
TrackerDBManagerFlags flags;
guint s_cache_size;
guint u_cache_size;
+
+ GWeakRef iface_data;
};
static gboolean db_exec_no_reply (TrackerDBInterface *iface,
@@ -568,6 +570,7 @@ tracker_db_manager_new (TrackerDBManagerFlags flags,
TrackerBusyCallback busy_callback,
gpointer busy_user_data,
const gchar *busy_operation,
+ GObject *iface_data,
GError **error)
{
TrackerDBManager *db_manager;
@@ -603,6 +606,7 @@ tracker_db_manager_new (TrackerDBManagerFlags flags,
g_set_object (&db_manager->cache_location, cache_location);
g_set_object (&db_manager->data_location, data_location);
+ g_weak_ref_init (&db_manager->iface_data, iface_data);
tracker_db_manager_ensure_locations (db_manager, cache_location, data_location);
db_manager->in_use_filename = g_build_filename (db_manager->user_data_dir,
@@ -915,6 +919,7 @@ tracker_db_manager_free (TrackerDBManager *db_manager)
{
g_free (db_manager->db.abs_filename);
g_clear_object (&db_manager->db.iface);
+ g_weak_ref_clear (&db_manager->iface_data);
g_free (db_manager->data_dir);
g_free (db_manager->user_data_dir);
@@ -980,6 +985,9 @@ tracker_db_manager_create_db_interface (TrackerDBManager *db_manager,
connection = tracker_db_interface_sqlite_new (db_manager->db.abs_filename,
flags,
&internal_error);
+ tracker_db_interface_set_user_data (connection,
+ g_weak_ref_get (&db_manager->iface_data),
+ g_object_unref);
if (internal_error) {
g_propagate_error (error, internal_error);
diff --git a/src/libtracker-data/tracker-db-manager.h b/src/libtracker-data/tracker-db-manager.h
index 3b1507c..becbd45 100644
--- a/src/libtracker-data/tracker-db-manager.h
+++ b/src/libtracker-data/tracker-db-manager.h
@@ -56,6 +56,7 @@ TrackerDBManager *tracker_db_manager_new (TrackerDBManagerF
TrackerBusyCallback busy_callback,
gpointer busy_user_data,
const gchar *busy_operation,
+ GObject *iface_data,
GError **error);
void tracker_db_manager_free (TrackerDBManager *db_manager);
void tracker_db_manager_remove_all (TrackerDBManager *db_manager);
diff --git a/src/libtracker-data/tracker-sparql-expression.vala
b/src/libtracker-data/tracker-sparql-expression.vala
index bc74cdc..8b1b122 100644
--- a/src/libtracker-data/tracker-sparql-expression.vala
+++ b/src/libtracker-data/tracker-sparql-expression.vala
@@ -34,8 +34,11 @@ class Tracker.Sparql.Expression : Object {
string? fts_sql;
+ Data.Manager manager;
+
public Expression (Query query) {
this.query = query;
+ this.manager = query.manager;
}
Context context {
@@ -853,7 +856,7 @@ class Tracker.Sparql.Expression : Object {
return PropertyType.STRING;
} else {
// support properties as functions
- var ontologies = Data.Manager.get_ontologies ();
+ var ontologies = 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 51dee71..bc05178 100644
--- a/src/libtracker-data/tracker-sparql-pattern.vala
+++ b/src/libtracker-data/tracker-sparql-pattern.vala
@@ -26,18 +26,24 @@ namespace Tracker.Sparql {
public Class? domain;
+ Data.Manager manager;
+
+ public PredicateVariable (Data.Manager manager) {
+ this.manager = manager;
+ }
+
public string get_sql_query (Query query) throws Sparql.Error {
try {
var sql = new StringBuilder ();
- var ontologies = Data.Manager.get_ontologies ();
+ var ontologies = manager.get_ontologies ();
if (subject != null) {
// single subject
- var subject_id = Data.query_resource_id (subject);
+ var subject_id = Data.query_resource_id (manager, subject);
DBCursor cursor = null;
if (subject_id > 0) {
- var iface = Data.Manager.get_db_interface ();
+ var iface = manager.get_db_interface ();
var stmt = iface.create_statement
(DBStatementCacheType.SELECT,
"SELECT (SELECT Uri FROM
Resource WHERE ID = \"rdf:type\") " +
"FROM
\"rdfs:Resource_rdf:type\" WHERE ID = ?");
@@ -84,9 +90,9 @@ namespace Tracker.Sparql {
}
} else if (object != null) {
// single object
- var object_id = Data.query_resource_id (object);
+ var object_id = Data.query_resource_id (manager, object);
- var iface = Data.Manager.get_db_interface ();
+ var iface = manager.get_db_interface ();
var stmt = iface.create_statement (DBStatementCacheType.SELECT,
"SELECT (SELECT Uri FROM Resource
WHERE ID = \"rdf:type\") " +
"FROM \"rdfs:Resource_rdf:type\"
WHERE ID = ?");
@@ -175,8 +181,11 @@ class Tracker.Sparql.Pattern : Object {
internal StringBuilder? match_str;
public bool queries_fts_data = false;
+ Data.Manager manager;
+
public Pattern (Query query) {
this.query = query;
+ this.manager = query.manager;
this.expression = query.expression;
}
@@ -879,7 +888,7 @@ class Tracker.Sparql.Pattern : Object {
} else {
return false;
}
- var ontologies = Data.Manager.get_ontologies ();
+ var ontologies = manager.get_ontologies ();
var prop = ontologies.get_property_by_uri (predicate);
if (prop == null) {
return false;
@@ -1353,7 +1362,7 @@ class Tracker.Sparql.Pattern : Object {
Class subject_type = null;
- var ontologies = Data.Manager.get_ontologies ();
+ var ontologies = manager.get_ontologies ();
if (!current_predicate_is_var) {
prop = ontologies.get_property_by_uri (current_predicate);
@@ -1390,7 +1399,7 @@ class Tracker.Sparql.Pattern : Object {
}
var pv = context.predicate_variable_map.lookup (context.get_variable
(current_subject));
if (pv == null) {
- pv = new PredicateVariable ();
+ pv = new PredicateVariable (manager);
context.predicate_variable_map.insert (context.get_variable
(current_subject), pv);
}
pv.domain = domain;
@@ -1465,7 +1474,7 @@ class Tracker.Sparql.Pattern : Object {
table = new DataTable ();
table.predicate_variable = context.predicate_variable_map.lookup
(context.get_variable (current_predicate));
if (table.predicate_variable == null) {
- table.predicate_variable = new PredicateVariable ();
+ table.predicate_variable = new PredicateVariable (manager);
context.predicate_variable_map.insert (context.get_variable
(current_predicate), table.predicate_variable);
}
if (!current_subject_is_var) {
diff --git a/src/libtracker-data/tracker-sparql-query.vala b/src/libtracker-data/tracker-sparql-query.vala
index 8ac954e..b24aa3e 100644
--- a/src/libtracker-data/tracker-sparql-query.vala
+++ b/src/libtracker-data/tracker-sparql-query.vala
@@ -242,12 +242,14 @@ public class Tracker.Sparql.Query : Object {
uchar[] base_uuid;
HashTable<string,string> blank_nodes;
+ public Data.Manager manager;
+
// Keep track of used SQL identifiers for SPARQL variables
public int last_var_index;
public bool no_cache { get; set; }
- public Query (string query) {
+ public Query (Data.Manager manager, string query) {
no_cache = false; /* Start with false, expression sets it */
tokens = new TokenInfo[BUFFER_SIZE];
prefix_map = new HashTable<string,string>.full (str_hash, str_equal, g_free, g_free);
@@ -256,13 +258,14 @@ public class Tracker.Sparql.Query : Object {
uuid_generate (base_uuid);
this.query_string = query;
+ this.manager = manager;
expression = new Expression (this);
pattern = new Pattern (this);
}
- public Query.update (string query) {
- this (query);
+ public Query.update (Data.Manager manager, string query) {
+ this (manager, query);
this.update_extensions = true;
}
@@ -298,7 +301,7 @@ public class Tracker.Sparql.Query : Object {
uri = get_uuid_for_name (base_uuid, user_bnodeid);
if (blank_nodes != null) {
- while (Data.query_resource_id (uri) > 0) {
+ while (Data.query_resource_id (manager, uri) > 0) {
// uri collision, generate new UUID
uchar[] new_base_uuid = new uchar[16];
uuid_generate (new_base_uuid);
@@ -404,7 +407,7 @@ public class Tracker.Sparql.Query : Object {
// declare fn prefix for XPath functions
prefix_map.insert ("fn", FN_NS);
- var ontologies = Data.Manager.get_ontologies ();
+ var ontologies = manager.get_ontologies ();
foreach (Namespace ns in ontologies.get_namespaces ()) {
if (ns.prefix == null) {
@@ -449,7 +452,7 @@ public class Tracker.Sparql.Query : Object {
// declare fn prefix for XPath functions
prefix_map.insert ("fn", FN_NS);
- var ontologies = Data.Manager.get_ontologies ();
+ var ontologies = manager.get_ontologies ();
foreach (Namespace ns in ontologies.get_namespaces ()) {
if (ns.prefix == null) {
@@ -505,7 +508,7 @@ public class Tracker.Sparql.Query : Object {
}
DBStatement prepare_for_exec (string sql) throws DBInterfaceError, Sparql.Error, DateError {
- var iface = Data.Manager.get_db_interface ();
+ var iface = manager.get_db_interface ();
if (iface == null) {
throw new DBInterfaceError.OPEN_ERROR ("Error opening database");
}
@@ -628,7 +631,7 @@ public class Tracker.Sparql.Query : Object {
bool delete_where = false;
bool data = false;
- var data_update = Data.Manager.get_data ();
+ var data_update = manager.get_data ();
// Sparql 1.1 defines deletes/inserts as a single
// operation with the syntax:
@@ -1055,7 +1058,7 @@ public class Tracker.Sparql.Query : Object {
void parse_construct_object (Solution var_value_map, UpdateType type) throws Sparql.Error, DateError {
bool is_null = false;
string object = parse_construct_var_or_term (var_value_map, type, out is_null);
- var data = Data.Manager.get_data ();
+ var data = manager.get_data ();
if (current_subject == null || current_predicate == null || object == null) {
// the SPARQL specification says that triples containing unbound variables
// should be excluded from the output RDF graph of CONSTRUCT
diff --git a/src/libtracker-data/tracker-turtle-reader.vala b/src/libtracker-data/tracker-turtle-reader.vala
index f029bdc..abc50e0 100644
--- a/src/libtracker-data/tracker-turtle-reader.vala
+++ b/src/libtracker-data/tracker-turtle-reader.vala
@@ -380,8 +380,7 @@ public class Tracker.TurtleReader : Object {
}
}
- public static void load (File file) throws Error, FileError, Sparql.Error, DateError,
DBInterfaceError {
- var data = Data.Manager.get_data ();
+ public static void load (File file, Data.Update data) throws Error, FileError, Sparql.Error,
DateError, DBInterfaceError {
try {
data.begin_transaction ();
diff --git a/src/libtracker-direct/tracker-direct.vala b/src/libtracker-direct/tracker-direct.vala
index ed94553..b12ccc4 100644
--- a/src/libtracker-direct/tracker-direct.vala
+++ b/src/libtracker-direct/tracker-direct.vala
@@ -24,6 +24,8 @@ public class Tracker.Direct.Connection : Tracker.Sparql.Connection, AsyncInitabl
File? ontology_loc;
Sparql.ConnectionFlags flags;
+ Data.Manager data_manager;
+
// Mutex to hold datamanager
private Mutex mutex = Mutex ();
Thread<void*> thread;
@@ -96,9 +98,8 @@ public class Tracker.Direct.Connection : Tracker.Sparql.Connection, AsyncInitabl
}
}
- static void wal_checkpoint_on_thread () {
+ static void wal_checkpoint_on_thread (DBInterface iface) {
new Thread<void*> ("wal-checkpoint", () => {
- var iface = Data.Manager.get_db_interface ();
wal_checkpoint (iface, false);
return null;
});
@@ -110,7 +111,7 @@ public class Tracker.Direct.Connection : Tracker.Sparql.Connection, AsyncInitabl
// to prevent excessive wal file growth
wal_checkpoint (iface, true);
} else if (n_pages >= 1000) {
- wal_checkpoint_on_thread ();
+ wal_checkpoint_on_thread (iface);
}
}
@@ -122,11 +123,13 @@ public class Tracker.Direct.Connection : Tracker.Sparql.Connection, AsyncInitabl
DBManagerFlags db_flags = DBManagerFlags.ENABLE_MUTEXES;
if ((flags & Sparql.ConnectionFlags.READONLY) != 0)
db_flags |= DBManagerFlags.READONLY;
- Data.Manager.init (db_flags,
- database_loc, journal_loc, ontology_loc,
- null, false, false, 100, 100, null, null);
- var iface = Data.Manager.get_db_interface ();
+ data_manager = new Data.Manager (db_flags,
+ database_loc, journal_loc, ontology_loc,
+ false, false, 100, 100);
+ data_manager.init ();
+
+ var iface = data_manager.get_db_interface ();
iface.sqlite_wal_hook (wal_hook);
} catch (Error e) {
init_error = e;
@@ -207,18 +210,9 @@ public class Tracker.Direct.Connection : Tracker.Sparql.Connection, AsyncInitabl
update_queue = new AsyncQueue<Task> ();
}
- ~Connection () {
- if (!initialized) {
- return;
- }
-
- // Clean up connection
- Data.Manager.shutdown ();
- }
-
Sparql.Cursor query_unlocked (string sparql) throws Sparql.Error, DBusError {
try {
- var query_object = new Sparql.Query (sparql);
+ var query_object = new Sparql.Query (data_manager, sparql);
var cursor = query_object.execute_cursor ();
cursor.connection = this;
return cursor;
@@ -289,7 +283,7 @@ public class Tracker.Direct.Connection : Tracker.Sparql.Connection, AsyncInitabl
public override void update (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable?
cancellable = null) throws Sparql.Error, IOError, DBusError, GLib.Error {
mutex.lock ();
try {
- var data = Data.Manager.get_data ();
+ var data = data_manager.get_data ();
data.update_sparql (sparql);
} finally {
mutex.unlock ();
@@ -310,7 +304,7 @@ public class Tracker.Direct.Connection : Tracker.Sparql.Connection, AsyncInitabl
GLib.Variant? blank_nodes = null;
mutex.lock ();
try {
- var data = Data.Manager.get_data ();
+ var data = data_manager.get_data ();
blank_nodes = data.update_sparql_blank (sparql);
} finally {
mutex.unlock ();
@@ -334,7 +328,7 @@ public class Tracker.Direct.Connection : Tracker.Sparql.Connection, AsyncInitabl
public override void load (File file, Cancellable? cancellable = null) throws Sparql.Error, IOError,
DBusError {
mutex.lock ();
try {
- var data = Data.Manager.get_data ();
+ var data = data_manager.get_data ();
data.load_turtle_file (file);
} finally {
mutex.unlock ();
diff --git a/src/libtracker-fts/tracker-fts-tokenizer.c b/src/libtracker-fts/tracker-fts-tokenizer.c
index fed3c7e..a9f09e8 100644
--- a/src/libtracker-fts/tracker-fts-tokenizer.c
+++ b/src/libtracker-fts/tracker-fts-tokenizer.c
@@ -272,16 +272,18 @@ tracker_offsets_function (const Fts5ExtensionApi *api,
}
static GHashTable *
-get_fts_weights (sqlite3_context *context)
+get_fts_weights (TrackerDBInterface *iface,
+ sqlite3_context *context)
{
static GHashTable *weights = NULL;
static GMutex mutex;
int rc = SQLITE_DONE;
- TrackerOntologies *ontologies;
g_mutex_lock (&mutex);
if (G_UNLIKELY (weights == NULL)) {
+ TrackerDataManager *manager;
+ TrackerOntologies *ontologies;
sqlite3_stmt *stmt;
sqlite3 *db;
const gchar *uri;
@@ -295,7 +297,8 @@ get_fts_weights (sqlite3_context *context)
"WHERE \"rdf:Property\".\"tracker:fulltextIndexed\" = 1 ",
-1, &stmt, NULL);
- ontologies = tracker_data_manager_get_ontologies ();
+ manager = tracker_db_interface_get_user_data (iface);
+ ontologies = tracker_data_manager_get_ontologies (manager);
while ((rc = sqlite3_step (stmt)) != SQLITE_DONE) {
if (rc == SQLITE_ROW) {
@@ -346,7 +349,7 @@ tracker_rank_function (const Fts5ExtensionApi *api,
n_columns = api->xColumnCount (fts_ctx);
data = api->xUserData (fts_ctx);
- weights = get_fts_weights (ctx);
+ weights = get_fts_weights (data->interface, ctx);
if (!weights) {
sqlite3_result_error (ctx, "Could not read FTS weights", -1);
diff --git a/src/tracker-store/tracker-backup.vala b/src/tracker-store/tracker-backup.vala
index 70a6379..1b01b81 100644
--- a/src/tracker-store/tracker-backup.vala
+++ b/src/tracker-store/tracker-backup.vala
@@ -56,7 +56,7 @@ public class Tracker.Backup : Object {
throw e;
} finally {
if (resources != null) {
- Tracker.Events.init ();
+ Tracker.Events.init (Tracker.Main.get_data_manager ());
resources.enable_signals ();
}
@@ -83,9 +83,10 @@ public class Tracker.Backup : Object {
var notifier = (Status) (Tracker.DBus.get_object (typeof (Status)));
var busy_callback = notifier.get_callback ();
+ var data_manager = Tracker.Main.get_data_manager ();
// TODO: set cache_location, data_location and ontology_location here from store
session
- Data.backup_restore (journal, null, null, null, busy_callback);
+ Data.backup_restore (data_manager, journal, null, null, null, busy_callback);
request.end ();
} catch (Error e) {
@@ -93,7 +94,7 @@ public class Tracker.Backup : Object {
throw e;
} finally {
if (resources != null) {
- Tracker.Events.init ();
+ Tracker.Events.init (Tracker.Main.get_data_manager ());
resources.enable_signals ();
}
diff --git a/src/tracker-store/tracker-events.c b/src/tracker-store/tracker-events.c
index 27827fe..199dced 100644
--- a/src/tracker-store/tracker-events.c
+++ b/src/tracker-store/tracker-events.c
@@ -165,7 +165,7 @@ tracker_events_get_classes (guint *length)
}
void
-tracker_events_init (void)
+tracker_events_init (TrackerDataManager *data_manager)
{
TrackerOntologies *ontologies;
TrackerClass **classes;
@@ -173,7 +173,7 @@ tracker_events_init (void)
private = g_new0 (EventsPrivate, 1);
- ontologies = tracker_data_manager_get_ontologies ();
+ ontologies = tracker_data_manager_get_ontologies (data_manager);
classes = tracker_ontologies_get_classes (ontologies, &length);
private->notify_classes = g_ptr_array_sized_new (length);
diff --git a/src/tracker-store/tracker-events.h b/src/tracker-store/tracker-events.h
index 26f5ccb..df9322f 100644
--- a/src/tracker-store/tracker-events.h
+++ b/src/tracker-store/tracker-events.h
@@ -30,7 +30,7 @@ G_BEGIN_DECLS
typedef GStrv (*TrackerNotifyClassGetter) (void);
-void tracker_events_init (void);
+void tracker_events_init (TrackerDataManager *data_manager);
void tracker_events_shutdown (void);
void tracker_events_add_insert (gint graph_id,
gint subject_id,
diff --git a/src/tracker-store/tracker-events.vapi b/src/tracker-store/tracker-events.vapi
index f9f7787..c232d8a 100644
--- a/src/tracker-store/tracker-events.vapi
+++ b/src/tracker-store/tracker-events.vapi
@@ -20,7 +20,7 @@
namespace Tracker {
[CCode (cheader_filename = "tracker-store/tracker-events.h")]
namespace Events {
- public void init ();
+ public void init (Tracker.Data.Manager data_manager);
public void shutdown ();
public void add_insert (int graph_id, int subject_id, string subject, int pred_id, int
object_id, string object, GLib.PtrArray rdf_types);
public void add_delete (int graph_id, int subject_id, string subject, int pred_id, int
object_id, string object, GLib.PtrArray rdf_types);
diff --git a/src/tracker-store/tracker-main.vala b/src/tracker-store/tracker-main.vala
index de2f907..ccd1107 100644
--- a/src/tracker-store/tracker-main.vala
+++ b/src/tracker-store/tracker-main.vala
@@ -39,6 +39,8 @@ License which can be viewed at:
static bool shutdown;
+ static Tracker.Data.Manager data_manager;
+
/* Private command line parameters */
static bool version;
static int verbosity;
@@ -158,7 +160,7 @@ License which can be viewed at:
string[] predicates_to_signal = null;
try {
- var cursor = Tracker.Data.query_sparql_cursor ("SELECT ?predicate WHERE { ?predicate
tracker:writeback true }");
+ var cursor = Tracker.Data.query_sparql_cursor (data_manager, "SELECT ?predicate WHERE
{ ?predicate tracker:writeback true }");
while (cursor.next ()) {
predicates_to_signal += cursor.get_string (0);
@@ -180,6 +182,10 @@ License which can be viewed at:
Tracker.DBusRequest.enable_client_lookup (verbosity > 0);
}
+ public static unowned Tracker.Data.Manager get_data_manager () {
+ return data_manager;
+ }
+
static int main (string[] args) {
Intl.setlocale (LocaleCategory.ALL, "");
@@ -342,8 +348,6 @@ License which can be viewed at:
update_cache_size = UPDATE_CACHE_SIZE;
}
- bool is_first_time_index;
-
try {
File final_cache_location = cache_location != null ?
File.new_for_path (cache_location.replace ("%HOME%",
Environment.get_home_dir()).replace("%SHAREDIR%", SHAREDIR)) :
@@ -359,17 +363,15 @@ License which can be viewed at:
if (env_ontology != null && env_ontology != "")
final_ontology_location = File.new_for_path (env_ontology);
- Tracker.Data.Manager.init (flags,
- final_cache_location,
- final_data_location,
- final_ontology_location,
- out is_first_time_index,
- true,
- false,
- select_cache_size,
- update_cache_size,
- busy_callback,
- "Initializing");
+ data_manager = new Tracker.Data.Manager (flags,
+ final_cache_location,
+ final_data_location,
+ final_ontology_location,
+ true,
+ false,
+ select_cache_size,
+ update_cache_size);
+ data_manager.init (null);
} catch (GLib.Error e) {
critical ("Cannot initialize database: %s", e.message);
return 1;
@@ -381,8 +383,8 @@ License which can be viewed at:
if (!shutdown) {
Tracker.DBus.register_prepare_class_signal ();
- Tracker.Events.init ();
- Tracker.Writeback.init (get_writeback_predicates);
+ Tracker.Events.init (data_manager);
+ Tracker.Writeback.init (data_manager, get_writeback_predicates);
Tracker.Store.resume ();
message ("Waiting for D-Bus requests...");
@@ -414,8 +416,8 @@ License which can be viewed at:
Tracker.Writeback.shutdown ();
Tracker.Events.shutdown ();
+ data_manager = null;
Tracker.DBus.shutdown (domain, dbus_path, ontology_name);
- Tracker.Data.Manager.shutdown ();
Tracker.Log.shutdown ();
config.disconnect (config_verbosity_id);
diff --git a/src/tracker-store/tracker-resources.vala b/src/tracker-store/tracker-resources.vala
index b35ab61..2f524f6 100644
--- a/src/tracker-store/tracker-resources.vala
+++ b/src/tracker-store/tracker-resources.vala
@@ -66,8 +66,9 @@ public class Tracker.Resources : Object {
var request = DBusRequest.begin (sender, "Resources.Load (uri: '%s')", uri);
try {
var file = File.new_for_uri (uri);
+ var data_manager = Tracker.Main.get_data_manager ();
- yield Tracker.Store.queue_turtle_import (file, sender);
+ yield Tracker.Store.queue_turtle_import (data_manager, file, sender);
request.end ();
} catch (DBInterfaceError.NO_SPACE ie) {
@@ -88,8 +89,9 @@ public class Tracker.Resources : Object {
request.debug ("query: %s", query);
try {
var builder = new VariantBuilder ((VariantType) "aas");
+ var data_manager = Tracker.Main.get_data_manager ();
- yield Tracker.Store.sparql_query (query, Tracker.Store.Priority.HIGH, cursor => {
+ yield Tracker.Store.sparql_query (data_manager, query, Tracker.Store.Priority.HIGH,
cursor => {
while (cursor.next ()) {
builder.open ((VariantType) "as");
@@ -129,7 +131,8 @@ public class Tracker.Resources : Object {
var request = DBusRequest.begin (sender, "Resources.SparqlUpdate");
request.debug ("query: %s", update);
try {
- yield Tracker.Store.sparql_update (update, Tracker.Store.Priority.HIGH, sender);
+ var data_manager = Tracker.Main.get_data_manager ();
+ yield Tracker.Store.sparql_update (data_manager, update, Tracker.Store.Priority.HIGH,
sender);
request.end ();
} catch (DBInterfaceError.NO_SPACE ie) {
@@ -149,7 +152,8 @@ public class Tracker.Resources : Object {
var request = DBusRequest.begin (sender, "Resources.SparqlUpdateBlank");
request.debug ("query: %s", update);
try {
- var variant = yield Tracker.Store.sparql_update_blank (update,
Tracker.Store.Priority.HIGH, sender);
+ var data_manager = Tracker.Main.get_data_manager ();
+ var variant = yield Tracker.Store.sparql_update_blank (data_manager, update,
Tracker.Store.Priority.HIGH, sender);
request.end ();
@@ -168,10 +172,12 @@ public class Tracker.Resources : Object {
public void sync (BusName sender) {
var request = DBusRequest.begin (sender, "Resources.Sync");
- var data = Data.Manager.get_data ();
+ var data_manager = Tracker.Main.get_data_manager ();
+ var data = data_manager.get_data ();
+ var iface = data_manager.get_db_interface ();
// wal checkpoint implies sync
- Tracker.Store.wal_checkpoint ();
+ Tracker.Store.wal_checkpoint (iface);
// sync journal if available
data.sync ();
@@ -182,7 +188,8 @@ public class Tracker.Resources : Object {
var request = DBusRequest.begin (sender, "Resources.BatchSparqlUpdate");
request.debug ("query: %s", update);
try {
- yield Tracker.Store.sparql_update (update, Tracker.Store.Priority.LOW, sender);
+ var data_manager = Tracker.Main.get_data_manager ();
+ yield Tracker.Store.sparql_update (data_manager, update, Tracker.Store.Priority.LOW,
sender);
request.end ();
} catch (DBInterfaceError.NO_SPACE ie) {
@@ -338,7 +345,8 @@ public class Tracker.Resources : Object {
[DBus (visible = false)]
public void enable_signals () {
- var data = Data.Manager.get_data ();
+ var data_manager = Tracker.Main.get_data_manager ();
+ var data = data_manager.get_data ();
data.add_insert_statement_callback (on_statement_inserted);
data.add_delete_statement_callback (on_statement_deleted);
data.add_commit_statement_callback (on_statements_committed);
@@ -347,7 +355,8 @@ public class Tracker.Resources : Object {
[DBus (visible = false)]
public void disable_signals () {
- var data = Data.Manager.get_data ();
+ var data_manager = Tracker.Main.get_data_manager ();
+ var data = data_manager.get_data ();
data.remove_insert_statement_callback (on_statement_inserted);
data.remove_delete_statement_callback (on_statement_deleted);
data.remove_commit_statement_callback (on_statements_committed);
diff --git a/src/tracker-store/tracker-statistics.vala b/src/tracker-store/tracker-statistics.vala
index 8a1a81d..e7f9a01 100644
--- a/src/tracker-store/tracker-statistics.vala
+++ b/src/tracker-store/tracker-statistics.vala
@@ -26,10 +26,11 @@ 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 ();
+ var data_manager = Tracker.Main.get_data_manager ();
+ var ontologies = data_manager.get_ontologies ();
if (!initialized) {
- var iface = Data.Manager.get_db_interface ();
+ var iface = data_manager.get_db_interface ();
foreach (var cl in ontologies.get_classes ()) {
/* xsd classes do not derive from rdfs:Resource and do not use separate
tables */
diff --git a/src/tracker-store/tracker-status.vala b/src/tracker-store/tracker-status.vala
index 430c802..002760f 100644
--- a/src/tracker-store/tracker-status.vala
+++ b/src/tracker-store/tracker-status.vala
@@ -110,7 +110,7 @@ public class Tracker.Status : Object {
}
public async void wait () throws Error {
- if (_progress == 1) {
+ if (status == "Idle") {
/* tracker-store is idle */
} else {
var context = new WaitContext ();
diff --git a/src/tracker-store/tracker-steroids.vala b/src/tracker-store/tracker-steroids.vala
index 67832f8..40679bf 100644
--- a/src/tracker-store/tracker-steroids.vala
+++ b/src/tracker-store/tracker-steroids.vala
@@ -29,8 +29,9 @@ public class Tracker.Steroids : Object {
request.debug ("query: %s", query);
try {
string[] variable_names = null;
+ var data_manager = Tracker.Main.get_data_manager ();
- yield Tracker.Store.sparql_query (query, Tracker.Store.Priority.HIGH, cursor => {
+ yield Tracker.Store.sparql_query (data_manager, query, Tracker.Store.Priority.HIGH,
cursor => {
var data_output_stream = new DataOutputStream (new BufferedOutputStream.sized
(output_stream, BUFFER_SIZE));
data_output_stream.set_byte_order (DataStreamByteOrder.HOST_ENDIAN);
@@ -111,15 +112,16 @@ public class Tracker.Steroids : Object {
data_input_stream = null;
request.debug ("query: %s", (string) query);
+ var data_manager = Tracker.Main.get_data_manager ();
if (!blank) {
- yield Tracker.Store.sparql_update ((string) query, priority, sender);
+ yield Tracker.Store.sparql_update (data_manager, (string) query, priority,
sender);
request.end ();
return null;
} else {
- var variant = yield Tracker.Store.sparql_update_blank ((string) query,
priority, sender);
+ var variant = yield Tracker.Store.sparql_update_blank (data_manager, (string)
query, priority, sender);
request.end ();
@@ -186,10 +188,11 @@ public class Tracker.Steroids : Object {
data_input_stream = null;
var builder = new VariantBuilder ((VariantType) "as");
+ var data_manager = Tracker.Main.get_data_manager ();
// first try combined query for best possible performance
try {
- yield Tracker.Store.sparql_update (combined_query.str,
Tracker.Store.Priority.LOW, sender);
+ yield Tracker.Store.sparql_update (data_manager, combined_query.str,
Tracker.Store.Priority.LOW, sender);
// combined query was successful
for (i = 0; i < query_count; i++) {
@@ -210,7 +213,7 @@ public class Tracker.Steroids : Object {
request.debug ("query: %s", query_array[i]);
try {
- yield Tracker.Store.sparql_update (query_array[i],
Tracker.Store.Priority.LOW, sender);
+ yield Tracker.Store.sparql_update (data_manager, query_array[i],
Tracker.Store.Priority.LOW, sender);
builder.add ("s", "");
builder.add ("s", "");
} catch (Error e1) {
diff --git a/src/tracker-store/tracker-store.vala b/src/tracker-store/tracker-store.vala
index a9362f7..4445575 100644
--- a/src/tracker-store/tracker-store.vala
+++ b/src/tracker-store/tracker-store.vala
@@ -30,7 +30,7 @@ public class Tracker.Store {
static bool update_running;
static ThreadPool<Task> update_pool;
static ThreadPool<Task> query_pool;
- static ThreadPool<bool> checkpoint_pool;
+ static ThreadPool<DBInterface> checkpoint_pool;
static GenericArray<Task> running_tasks;
static int max_task_time;
static bool active;
@@ -57,6 +57,7 @@ public class Tracker.Store {
public string client_id;
public Error error;
public SourceFunc callback;
+ public Tracker.Data.Manager data_manager;
}
class QueryTask : Task {
@@ -161,7 +162,7 @@ public class Tracker.Store {
}
static bool task_finish_cb (Task task) {
- var data = Data.Manager.get_data ();
+ var data = task.data_manager.get_data ();
if (task.type == TaskType.QUERY) {
var query_task = (QueryTask) task;
@@ -211,12 +212,12 @@ public class Tracker.Store {
if (task.type == TaskType.QUERY) {
var query_task = (QueryTask) task;
- var cursor = Tracker.Data.query_sparql_cursor (query_task.query);
+ var cursor = Tracker.Data.query_sparql_cursor (task.data_manager,
query_task.query);
query_task.in_thread (cursor);
} else {
- var data = Data.Manager.get_data ();
- var iface = Data.Manager.get_db_interface ();
+ var data = task.data_manager.get_data ();
+ var iface = task.data_manager.get_db_interface ();
iface.sqlite_wal_hook (wal_hook);
if (task.type == TaskType.UPDATE) {
@@ -250,10 +251,9 @@ public class Tracker.Store {
});
}
- public static void wal_checkpoint () {
+ public static void wal_checkpoint (DBInterface iface) {
try {
debug ("Checkpointing database...");
- var iface = Data.Manager.get_db_interface ();
iface.execute_query ("PRAGMA wal_checkpoint");
debug ("Checkpointing complete...");
} catch (Error e) {
@@ -271,12 +271,12 @@ public class Tracker.Store {
if (n_pages >= 10000) {
// do immediate checkpointing (blocking updates)
// to prevent excessive wal file growth
- wal_checkpoint ();
+ wal_checkpoint (iface);
} else if (n_pages >= 1000) {
if (AtomicInt.compare_and_exchange (ref checkpointing, 0, 1)) {
// initiate asynchronous checkpointing (not blocking updates)
try {
- checkpoint_pool.push (true);
+ checkpoint_pool.push (iface);
} catch (Error e) {
warning (e.message);
AtomicInt.set (ref checkpointing, 0);
@@ -285,10 +285,10 @@ public class Tracker.Store {
}
}
- static void checkpoint_dispatch_cb (bool task) {
+ static void checkpoint_dispatch_cb (DBInterface iface) {
// run in checkpoint thread
- wal_checkpoint ();
+ wal_checkpoint (iface);
AtomicInt.set (ref checkpointing, 0);
}
@@ -310,7 +310,7 @@ public class Tracker.Store {
try {
update_pool = new ThreadPool<Task>.with_owned_data (pool_dispatch_cb, 1, true);
query_pool = new ThreadPool<Task>.with_owned_data (pool_dispatch_cb,
MAX_CONCURRENT_QUERIES, true);
- checkpoint_pool = new ThreadPool<bool>.with_owned_data (checkpoint_dispatch_cb, 1,
true);
+ checkpoint_pool = new ThreadPool<DBInterface> (checkpoint_dispatch_cb, 1, true);
} catch (Error e) {
warning (e.message);
}
@@ -333,7 +333,7 @@ public class Tracker.Store {
}
}
- public static async void sparql_query (string sparql, Priority priority, SparqlQueryInThread
in_thread, string client_id) throws Error {
+ public static async void sparql_query (Tracker.Data.Manager manager, string sparql, Priority
priority, SparqlQueryInThread in_thread, string client_id) throws Error {
var task = new QueryTask ();
task.type = TaskType.QUERY;
task.query = sparql;
@@ -341,6 +341,7 @@ public class Tracker.Store {
task.in_thread = in_thread;
task.callback = sparql_query.callback;
task.client_id = client_id;
+ task.data_manager = manager;
query_queues[priority].push_tail (task);
@@ -353,13 +354,14 @@ public class Tracker.Store {
}
}
- public static async void sparql_update (string sparql, Priority priority, string client_id) throws
Error {
+ public static async void sparql_update (Tracker.Data.Manager manager, string sparql, Priority
priority, string client_id) throws Error {
var task = new UpdateTask ();
task.type = TaskType.UPDATE;
task.query = sparql;
task.priority = priority;
task.callback = sparql_update.callback;
task.client_id = client_id;
+ task.data_manager = manager;
update_queues[priority].push_tail (task);
@@ -372,13 +374,14 @@ public class Tracker.Store {
}
}
- public static async Variant sparql_update_blank (string sparql, Priority priority, string client_id)
throws Error {
+ public static async Variant sparql_update_blank (Tracker.Data.Manager manager, string sparql,
Priority priority, string client_id) throws Error {
var task = new UpdateTask ();
task.type = TaskType.UPDATE_BLANK;
task.query = sparql;
task.priority = priority;
task.callback = sparql_update_blank.callback;
task.client_id = client_id;
+ task.data_manager = manager;
update_queues[priority].push_tail (task);
@@ -393,12 +396,13 @@ public class Tracker.Store {
return task.blank_nodes;
}
- public static async void queue_turtle_import (File file, string client_id) throws Error {
+ public static async void queue_turtle_import (Tracker.Data.Manager manager, File file, string
client_id) throws Error {
var task = new TurtleTask ();
task.type = TaskType.TURTLE;
task.path = file.get_path ();
task.callback = queue_turtle_import.callback;
task.client_id = client_id;
+ task.data_manager = manager;
update_queues[Priority.TURTLE].push_tail (task);
@@ -480,7 +484,7 @@ public class Tracker.Store {
// this will wait for checkpointing to finish
checkpoint_pool = null;
try {
- checkpoint_pool = new ThreadPool<bool> (checkpoint_dispatch_cb, 1, true);
+ checkpoint_pool = new ThreadPool<DBInterface> (checkpoint_dispatch_cb, 1,
true);
} catch (Error e) {
warning (e.message);
}
diff --git a/src/tracker-store/tracker-writeback.c b/src/tracker-store/tracker-writeback.c
index 4882cf1..a183b00 100644
--- a/src/tracker-store/tracker-writeback.c
+++ b/src/tracker-store/tracker-writeback.c
@@ -135,7 +135,8 @@ free_private (gpointer user_data)
}
void
-tracker_writeback_init (TrackerWritebackGetPredicatesFunc func)
+tracker_writeback_init (TrackerDataManager *data_manager,
+ TrackerWritebackGetPredicatesFunc func)
{
TrackerOntologies *ontologies;
GStrv predicates_to_signal;
@@ -165,7 +166,7 @@ tracker_writeback_init (TrackerWritebackGetPredicatesFunc func)
}
count = g_strv_length (predicates_to_signal);
- ontologies = tracker_data_manager_get_ontologies ();
+ ontologies = tracker_data_manager_get_ontologies (data_manager);
for (i = 0; i < count; i++) {
TrackerProperty *predicate = tracker_ontologies_get_property_by_uri (ontologies,
predicates_to_signal[i]);
diff --git a/src/tracker-store/tracker-writeback.h b/src/tracker-store/tracker-writeback.h
index 676891f..57d09da 100644
--- a/src/tracker-store/tracker-writeback.h
+++ b/src/tracker-store/tracker-writeback.h
@@ -29,7 +29,8 @@ G_BEGIN_DECLS
typedef GStrv (*TrackerWritebackGetPredicatesFunc) ();
-void tracker_writeback_init (TrackerWritebackGetPredicatesFunc callback);
+void tracker_writeback_init (TrackerDataManager *data_manager,
+ TrackerWritebackGetPredicatesFunc callback);
void tracker_writeback_shutdown (void);
void tracker_writeback_check (gint graph_id,
const gchar *graph,
diff --git a/src/tracker-store/tracker-writeback.vapi b/src/tracker-store/tracker-writeback.vapi
index 1c50eca..f51fa25 100644
--- a/src/tracker-store/tracker-writeback.vapi
+++ b/src/tracker-store/tracker-writeback.vapi
@@ -23,7 +23,7 @@ namespace Tracker {
[CCode (cheader_filename = "tracker-store/tracker-writeback.h")]
namespace Writeback {
- public void init (WritebackGetPredicatesFunc callback);
+ public void init (Tracker.Data.Manager data_manager, WritebackGetPredicatesFunc callback);
public void shutdown ();
public void check (int graph_id, string graph, int subject_id, string subject, int pred_id,
int object_id, string object, GLib.PtrArray rdf_types);
public unowned GLib.HashTable<int, GLib.Array<int>> get_ready ();
diff --git a/src/tracker/tracker-reset.c b/src/tracker/tracker-reset.c
index 158b8d2..fa7a2ee 100644
--- a/src/tracker/tracker-reset.c
+++ b/src/tracker/tracker-reset.c
@@ -313,6 +313,7 @@ reset_run (void)
NULL,
NULL,
NULL,
+ NULL,
&error);
if (!db_manager) {
diff --git a/src/tracker/tracker-sql.c b/src/tracker/tracker-sql.c
index 76f6af8..8843887 100644
--- a/src/tracker/tracker-sql.c
+++ b/src/tracker/tracker-sql.c
@@ -94,9 +94,9 @@ sql_by_query (void)
TrackerDBStatement *stmt;
TrackerDBCursor *cursor = NULL;
GError *error = NULL;
- gboolean first_time = FALSE;
gint n_rows = 0;
GFile *cache_location, *data_location, *ontology_location;
+ TrackerDataManager *data_manager;
gchar *dir;
dir = g_build_filename (g_get_user_cache_dir (), "tracker", NULL);
@@ -111,17 +111,11 @@ sql_by_query (void)
ontology_location = g_file_new_for_path (dir);
g_free (dir);
- if (!tracker_data_manager_init (0, cache_location,
- data_location, ontology_location,
- &first_time,
- FALSE,
- FALSE,
- 100,
- 100,
- NULL,
- NULL,
- NULL,
- &error)) {
+ data_manager = tracker_data_manager_new (0, cache_location,
+ data_location, ontology_location,
+ FALSE, FALSE, 100, 100);
+
+ if (!g_initable_init (G_INITABLE (data_manager), NULL, &error)) {
g_printerr ("%s: %s\n",
_("Failed to initialize data manager"),
error->message);
@@ -132,7 +126,7 @@ sql_by_query (void)
g_print ("--------------------------------------------------\n");
g_print ("\n\n");
- iface = tracker_data_manager_get_db_interface ();
+ iface = tracker_data_manager_get_db_interface (data_manager);
stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_NONE, &error,
"%s", query);
diff --git a/tests/libtracker-data/tracker-backup-test.c b/tests/libtracker-data/tracker-backup-test.c
index 30c5d9b..f267217 100644
--- a/tests/libtracker-data/tracker-backup-test.c
+++ b/tests/libtracker-data/tracker-backup-test.c
@@ -60,8 +60,9 @@ backup_finished_cb (GError *error,
}
static gboolean
-check_content_in_db (gint expected_instances,
- gint expected_relations)
+check_content_in_db (TrackerDataManager *manager,
+ gint expected_instances,
+ gint expected_relations)
{
GError *error = NULL;
const gchar *query_instances_1 = "SELECT ?u WHERE { ?u a foo:class1. }";
@@ -69,7 +70,7 @@ check_content_in_db (gint expected_instances,
TrackerDBCursor *cursor;
gint n_rows;
- cursor = tracker_data_query_sparql_cursor (query_instances_1, &error);
+ cursor = tracker_data_query_sparql_cursor (manager, query_instances_1, &error);
g_assert_no_error (error);
n_rows = 0;
while (tracker_db_cursor_iter_next (cursor, NULL, &error)) {
@@ -79,7 +80,7 @@ check_content_in_db (gint expected_instances,
g_assert_cmpint (n_rows, ==, expected_instances);
g_object_unref (cursor);
- cursor = tracker_data_query_sparql_cursor (query_relation, &error);
+ cursor = tracker_data_query_sparql_cursor (manager, query_relation, &error);
g_assert_no_error (error);
n_rows = 0;
while (tracker_db_cursor_iter_next (cursor, NULL, &error)) {
@@ -108,6 +109,8 @@ test_backup_and_restore_helper (const gchar *db_location,
GError *error = NULL;
GFile *backup_file;
GFile *data_location, *test_schemas;
+ TrackerDataManager *manager;
+ TrackerData *data_update;
data_location = g_file_new_for_path (db_location);
@@ -122,18 +125,18 @@ test_backup_and_restore_helper (const gchar *db_location,
tracker_db_journal_set_rotating (FALSE, G_MAXSIZE, NULL);
- tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
- data_location, data_location, test_schemas,
- NULL, FALSE, FALSE,
- 100, 100, NULL, NULL, NULL, &error);
-
+ manager = tracker_data_manager_new (TRACKER_DB_MANAGER_FORCE_REINDEX,
+ data_location, data_location, test_schemas,
+ FALSE, FALSE, 100, 100);
+ g_initable_init (G_INITABLE (manager), NULL, &error);
g_assert_no_error (error);
/* load data set */
data_filename = g_strconcat (data_prefix, ".data", NULL);
if (g_file_test (data_filename, G_FILE_TEST_IS_REGULAR)) {
GFile *file = g_file_new_for_path (data_filename);
- tracker_turtle_reader_load (file, &error);
+ data_update = tracker_data_manager_get_data (manager);
+ tracker_turtle_reader_load (file, data_update, &error);
g_assert_no_error (error);
g_object_unref (file);
} else {
@@ -143,7 +146,7 @@ test_backup_and_restore_helper (const gchar *db_location,
/* Check everything is correct */
- check_content_in_db (3, 1);
+ check_content_in_db (manager, 3, 1);
backup_location = g_build_filename (db_location, "backup", NULL);
g_mkdir (backup_location, 0777);
@@ -163,7 +166,7 @@ test_backup_and_restore_helper (const gchar *db_location,
g_main_loop_unref (loop);
loop = NULL;
- tracker_data_manager_shutdown ();
+ g_object_unref (manager);
meta_db = g_build_path (G_DIR_SEPARATOR_S, db_location, "meta.db", NULL);
g_unlink (meta_db);
@@ -189,25 +192,24 @@ test_backup_and_restore_helper (const gchar *db_location,
tracker_db_journal_set_rotating (FALSE, G_MAXSIZE, NULL);
#endif /* DISABLE_JOURNAL */
- tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
- data_location, data_location, test_schemas,
- NULL, FALSE, FALSE,
- 100, 100, NULL, NULL, NULL, &error);
-
+ manager = tracker_data_manager_new (TRACKER_DB_MANAGER_FORCE_REINDEX,
+ data_location, data_location, test_schemas,
+ FALSE, FALSE, 100, 100);
+ g_initable_init (G_INITABLE (manager), NULL, &error);
g_assert_no_error (error);
- check_content_in_db (0, 0);
+ check_content_in_db (manager, 0, 0);
- tracker_data_backup_restore (backup_file, data_location, data_location, test_schemas, NULL, NULL,
&error);
+ tracker_data_backup_restore (manager, backup_file, data_location, data_location, test_schemas, NULL,
NULL, &error);
g_assert_no_error (error);
- check_content_in_db (3, 1);
+ check_content_in_db (manager, 3, 1);
g_object_unref (test_schemas);
g_free (ontologies);
g_assert_cmpint (backup_calls, ==, 1);
- tracker_data_manager_shutdown ();
+ g_object_unref (manager);
}
static void
diff --git a/tests/libtracker-data/tracker-ontology-change-test.c
b/tests/libtracker-data/tracker-ontology-change-test.c
index ad0585b..c7fc235 100644
--- a/tests/libtracker-data/tracker-ontology-change-test.c
+++ b/tests/libtracker-data/tracker-ontology-change-test.c
@@ -90,7 +90,7 @@ delete_db (gboolean del_journal)
}
static void
-query_helper (const gchar *query_filename, const gchar *results_filename)
+query_helper (TrackerDataManager *manager, const gchar *query_filename, const gchar *results_filename)
{
GError *error = NULL;
gchar *queries = NULL, *query;
@@ -110,7 +110,7 @@ query_helper (const gchar *query_filename, const gchar *results_filename)
while (query) {
TrackerDBCursor *cursor;
- cursor = tracker_data_query_sparql_cursor (query, &error);
+ cursor = tracker_data_query_sparql_cursor (manager, query, &error);
g_assert_no_error (error);
/* compare results with reference output */
@@ -187,6 +187,7 @@ test_ontology_change (void)
guint i;
GError *error = NULL;
GFile *data_location, *test_schemas;
+ TrackerDataManager *manager;
delete_db (TRUE);
@@ -230,13 +231,13 @@ test_ontology_change (void)
g_assert_no_error (error);
g_chmod (ontology_file, 0666);
- tracker_data_manager_init (0, data_location, data_location, test_schemas,
- NULL, FALSE, FALSE,
- 100, 100, NULL, NULL, NULL, &error);
- data = tracker_data_manager_get_data ();
-
+ manager = tracker_data_manager_new (0, data_location, data_location, test_schemas,
+ FALSE, FALSE, 100, 100);
+ g_initable_init (G_INITABLE (manager), NULL, &error);
g_assert_no_error (error);
+ data = tracker_data_manager_get_data (manager);
+
if (g_file_get_contents (update, &queries, NULL, NULL)) {
gchar *query = strtok (queries, "\n");
while (query) {
@@ -262,22 +263,21 @@ test_ontology_change (void)
query_filename = g_strconcat (test_prefix, ".rq", NULL);
results_filename = g_strconcat (test_prefix, ".out", NULL);
- query_helper (query_filename, results_filename);
+ query_helper (manager, query_filename, results_filename);
g_free (test_prefix);
g_free (query_filename);
g_free (results_filename);
}
- tracker_data_manager_shutdown ();
+ g_object_unref (manager);
}
delete_db (FALSE);
- tracker_data_manager_init (0, data_location, data_location, test_schemas,
- NULL, TRUE, FALSE,
- 100, 100, NULL, NULL, NULL, &error);
-
+ manager = tracker_data_manager_new (0, data_location, data_location, test_schemas,
+ TRUE, FALSE, 100, 100);
+ g_initable_init (G_INITABLE (manager), NULL, &error);
g_assert_no_error (error);
for (i = 0; change_tests[i].test_name != NULL; i++) {
@@ -289,14 +289,14 @@ test_ontology_change (void)
query_filename = g_strconcat (test_prefix, ".rq", NULL);
results_filename = g_strconcat (test_prefix, ".out", NULL);
- query_helper (query_filename, results_filename);
+ query_helper (manager, query_filename, results_filename);
g_free (test_prefix);
g_free (query_filename);
g_free (results_filename);
}
- tracker_data_manager_shutdown ();
+ g_object_unref (manager);
g_file_delete (file2, NULL, NULL);
diff --git a/tests/libtracker-data/tracker-ontology-test.c b/tests/libtracker-data/tracker-ontology-test.c
index bd0b810..9e9f311 100644
--- a/tests/libtracker-data/tracker-ontology-test.c
+++ b/tests/libtracker-data/tracker-ontology-test.c
@@ -90,7 +90,7 @@ const TestInfo nmo_tests[] = {
};
static void
-query_helper (const gchar *query_filename, const gchar *results_filename)
+query_helper (TrackerDataManager *manager, const gchar *query_filename, const gchar *results_filename)
{
GError *error = NULL;
gchar *queries = NULL, *query;
@@ -110,7 +110,7 @@ query_helper (const gchar *query_filename, const gchar *results_filename)
while (query) {
TrackerDBCursor *cursor;
- cursor = tracker_data_query_sparql_cursor (query, &error);
+ cursor = tracker_data_query_sparql_cursor (manager, query, &error);
g_assert_no_error (error);
/* compare results with reference output */
@@ -181,6 +181,7 @@ static void
test_ontology_init (TestInfo *test_info,
gconstpointer context)
{
+ TrackerDataManager *manager;
GError *error = NULL;
GFile *data_location;
@@ -189,41 +190,23 @@ test_ontology_init (TestInfo *test_info,
tracker_db_journal_set_rotating (FALSE, G_MAXSIZE, NULL);
/* first-time initialization */
- tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
- data_location, data_location, data_location,
- NULL,
- FALSE,
- FALSE,
- 100,
- 100,
- NULL,
- NULL,
- NULL,
- &error);
-
+ manager = tracker_data_manager_new (TRACKER_DB_MANAGER_FORCE_REINDEX,
+ data_location, data_location, data_location,
+ FALSE, FALSE, 100, 100);
+ g_initable_init (G_INITABLE (manager), NULL, &error);
g_assert_no_error (error);
- tracker_data_manager_shutdown ();
+ g_object_unref (manager);
tracker_db_journal_set_rotating (FALSE, G_MAXSIZE, NULL);
/* initialization from existing database */
- tracker_data_manager_init (0,
- data_location, data_location, data_location,
- NULL,
- FALSE,
- FALSE,
- 100,
- 100,
- NULL,
- NULL,
- NULL,
- &error);
-
+ manager = tracker_data_manager_new (0, data_location, data_location, data_location,
+ FALSE, FALSE, 100, 100);
+ g_initable_init (G_INITABLE (manager), NULL, &error);
g_assert_no_error (error);
- tracker_data_manager_shutdown ();
-
+ g_object_unref (manager);
g_object_unref (data_location);
}
@@ -237,6 +220,8 @@ test_query (TestInfo *test_info,
gchar *results_filename;
gchar *prefix, *data_prefix, *test_prefix, *ontology_path;
GFile *file, *data_location, *ontology_location;
+ TrackerDataManager *manager;
+ TrackerData *data_update;
data_location = g_file_new_for_path (test_info->data_location);
@@ -252,22 +237,19 @@ test_query (TestInfo *test_info,
tracker_db_journal_set_rotating (FALSE, G_MAXSIZE, NULL);
/* initialization */
- tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
- data_location, data_location, ontology_location,
- NULL,
- FALSE,
- FALSE,
- 100,
- 100,
- NULL,
- NULL,
- NULL,
- NULL);
+ manager = tracker_data_manager_new (TRACKER_DB_MANAGER_FORCE_REINDEX,
+ data_location, data_location, ontology_location,
+ FALSE, FALSE, 100, 100);
+ g_initable_init (G_INITABLE (manager), NULL, &error);
+ g_assert_no_error (error);
+
+ data_update = tracker_data_manager_get_data (manager);
/* load data set */
data_filename = g_strconcat (data_prefix, ".ttl", NULL);
file = g_file_new_for_path (data_filename);
- tracker_turtle_reader_load (file, &error);
+ data_update = tracker_data_manager_get_data (manager);
+ tracker_turtle_reader_load (file, data_update, &error);
g_assert_no_error (error);
g_object_unref (file);
@@ -277,7 +259,7 @@ test_query (TestInfo *test_info,
g_free (data_prefix);
g_free (test_prefix);
- query_helper (query_filename, results_filename);
+ query_helper (manager, query_filename, results_filename);
/* cleanup */
@@ -287,8 +269,7 @@ test_query (TestInfo *test_info,
g_object_unref (ontology_location);
g_object_unref (data_location);
-
- tracker_data_manager_shutdown ();
+ g_object_unref (manager);
}
static inline void
diff --git a/tests/libtracker-data/tracker-sparql-blank-test.c
b/tests/libtracker-data/tracker-sparql-blank-test.c
index f9cbc14..73adc28 100644
--- a/tests/libtracker-data/tracker-sparql-blank-test.c
+++ b/tests/libtracker-data/tracker-sparql-blank-test.c
@@ -50,6 +50,7 @@ test_blank (TestInfo *info,
guint len = 0;
gchar *solutions[3][3];
GFile *data_location;
+ TrackerDataManager *manager;
error = NULL;
@@ -58,23 +59,15 @@ test_blank (TestInfo *info,
tracker_db_journal_set_rotating (FALSE, G_MAXSIZE, NULL);
/* initialization */
- tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
- data_location, data_location, data_location, /* loc, domain and
ontology_name */
- NULL,
- FALSE,
- FALSE,
- 100,
- 100,
- NULL,
- NULL,
- NULL,
- &error);
-
+ manager = tracker_data_manager_new (TRACKER_DB_MANAGER_FORCE_REINDEX,
+ data_location, data_location, data_location, /* loc, domain and
ontology_name */
+ FALSE, FALSE, 100, 100);
+ g_initable_init (G_INITABLE (manager), NULL, &error);
g_assert_no_error (error);
/* perform update in transaction */
- updates = tracker_data_update_sparql_blank (tracker_data_manager_get_data (),
+ updates = tracker_data_update_sparql_blank (tracker_data_manager_get_data (manager),
"INSERT { _:foo a rdfs:Resource } "
"INSERT { _:foo a rdfs:Resource . _:bar a rdfs:Resource }
",
&error);
@@ -130,8 +123,7 @@ test_blank (TestInfo *info,
g_variant_unref (updates);
g_object_unref (data_location);
-
- tracker_data_manager_shutdown ();
+ g_object_unref (manager);
}
static void
diff --git a/tests/libtracker-data/tracker-sparql-test.c b/tests/libtracker-data/tracker-sparql-test.c
index 443d557..cf5da81 100644
--- a/tests/libtracker-data/tracker-sparql-test.c
+++ b/tests/libtracker-data/tracker-sparql-test.c
@@ -256,6 +256,7 @@ test_sparql_query (TestInfo *test_info,
gchar *results_filename;
gchar *prefix, *data_prefix, *test_prefix;
GFile *file, *test_schemas, *data_location;
+ TrackerDataManager *manager;
TrackerData *data_update;
/* initialization */
@@ -272,21 +273,21 @@ test_sparql_query (TestInfo *test_info,
tracker_db_journal_set_rotating (FALSE, G_MAXSIZE, NULL);
- tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
- data_location, data_location, test_schemas, /* loc, domain and
ontology_name */
- NULL, FALSE, FALSE,
- 100, 100, NULL, NULL, NULL, &error);
- data_update = tracker_data_manager_get_data ();
-
+ manager = tracker_data_manager_new (TRACKER_DB_MANAGER_FORCE_REINDEX,
+ data_location, data_location, test_schemas, /* loc, domain and
ontology_name */
+ FALSE, FALSE, 100, 100);
+ g_initable_init (G_INITABLE (manager), NULL, &error);
g_assert_no_error (error);
+ data_update = tracker_data_manager_get_data (manager);
+
/* data_path = g_build_path (G_DIR_SEPARATOR_S, TOP_SRCDIR, "tests", "libtracker-data", NULL); */
/* load data set */
data_filename = g_strconcat (data_prefix, ".ttl", NULL);
if (g_file_test (data_filename, G_FILE_TEST_IS_REGULAR)) {
GFile *file = g_file_new_for_path (data_filename);
- tracker_turtle_reader_load (file, &error);
+ tracker_turtle_reader_load (file, data_update, &error);
g_assert_no_error (error);
g_object_unref (file);
} else {
@@ -318,7 +319,7 @@ test_sparql_query (TestInfo *test_info,
/* perform actual query */
- cursor = tracker_data_query_sparql_cursor (query, &error);
+ cursor = tracker_data_query_sparql_cursor (manager, query, &error);
check_result (cursor, test_info, results_filename, error);
@@ -328,7 +329,7 @@ test_sparql_query (TestInfo *test_info,
query_filename = g_strconcat (test_prefix, ".extra.rq", NULL);
if (g_file_get_contents (query_filename, &query, NULL, NULL)) {
g_object_unref (cursor);
- cursor = tracker_data_query_sparql_cursor (query, &error);
+ cursor = tracker_data_query_sparql_cursor (manager, query, &error);
g_assert_no_error (error);
g_free (results_filename);
results_filename = g_strconcat (test_prefix, ".extra.out", NULL);
@@ -350,8 +351,7 @@ test_sparql_query (TestInfo *test_info,
g_free (results_filename);
g_object_unref (test_schemas);
g_object_unref (data_location);
-
- tracker_data_manager_shutdown ();
+ g_object_unref (manager);
}
static void
diff --git a/tests/libtracker-fts/tracker-fts-test.c b/tests/libtracker-fts/tracker-fts-test.c
index cdd7da3..1e88aaf 100644
--- a/tests/libtracker-fts/tracker-fts-test.c
+++ b/tests/libtracker-fts/tracker-fts-test.c
@@ -57,6 +57,7 @@ test_sparql_query (gconstpointer test_data)
gchar *results, *results_filename;
gchar *prefix, *test_prefix;
GFile *ontology, *data_location;
+ TrackerDataManager *manager;
TrackerData *data;
gint i;
@@ -72,13 +73,13 @@ test_sparql_query (gconstpointer test_data)
data_location = g_file_new_for_path (datadir);
tracker_db_journal_set_rotating (FALSE, G_MAXSIZE, NULL);
- tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
- data_location, data_location, ontology,
- NULL, FALSE, FALSE,
- 100, 100, NULL, NULL, NULL, &error);
- data = tracker_data_manager_get_data ();
-
+ manager = tracker_data_manager_new (TRACKER_DB_MANAGER_FORCE_REINDEX,
+ data_location, data_location, ontology,
+ FALSE, FALSE, 100, 100);
+ g_initable_init (G_INITABLE (manager), NULL, &error);
g_assert_no_error (error);
+
+ data = tracker_data_manager_get_data (manager);
g_object_unref (ontology);
/* load data / perform updates */
@@ -104,7 +105,7 @@ test_sparql_query (gconstpointer test_data)
g_file_get_contents (results_filename, &results, NULL, &error);
g_assert_no_error (error);
- cursor = tracker_data_query_sparql_cursor (query, &error);
+ cursor = tracker_data_query_sparql_cursor (manager, query, &error);
g_assert_no_error (error);
/* compare results with reference output */
@@ -170,8 +171,7 @@ test_sparql_query (gconstpointer test_data)
g_free (test_prefix);
g_object_unref (data_location);
-
- tracker_data_manager_shutdown ();
+ g_object_unref (manager);
}
int
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]