[tracker/property-changes: 3/3] libtracker-data: Support for traker:writeback ontology changes



commit 5b233469b617b35fe2e397ea78ffccdf4a82eb4f
Author: Philip Van Hoof <philip codeminded be>
Date:   Wed Mar 31 13:13:04 2010 +0200

    libtracker-data: Support for traker:writeback ontology changes

 src/libtracker-data/tracker-data-manager.c |   87 +++++++++++++++++++++++-----
 src/libtracker-data/tracker-property.c     |   26 ++++++++
 src/libtracker-data/tracker-property.h     |    3 +
 3 files changed, 102 insertions(+), 14 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 33f6f38..98aaa28 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 tracker:%s for property %s: %s", 
+		            kind, subject, error->message);
+		g_error_free (error);
+	}
+}
 
 void
 tracker_data_ontology_load_statement (const gchar *ontology_path,
@@ -213,21 +264,29 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
 		}
 
 		if (tracker_class_get_is_new (class) != in_update) {
-			if (tracker_class_get_notify (class) != wanted_value) {
-				GError *error = NULL;
+			notify_and_writeback_helper ("notify", subject, predicate, object);
+		}
 
-				tracker_data_insert_statement_with_string (NULL, subject,
-				                                           predicate, object,
-				                                           &error);
+		tracker_class_set_notify (class, wanted_value);
+	} else if (g_strcmp0 (predicate, TRACKER_PREFIX "writeback") == 0) {
+		TrackerProperty *property;
+		gboolean wanted_value;
 
-				if (error) {
-					g_critical ("Can't update tracker:notify for class %s: %s", subject, error->message);
-					g_error_free (error);
-				}
-			}
+		property = tracker_ontologies_get_property_by_uri (subject);
+		if (property == NULL) {
+			g_critical ("%s: Unknown property %s", ontology_path, subject);
+			return;
 		}
 
-		tracker_class_set_notify (class, wanted_value);
+		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);
+		}
+
+		tracker_property_set_writeback (property, wanted_value);
 	} else if (g_strcmp0 (predicate, RDFS_SUB_PROPERTY_OF) == 0) {
 		TrackerProperty *property, *super_property;
 
diff --git a/src/libtracker-data/tracker-property.c b/src/libtracker-data/tracker-property.c
index b59d1e6..4894075 100644
--- a/src/libtracker-data/tracker-property.c
+++ b/src/libtracker-data/tracker-property.c
@@ -59,6 +59,7 @@ struct _TrackerPropertyPriv {
 	gboolean       transient;
 	gboolean       is_inverse_functional_property;
 	gboolean       is_new;
+	gboolean       writeback;
 
 	GArray        *super_properties;
 };
@@ -341,6 +342,18 @@ tracker_property_get_is_new (TrackerProperty *field)
 }
 
 gboolean
+tracker_property_get_writeback (TrackerProperty *field)
+{
+	TrackerPropertyPriv *priv;
+
+	g_return_val_if_fail (TRACKER_IS_PROPERTY (field), FALSE);
+
+	priv = GET_PRIV (field);
+
+	return priv->writeback;
+}
+
+gboolean
 tracker_property_get_embedded (TrackerProperty *field)
 {
 	TrackerPropertyPriv *priv;
@@ -551,6 +564,19 @@ tracker_property_set_is_new (TrackerProperty *field,
 }
 
 void
+tracker_property_set_writeback (TrackerProperty *field,
+                             gboolean         value)
+{
+	TrackerPropertyPriv *priv;
+
+	g_return_if_fail (TRACKER_IS_PROPERTY (field));
+
+	priv = GET_PRIV (field);
+
+	priv->writeback = value;
+}
+
+void
 tracker_property_set_fulltext_indexed (TrackerProperty *field,
                                        gboolean                 value)
 {
diff --git a/src/libtracker-data/tracker-property.h b/src/libtracker-data/tracker-property.h
index ab4e532..7b78521 100644
--- a/src/libtracker-data/tracker-property.h
+++ b/src/libtracker-data/tracker-property.h
@@ -87,6 +87,7 @@ gboolean            tracker_property_get_embedded         (TrackerProperty
 gboolean            tracker_property_get_multiple_values  (TrackerProperty      *property);
 gboolean            tracker_property_get_transient        (TrackerProperty      *property);
 gboolean            tracker_property_get_is_new           (TrackerProperty      *property);
+gboolean            tracker_property_get_writeback        (TrackerProperty      *property);
 gboolean            tracker_property_get_is_inverse_functional_property
 (TrackerProperty      *property);
 TrackerProperty **  tracker_property_get_super_properties (TrackerProperty      *property);
@@ -114,6 +115,8 @@ void                tracker_property_set_transient        (TrackerProperty
                                                            gboolean              value);
 void                tracker_property_set_is_new           (TrackerProperty      *property,
                                                            gboolean              value);
+void                tracker_property_set_writeback        (TrackerProperty      *property,
+                                                           gboolean              value);
 void                tracker_property_set_is_inverse_functional_property
 (TrackerProperty      *property,
  gboolean              value);



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