[tracker/property-changes: 2/3] libtracker-data: Support for ontology change tracker:notify and tracker:writeback
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/property-changes: 2/3] libtracker-data: Support for ontology change tracker:notify and tracker:writeback
- Date: Wed, 31 Mar 2010 13:24:24 +0000 (UTC)
commit d15a7a36445301a3ef8d951e9ee1e29f8f473b4e
Author: Philip Van Hoof <philip codeminded be>
Date: Wed Mar 31 11:40:57 2010 +0200
libtracker-data: Support for ontology change tracker:notify and tracker:writeback
s
src/libtracker-data/tracker-data-manager.c | 98 ++++++++++++++++++++++++++-
1 files changed, 94 insertions(+), 4 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index ef29b66..f4f9388 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -46,6 +46,7 @@
#include "tracker-ontology.h"
#include "tracker-property.h"
#include "tracker-sparql-query.h"
+#include "tracker-data-query.h"
#define RDF_PREFIX TRACKER_RDF_PREFIX
#define RDF_PROPERTY RDF_PREFIX "Property"
@@ -69,9 +70,59 @@
#define ZLIBBUFSIZ 8192
-static gchar *ontologies_dir;
-static gboolean initialized;
-static gboolean in_journal_replay;
+static gchar *ontologies_dir;
+static gboolean initialized;
+static gboolean in_journal_replay;
+
+static void
+notify_and_writeback_helper (const gchar *kind,
+ const gchar *subject,
+ const gchar *predicate,
+ const gchar *object)
+{
+ GError *error = NULL;
+ TrackerDBResultSet *result_set;
+ gchar *query;
+ gboolean needed = TRUE;
+
+ query = g_strdup_printf ("SELECT ?old_value WHERE { "
+ "<%s> tracker:%s ?old_value "
+ "}", subject, kind);
+
+ result_set = tracker_data_query_sparql (query, &error);
+
+ g_free (query);
+
+ if (!error && result_set) {
+ gchar *str = NULL;
+
+ tracker_db_result_set_get (result_set, 0, &str, -1);
+
+ if (g_strcmp0 (object, str) == 0) {
+ needed = FALSE;
+ } else {
+ tracker_data_delete_statement (NULL, subject, predicate, str, &error);
+ }
+
+ g_free (str);
+ }
+
+ if (result_set) {
+ g_object_unref (result_set);
+ }
+
+ if (!error && needed) {
+ tracker_data_insert_statement_with_string (NULL, subject,
+ predicate, object,
+ &error);
+ }
+
+ if (error) {
+ g_critical ("Can't update %s for %s: %s",
+ kind, subject, error->message);
+ g_error_free (error);
+ }
+}
void
tracker_data_ontology_load_statement (const gchar *ontology_path,
@@ -198,6 +249,42 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
}
tracker_class_add_super_class (class, super_class);
+ } else if (g_strcmp0 (predicate, TRACKER_PREFIX "notify") == 0) {
+ TrackerClass *class;
+ gboolean wanted_value;
+
+ class = tracker_ontologies_get_class_by_uri (subject);
+ if (class == NULL) {
+ g_critical ("%s: Unknown class %s", ontology_path, subject);
+ return;
+ }
+
+ if (strcmp (object, "true") == 0) {
+ wanted_value = TRUE;
+ }
+
+ if (tracker_class_get_is_new (class) != in_update) {
+ notify_and_writeback_helper ("notify", subject, predicate, object);
+ }
+
+ } else if (g_strcmp0 (predicate, TRACKER_PREFIX "writeback") == 0) {
+ TrackerProperty *property;
+ gboolean wanted_value;
+
+ property = tracker_ontologies_get_property_by_uri (subject);
+ if (property == NULL) {
+ g_critical ("%s: Unknown property %s", ontology_path, subject);
+ return;
+ }
+
+ if (strcmp (object, "true") == 0) {
+ wanted_value = TRUE;
+ }
+
+ if (tracker_property_get_is_new (property) != in_update) {
+ notify_and_writeback_helper ("writeback", subject, predicate, object);
+ }
+
} else if (g_strcmp0 (predicate, RDFS_SUB_PROPERTY_OF) == 0) {
TrackerProperty *property, *super_property;
@@ -349,6 +436,10 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
return;
}
+ if (tracker_property_get_is_new (property) != in_update) {
+ return;
+ }
+
if (strcmp (object, "true") == 0) {
tracker_property_set_fulltext_no_limit (property, TRUE);
}
@@ -381,7 +472,6 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
tracker_ontology_set_last_modified (ontology, tracker_string_to_date (object, NULL, NULL));
}
-
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]