[tracker/property-changes] libtracker-data: Fixed the support for property property changes
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/property-changes] libtracker-data: Fixed the support for property property changes
- Date: Sat, 3 Apr 2010 11:47:14 +0000 (UTC)
commit 258e9fa7dc308702f89fb6a01d601af314c17290
Author: Philip Van Hoof <philip codeminded be>
Date: Sat Apr 3 13:45:24 2010 +0200
libtracker-data: Fixed the support for property property changes
For tracker:indexed, tracker:writeback and tracker:notify
src/libtracker-data/tracker-data-manager.c | 210 +++++++++-------------------
1 files changed, 64 insertions(+), 146 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 5b1e256..ba8ae9b 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -231,8 +231,12 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
if (class != NULL) {
if (seen_classes)
g_ptr_array_add (seen_classes, g_object_ref (class));
- if (!in_update)
+ if (!in_update) {
g_critical ("%s: Duplicate definition of class %s", ontology_path, subject);
+ } else {
+ /* Reset for a correct post-check */
+ tracker_class_set_notify (class, FALSE);
+ }
return;
}
@@ -263,8 +267,13 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
if (property != NULL) {
if (seen_properties)
g_ptr_array_add (seen_properties, g_object_ref (property));
- if (!in_update)
+ if (!in_update) {
g_critical ("%s: Duplicate definition of property %s", ontology_path, subject);
+ } else {
+ /* Reset for a correct post-check */
+ tracker_property_set_indexed (property, FALSE);
+ tracker_property_set_writeback (property, FALSE);
+ }
return;
}
@@ -353,32 +362,25 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
TrackerClass *class;
class = tracker_ontologies_get_class_by_uri (subject);
+
if (class == NULL) {
g_critical ("%s: Unknown class %s", ontology_path, subject);
return;
}
- if (tracker_class_get_is_new (class) != in_update) {
- update_property_value ("tracker:notify", subject, predicate, object);
- }
-
tracker_class_set_notify (class, (strcmp (object, "true") == 0));
} else if (g_strcmp0 (predicate, TRACKER_PREFIX "writeback") == 0) {
TrackerProperty *property;
property = tracker_ontologies_get_property_by_uri (subject);
+
if (property == NULL) {
g_critical ("%s: Unknown property %s", ontology_path, subject);
return;
}
- if (tracker_property_get_is_new (property) != in_update) {
- update_property_value ("tracker:writeback", subject, predicate, object);
- }
-
tracker_property_set_writeback (property, (strcmp (object, "true") == 0));
-
} else if (g_strcmp0 (predicate, RDFS_SUB_PROPERTY_OF) == 0) {
TrackerProperty *property, *super_property;
@@ -464,7 +466,6 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
}
} else if (g_strcmp0 (predicate, TRACKER_PREFIX "indexed") == 0) {
TrackerProperty *property;
- gboolean enabled;
property = tracker_ontologies_get_property_by_uri (subject);
if (property == NULL) {
@@ -472,17 +473,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
return;
}
- enabled = (strcmp (object, "true") == 0);
-
- if (tracker_property_get_is_new (property) != in_update) {
- if (update_property_value ("tracker:indexed", subject, predicate, object)) {
- fix_indexed (property, enabled);
- }
- }
-
- if (enabled) {
- tracker_property_set_indexed (property, TRUE);
- }
+ tracker_property_set_indexed (property, (strcmp (object, "true") == 0));
} else if (g_strcmp0 (predicate, TRACKER_PREFIX "transient") == 0) {
TrackerProperty *property;
@@ -584,127 +575,54 @@ tracker_data_ontology_post_check (GPtrArray *seen_classes,
{
gint i;
- /* This checks for properties of classes being removed from the ontology.
- * For example when going from: prefix:A rdfs:Class ; tracker:notify true .
- * to prefix:A rdfs:Class . */
-
for (i = 0; i < seen_classes->len; i++) {
TrackerClass *class = g_ptr_array_index (seen_classes, i);
- GError *error = NULL;
- TrackerDBResultSet *result_set;
const gchar *subject;
- gchar *query;
-
subject = tracker_class_get_uri (class);
- query = g_strdup_printf ("SELECT ?predicate ?object WHERE { <%s> ?predicate ?object }",
- subject);
-
- result_set = tracker_data_query_sparql (query, &error);
- g_free (query);
-
- if (!error && result_set) {
- gboolean saw_notify = FALSE, is_notify;
-
- do {
- gchar *predicate, *old_object;
- TrackerProperty *property;
-
- tracker_db_result_set_get (result_set, 0, &predicate, -1);
- tracker_db_result_set_get (result_set, 1, &old_object, -1);
-
- property = tracker_ontologies_get_property_by_uri (predicate);
-
- if (property != NULL) {
- if (g_strcmp0 (predicate, TRACKER_PREFIX "notify") == 0) {
- saw_notify = TRUE;
- is_notify = (strcmp (old_object, "true") == 0);
- }
- }
-
- g_free (old_object);
- g_free (predicate);
-
- } while (tracker_db_result_set_iter_next (result_set) && !saw_notify);
-
- if (!saw_notify && tracker_class_get_notify (class)) {
- update_property_value ("tracker:notify",
- subject,
- TRACKER_PREFIX "notify",
- is_notify ? "true" : "false");
- }
-
+ if (tracker_class_get_notify (class)) {
+ update_property_value ("tracker:notify",
+ subject,
+ TRACKER_PREFIX "notify",
+ "true");
} else {
- if (error) {
- g_critical ("Ontology change: %s", error->message);
- g_clear_error (&error);
- }
+ update_property_value ("tracker:notify",
+ subject,
+ TRACKER_PREFIX "notify",
+ "false");
}
-
- if (result_set)
- g_object_unref (result_set);
}
for (i = 0; i < seen_properties->len; i++) {
TrackerProperty *property = g_ptr_array_index (seen_properties, i);
- GError *error = NULL;
- TrackerDBResultSet *result_set;
const gchar *subject;
- gboolean saw_writeback = FALSE, saw_indexed = FALSE;
- gboolean is_writeback, is_indexed;
- gchar *query;
-
subject = tracker_property_get_uri (property);
- query = g_strdup_printf ("SELECT ?predicate ?object WHERE { <%s> ?predicate ?object }",
- subject);
- result_set = tracker_data_query_sparql (query, &error);
- g_free (query);
-
- if (!error && result_set) {
- do {
- gchar *predicate, *old_object;
-
- tracker_db_result_set_get (result_set, 0, &predicate, -1);
- tracker_db_result_set_get (result_set, 1, &old_object, -1);
-
- if (!saw_writeback && g_strcmp0 (predicate, TRACKER_PREFIX "writeback") == 0) {
- saw_writeback = TRUE;
- is_writeback = (strcmp (old_object, "true") == 0);
- }
-
- if (!saw_indexed && g_strcmp0 (predicate, TRACKER_PREFIX "indexed") == 0) {
- saw_indexed = TRUE;
- is_indexed = (strcmp (old_object, "true") == 0);
- }
-
- g_free (predicate);
- g_free (old_object);
- } while (tracker_db_result_set_iter_next (result_set));
-
- if (!saw_writeback && tracker_property_get_writeback (property)) {
- update_property_value ("tracker:writeback",
- subject,
- TRACKER_PREFIX "writeback",
- is_writeback ? "true" : "false");
- }
-
- if (!saw_indexed && tracker_property_get_indexed (property)) {
- if (update_property_value ("tracker:indexed",
- subject,
- TRACKER_PREFIX "indexed",
- is_indexed ? "true" : "false")) {
- fix_indexed (property, is_indexed);
- }
+ if (tracker_property_get_writeback (property)) {
+ update_property_value ("tracker:writeback",
+ subject,
+ TRACKER_PREFIX "writeback",
+ "true");
+ } else {
+ update_property_value ("tracker:writeback",
+ subject,
+ TRACKER_PREFIX "writeback",
+ "false");
+ }
+
+ if (tracker_property_get_indexed (property)) {
+ if (update_property_value ("tracker:indexed",
+ subject,
+ TRACKER_PREFIX "indexed",
+ "true")) {
+ fix_indexed (property, TRUE);
}
-
} else {
- if (error) {
- g_critical ("Ontology change: %s", error->message);
- g_clear_error (&error);
+ if (update_property_value ("tracker:indexed",
+ subject,
+ TRACKER_PREFIX "indexed",
+ "false")) {
+ fix_indexed (property, FALSE);
}
}
-
- if (result_set)
- g_object_unref (result_set);
}
}
@@ -718,12 +636,12 @@ tracker_data_ontology_free_seen (GPtrArray *seen)
static void
load_ontology_file_from_path (const gchar *ontology_path,
gint *max_id,
- gboolean in_update)
+ gboolean in_update,
+ GPtrArray *seen_classes,
+ GPtrArray *seen_properties)
{
TrackerTurtleReader *reader;
GError *error = NULL;
- GPtrArray *seen_classes = NULL;
- GPtrArray *seen_properties = NULL;
reader = tracker_turtle_reader_new (ontology_path, &error);
if (error) {
@@ -735,11 +653,6 @@ load_ontology_file_from_path (const gchar *ontology_path,
/* Post checks are only needed for ontology updates, not the initial
* ontology */
- if (in_update) {
- seen_classes = g_ptr_array_new ();
- seen_properties = g_ptr_array_new ();
- }
-
while (error == NULL && tracker_turtle_reader_next (reader, &error)) {
const gchar *subject, *predicate, *object;
@@ -754,12 +667,6 @@ load_ontology_file_from_path (const gchar *ontology_path,
g_object_unref (reader);
- if (in_update) {
- tracker_data_ontology_post_check (seen_classes, seen_properties);
- tracker_data_ontology_free_seen (seen_classes);
- tracker_data_ontology_free_seen (seen_properties);
- }
-
if (error) {
g_critical ("Turtle parse error: %s", error->message);
g_error_free (error);
@@ -2020,7 +1927,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
gchar *ontology_path;
g_debug ("Loading ontology %s", (char *) l->data);
ontology_path = g_build_filename (ontologies_dir, l->data, NULL);
- load_ontology_file_from_path (ontology_path, &max_id, FALSE);
+ load_ontology_file_from_path (ontology_path, &max_id, FALSE, NULL, NULL);
g_free (ontology_path);
}
@@ -2032,7 +1939,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
g_debug ("Loading ontology:'%s' (TEST ONTOLOGY)", test_schema_path);
- load_ontology_file_from_path (test_schema_path, &max_id, FALSE);
+ load_ontology_file_from_path (test_schema_path, &max_id, FALSE, NULL, NULL);
g_free (test_schema_path);
}
}
@@ -2087,6 +1994,11 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
GList *to_reload = NULL;
GList *ontos = NULL;
guint p;
+ GPtrArray *seen_classes;
+ GPtrArray *seen_properties;
+
+ seen_classes = g_ptr_array_new ();
+ seen_properties = g_ptr_array_new ();
/* Get all the ontology files from ontologies_dir */
sorted = get_ontologies (test_schemas != NULL, ontologies_dir);
@@ -2187,7 +2099,8 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
}
/* load ontology from files into memory, set all new's
* is_new to TRUE */
- load_ontology_file_from_path (ontology_path, &max_id, TRUE);
+ load_ontology_file_from_path (ontology_path, &max_id, TRUE,
+ seen_classes, seen_properties);
to_reload = g_list_prepend (to_reload, l->data);
update_nao = TRUE;
}
@@ -2199,7 +2112,8 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
}
/* load ontology from files into memory, set all new's
* is_new to TRUE */
- load_ontology_file_from_path (ontology_path, &max_id, TRUE);
+ load_ontology_file_from_path (ontology_path, &max_id, TRUE,
+ seen_classes, seen_properties);
to_reload = g_list_prepend (to_reload, l->data);
update_nao = TRUE;
}
@@ -2234,6 +2148,10 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
g_list_free (to_reload);
}
+ tracker_data_ontology_post_check (seen_classes, seen_properties);
+ 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 ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]