[tracker/journal] libtracker-data: Prepare resource creation for ID values



commit 767eb68e83ce4a3ca824367c68781d24689857c1
Author: Philip Van Hoof <philip codeminded be>
Date:   Mon Mar 15 13:19:25 2010 +0100

    libtracker-data: Prepare resource creation for ID values

 src/libtracker-data/tracker-data-update.c |   71 ++++++++++++++++++++---------
 1 files changed, 49 insertions(+), 22 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 5bd6b3d..4d4c7b6 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -87,6 +87,7 @@ struct _TrackerDataUpdateBufferResource {
 struct _TrackerDataUpdateBufferProperty {
 	const gchar *name;
 	GValue value;
+	gint value_id;
 	gint graph;
 	gboolean fts : 1;
 	gboolean date_time : 1;
@@ -286,7 +287,10 @@ cache_table_free (TrackerDataUpdateBufferTable *table)
 
 	for (i = 0; i < table->properties->len; i++) {
 		property = &g_array_index (table->properties, TrackerDataUpdateBufferProperty, i);
-		g_value_unset (&property->value);
+
+		if (property->value_id == 0) {
+			g_value_unset (&property->value);
+		}
 	}
 
 	g_array_free (table->properties, TRUE);
@@ -323,6 +327,7 @@ static void
 cache_insert_value (const gchar            *table_name,
                     const gchar            *field_name,
                     GValue                 *value,
+                    gint                    value_id,
                     gint                    graph,
                     gboolean                multiple_values,
                     gboolean                fts,
@@ -335,7 +340,13 @@ cache_insert_value (const gchar            *table_name,
 	 * long-standing as tracker_property_get_name return value. */
 	property.name = field_name;
 
-	property.value = *value;
+	if (value) {
+		property.value = *value;
+		property.value_id = 0;
+	} else {
+		property.value_id = value_id;
+	}
+
 	property.graph = graph;
 	property.fts = fts;
 	property.date_time = date_time;
@@ -367,6 +378,7 @@ cache_delete_value (const gchar            *table_name,
 
 	property.name = g_strdup (field_name);
 	property.value = *value;
+	property.value_id = 0;
 	property.graph = 0;
 	property.fts = fts;
 	property.date_time = date_time;
@@ -544,7 +556,12 @@ tracker_data_resource_buffer_flush (GError **error)
 				param = 0;
 
 				tracker_db_statement_bind_int (stmt, param++, resource_buffer->id);
-				statement_bind_gvalue (stmt, &param, &property->value);
+
+				if (property->value_id == 0) {
+					statement_bind_gvalue (stmt, &param, &property->value);
+				} else {
+					tracker_db_statement_bind_int (stmt, param++, property->value_id);
+				}
 
 				if (property->graph != 0) {
 					tracker_db_statement_bind_int (stmt, param++, property->graph);
@@ -658,7 +675,11 @@ tracker_data_resource_buffer_flush (GError **error)
 						tracker_db_statement_bind_null (stmt, param++);
 					}
 				} else {
-					statement_bind_gvalue (stmt, &param, &property->value);
+					if (property->value_id == 0) {
+						statement_bind_gvalue (stmt, &param, &property->value);
+					} else {
+						tracker_db_statement_bind_int (stmt, param++, property->value_id);
+					}
 				}
 				if (property->graph != 0) {
 					tracker_db_statement_bind_int (stmt, param++, property->graph);
@@ -860,7 +881,9 @@ tracker_data_blank_buffer_flush (GError **error)
 
 static void
 cache_create_service_decomposed (TrackerClass *cl,
-                                 const gchar  *graph)
+                                 const gchar  *graph,
+                                 gint          graph_id,
+                                 gboolean      do_callback)
 {
 	TrackerClass       **super_classes;
 	GValue              gvalue = { 0 };
@@ -869,7 +892,7 @@ cache_create_service_decomposed (TrackerClass *cl,
 	/* also create instance of all super classes */
 	super_classes = tracker_class_get_super_classes (cl);
 	while (*super_classes) {
-		cache_create_service_decomposed (*super_classes, graph);
+		cache_create_service_decomposed (*super_classes, graph, graph_id, do_callback);
 		super_classes++;
 	}
 
@@ -887,12 +910,12 @@ cache_create_service_decomposed (TrackerClass *cl,
 	cache_insert_row (cl);
 
 	g_value_set_int (&gvalue, ensure_resource_id (tracker_class_get_uri (cl), NULL));
-	cache_insert_value ("rdfs:Resource_rdf:type", "rdf:type", &gvalue,
-	                    graph != NULL ? ensure_resource_id (graph, NULL) : 0,
+	cache_insert_value ("rdfs:Resource_rdf:type", "rdf:type", &gvalue, 0,
+	                    graph != NULL ? ensure_resource_id (graph, NULL) : graph_id,
 	                    TRUE, FALSE, FALSE);
 
 	add_class_count (cl, 1);
-	if (insert_callbacks) {
+	if (do_callback && insert_callbacks) {
 		guint n;
 		const gchar *class_uri;
 
@@ -1175,6 +1198,7 @@ string_to_gvalue (const gchar         *value,
 static gboolean
 cache_set_metadata_decomposed (TrackerProperty  *property,
                                const gchar      *value,
+                               gint              value_id,
                                const gchar      *graph,
                                gint              graph_id,
                                GError          **error)
@@ -1191,7 +1215,8 @@ cache_set_metadata_decomposed (TrackerProperty  *property,
 	/* also insert super property values */
 	super_properties = tracker_property_get_super_properties (property);
 	while (*super_properties) {
-		cache_set_metadata_decomposed (*super_properties, value, graph, graph_id, &new_error);
+		cache_set_metadata_decomposed (*super_properties, value, value_id, 
+		                               graph, graph_id, &new_error);
 		if (new_error) {
 			g_propagate_error (error, new_error);
 			return FALSE;
@@ -1219,11 +1244,13 @@ cache_set_metadata_decomposed (TrackerProperty  *property,
 		return FALSE;
 	}
 
-	string_to_gvalue (value, tracker_property_get_data_type (property), &gvalue, &new_error);
-	if (new_error) {
-		g_free (table_name);
-		g_propagate_error (error, new_error);
-		return FALSE;
+	if (value) {
+		string_to_gvalue (value, tracker_property_get_data_type (property), &gvalue, &new_error);
+		if (new_error) {
+			g_free (table_name);
+			g_propagate_error (error, new_error);
+			return FALSE;
+		}
 	}
 
 	if (!value_set_add_value (old_values, &gvalue)) {
@@ -1239,7 +1266,7 @@ cache_set_metadata_decomposed (TrackerProperty  *property,
 		             resource_buffer->subject,
 		             field_name);
 	} else {
-		cache_insert_value (table_name, field_name, &gvalue,
+		cache_insert_value (table_name, field_name, value ? &gvalue : NULL, value_id,
 		                    graph != NULL ? ensure_resource_id (graph, NULL) : graph_id,
 		                    multiple_values, fts,
 		                    tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_DATETIME);
@@ -1488,7 +1515,7 @@ resource_buffer_switch (const gchar *graph,
 
 		g_value_init (&gvalue, G_TYPE_INT);
 		g_value_set_int (&gvalue, tracker_data_update_get_next_modseq ());
-		cache_insert_value ("rdfs:Resource", "tracker:modified", &gvalue,
+		cache_insert_value ("rdfs:Resource", "tracker:modified", &gvalue, 0,
 		                    graph_id,
 		                    FALSE, FALSE, FALSE);
 	}
@@ -1743,7 +1770,7 @@ tracker_data_insert_statement_with_uri (const gchar            *graph,
 		   cope with inference and insert blank rows */
 		class = tracker_ontologies_get_class_by_uri (object);
 		if (class != NULL) {
-			cache_create_service_decomposed (class, graph);
+			cache_create_service_decomposed (class, graph, 0, TRUE);
 		} else {
 			g_set_error (error, TRACKER_DATA_ERROR, TRACKER_DATA_ERROR_UNKNOWN_CLASS,
 			             "Class '%s' not found in the ontology", object);
@@ -1758,7 +1785,7 @@ tracker_data_insert_statement_with_uri (const gchar            *graph,
 		change = TRUE;
 	} else {
 		/* add value to metadata database */
-		change = cache_set_metadata_decomposed (property, object, graph, 0, &actual_error);
+		change = cache_set_metadata_decomposed (property, object, 0, graph, 0, &actual_error);
 		if (actual_error) {
 			tracker_data_update_buffer_clear ();
 			g_propagate_error (error, actual_error);
@@ -1829,7 +1856,7 @@ tracker_data_insert_statement_with_string (const gchar            *graph,
 	}
 
 	/* add value to metadata database */
-	change = cache_set_metadata_decomposed (property, object, graph, 0, &actual_error);
+	change = cache_set_metadata_decomposed (property, object, 0, graph, 0, &actual_error);
 	if (actual_error) {
 		tracker_data_update_buffer_clear ();
 		g_propagate_error (error, actual_error);
@@ -2484,6 +2511,7 @@ tracker_data_replay_journal (GHashTable *classes,
                              GHashTable *properties)
 {
 	GError *journal_error = NULL;
+	static TrackerProperty *rdf_type = NULL;
 
 	tracker_db_journal_reader_init (NULL);
 
@@ -2535,7 +2563,7 @@ tracker_data_replay_journal (GHashTable *classes,
 			if (property) {
 				GError *new_error = NULL;
 
-				cache_set_metadata_decomposed (property, object, NULL, graph_id, &new_error);
+				cache_set_metadata_decomposed (property, object, 0, NULL, graph_id, &new_error);
 
 				if (new_error) {
 					g_warning ("Journal replay error: '%s'", new_error->message);
@@ -2570,7 +2598,6 @@ tracker_data_replay_journal (GHashTable *classes,
 
 			if (property) {
 				GError *new_error = NULL;
-				static TrackerProperty *rdf_type = NULL;
 
 				if (!rdf_type) {
 					rdf_type = tracker_ontologies_get_property_by_uri (RDF_PREFIX "type");



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