[tracker] libtracker-data: Fix for tracker:domainIndex ontology changing



commit 62197a2546d0bedfa48093fd06a92bd329363ae5
Author: Philip Van Hoof <philip codeminded be>
Date:   Tue Nov 9 11:08:54 2010 +0100

    libtracker-data: Fix for tracker:domainIndex ontology changing
    
    When you set the tracker:domainIndex to a specific property twice,
    for example two classes get nie:title, then the ontology change
    coping was failing because the registration that the change has to
    happen was done on nie:title. Making each occurrence of a domain-
    index on nie:title be detected as changed. This commit fixes that.

 src/libtracker-data/tracker-data-manager.c |   23 ++++++-----
 src/libtracker-data/tracker-property.c     |   59 ++++++++++++++++++++++++++--
 src/libtracker-data/tracker-property.h     |    4 +-
 3 files changed, 71 insertions(+), 15 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index a209719..4a73f40 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -786,7 +786,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
 
 		if (!ignore) {
 			if (!had) {
-				tracker_property_set_is_new_domain_index (property, in_update);
+				tracker_property_set_is_new_domain_index (property, class, in_update);
 			}
 			tracker_class_add_domain_index (class, property);
 			tracker_property_add_domain_index (property, class);
@@ -1210,7 +1210,7 @@ check_for_deleted_domain_index (TrackerClass *class)
 				 * functionality that'll recreate the table to know that the
 				 * property must be involved in the recreation and copy */
 
-				tracker_property_set_is_new_domain_index (properties[i], TRUE);
+				tracker_property_set_is_new_domain_index (properties[i], class, TRUE);
 			}
 		}
 
@@ -1218,7 +1218,7 @@ check_for_deleted_domain_index (TrackerClass *class)
 			TrackerProperty *prop = l->data;
 			g_debug ("Ontology change: keeping tracker:domainIndex: %s",
 			         tracker_property_get_name (prop));
-			tracker_property_set_is_new_domain_index (prop, TRUE);
+			tracker_property_set_is_new_domain_index (prop, class, TRUE);
 		}
 
 		for (l = deleted; l != NULL; l = l->next) {
@@ -2167,7 +2167,7 @@ db_get_static_data (TrackerDBInterface *iface)
 
 			default_value = tracker_db_cursor_get_string (cursor, 13, NULL);
 
-			tracker_property_set_is_new_domain_index (property, FALSE);
+			tracker_property_set_is_new_domain_index (property, tracker_ontologies_get_class_by_uri (domain_uri), FALSE);
 			tracker_property_set_is_new (property, FALSE);
 			tracker_property_set_transient (property, transient);
 			tracker_property_set_uri (property, uri);
@@ -2300,6 +2300,7 @@ static void
 create_decomposed_metadata_property_table (TrackerDBInterface *iface,
                                            TrackerProperty    *property,
                                            const gchar        *service_name,
+                                           TrackerClass       *service,
                                            const gchar       **sql_type_for_single_value,
                                            gboolean            in_update,
                                            gboolean            in_change)
@@ -2336,7 +2337,7 @@ create_decomposed_metadata_property_table (TrackerDBInterface *iface,
 	}
 
 	if (!in_update || (in_update && (tracker_property_get_is_new (property) ||
-	                                 tracker_property_get_is_new_domain_index (property) ||
+	                                 tracker_property_get_is_new_domain_index (property, service) ||
 	                                 tracker_property_get_db_schema_changed (property)))) {
 		if (transient || tracker_property_get_multiple_values (property)) {
 			GString *sql;
@@ -2622,6 +2623,7 @@ create_decomposed_metadata_tables (TrackerDBInterface *iface,
 
 			create_decomposed_metadata_property_table (iface, property,
 			                                           service_name,
+			                                           service,
 			                                           &sql_type_for_single_value,
 			                                           in_update,
 			                                           in_change);
@@ -2655,7 +2657,7 @@ create_decomposed_metadata_tables (TrackerDBInterface *iface,
 						copy_schedule = g_ptr_array_new_with_free_func (g_free);
 					}
 
-					if (is_domain_index && tracker_property_get_is_new_domain_index (property)) {
+					if (is_domain_index && tracker_property_get_is_new_domain_index (property, service)) {
 						schedule_copy (copy_schedule, property, field_name, NULL);
 					}
 
@@ -2676,7 +2678,7 @@ create_decomposed_metadata_tables (TrackerDBInterface *iface,
 					g_string_append_printf (create_sql, ", \"%s:graph\" INTEGER",
 					                        field_name);
 
-					if (is_domain_index && tracker_property_get_is_new_domain_index (property)) {
+					if (is_domain_index && tracker_property_get_is_new_domain_index (property, service)) {
 						schedule_copy (copy_schedule, property, field_name, ":graph");
 					}
 
@@ -2687,7 +2689,7 @@ create_decomposed_metadata_tables (TrackerDBInterface *iface,
 						                        tracker_property_get_name (property),
 						                        tracker_property_get_name (property));
 
-						if (is_domain_index && tracker_property_get_is_new_domain_index (property)) {
+						if (is_domain_index && tracker_property_get_is_new_domain_index (property, service)) {
 							schedule_copy (copy_schedule, property, field_name, ":localTime");
 							schedule_copy (copy_schedule, property, field_name, ":localDate");
 						}
@@ -2695,7 +2697,7 @@ create_decomposed_metadata_tables (TrackerDBInterface *iface,
 					}
 
 				} else if ((!is_domain_index && tracker_property_get_is_new (property)) ||
-				           (is_domain_index && tracker_property_get_is_new_domain_index (property))) {
+				           (is_domain_index && tracker_property_get_is_new_domain_index (property, service))) {
 					GString *alter_sql = NULL;
 
 					put_change = FALSE;
@@ -2904,6 +2906,7 @@ create_decomposed_transient_metadata_tables (TrackerDBInterface *iface)
 			/* create the TEMPORARY table */
 			create_decomposed_metadata_property_table (iface, property,
 			                                           service_name,
+			                                           domain,
 			                                           NULL, FALSE,
 			                                           FALSE);
 		}
@@ -2926,7 +2929,7 @@ tracker_data_ontology_import_finished (void)
 	}
 
 	for (i = 0; i < n_props; i++) {
-		tracker_property_set_is_new_domain_index (properties[i], FALSE);
+		tracker_property_set_is_new_domain_index (properties[i], NULL, FALSE);
 		tracker_property_set_is_new (properties[i], FALSE);
 		tracker_property_set_db_schema_changed (properties[i], FALSE);
 	}
diff --git a/src/libtracker-data/tracker-property.c b/src/libtracker-data/tracker-property.c
index d22d567..d29754f 100644
--- a/src/libtracker-data/tracker-property.c
+++ b/src/libtracker-data/tracker-property.c
@@ -63,7 +63,7 @@ struct _TrackerPropertyPrivate {
 	gboolean       db_schema_changed;
 	gboolean       writeback;
 	gchar         *default_value;
-	gboolean       is_new_domain_index;
+	GPtrArray     *is_new_domain_index;
 
 	GArray        *super_properties;
 	GArray        *domain_indexes;
@@ -153,6 +153,10 @@ property_finalize (GObject *object)
 	g_free (priv->name);
 	g_free (priv->table_name);
 
+	if (priv->is_new_domain_index) {
+		g_ptr_array_unref (priv->is_new_domain_index);
+	}
+
 	if (priv->domain) {
 		g_object_unref (priv->domain);
 	}
@@ -391,15 +395,28 @@ tracker_property_get_is_new (TrackerProperty *property)
 }
 
 gboolean
-tracker_property_get_is_new_domain_index (TrackerProperty *property)
+tracker_property_get_is_new_domain_index (TrackerProperty *property,
+                                          TrackerClass    *class)
 {
 	TrackerPropertyPrivate *priv;
+	guint i;
 
 	g_return_val_if_fail (TRACKER_IS_PROPERTY (property), FALSE);
+	g_return_val_if_fail (TRACKER_IS_CLASS (class), FALSE);
 
 	priv = GET_PRIV (property);
 
-	return priv->is_new_domain_index;
+	if (!priv->is_new_domain_index) {
+		return FALSE;
+	}
+
+	for (i = 0; i < priv->is_new_domain_index->len; i++) {
+		if (g_ptr_array_index (priv->is_new_domain_index, i) == class) {
+			return TRUE;
+		}
+	}
+
+	return FALSE;
 }
 
 gboolean
@@ -724,15 +741,49 @@ tracker_property_set_is_new (TrackerProperty *property,
 
 void
 tracker_property_set_is_new_domain_index (TrackerProperty *property,
+                                          TrackerClass    *class,
                                           gboolean         value)
 {
 	TrackerPropertyPrivate *priv;
 
 	g_return_if_fail (TRACKER_IS_PROPERTY (property));
 
+	if (class) {
+		g_return_if_fail (TRACKER_IS_CLASS (class));
+	}
+
 	priv = GET_PRIV (property);
 
-	priv->is_new_domain_index = value;
+	if (value) {
+		if (!priv->is_new_domain_index) {
+			priv->is_new_domain_index = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
+		}
+		g_ptr_array_add (priv->is_new_domain_index, g_object_ref (class));
+	} else {
+		guint i;
+		gboolean found = FALSE;
+
+		if (!priv->is_new_domain_index) {
+			return;
+		}
+
+		if (!class) {
+			g_ptr_array_unref (priv->is_new_domain_index);
+			priv->is_new_domain_index = NULL;
+			return;
+		}
+
+		for (i = 0; i < priv->is_new_domain_index->len; i++) {
+			if (g_ptr_array_index (priv->is_new_domain_index, i) == class) {
+				found = TRUE;
+				break;
+			}
+		}
+
+		if (found) {
+			g_ptr_array_remove_index (priv->is_new_domain_index, i);
+		}
+	}
 }
 
 void
diff --git a/src/libtracker-data/tracker-property.h b/src/libtracker-data/tracker-property.h
index e16c008..ee61a8d 100644
--- a/src/libtracker-data/tracker-property.h
+++ b/src/libtracker-data/tracker-property.h
@@ -91,7 +91,8 @@ 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_is_new_domain_index (TrackerProperty      *property);
+gboolean            tracker_property_get_is_new_domain_index (TrackerProperty      *property,
+                                                              TrackerClass         *class);
 gboolean            tracker_property_get_writeback           (TrackerProperty      *property);
 const gchar *       tracker_property_get_default_value       (TrackerProperty      *property);
 gboolean            tracker_property_get_db_schema_changed   (TrackerProperty      *property);
@@ -130,6 +131,7 @@ void                tracker_property_set_transient           (TrackerProperty
 void                tracker_property_set_is_new              (TrackerProperty      *property,
                                                               gboolean              value);
 void                tracker_property_set_is_new_domain_index (TrackerProperty      *property,
+                                                              TrackerClass         *class,
                                                               gboolean              value);
 void                tracker_property_set_writeback           (TrackerProperty      *property,
                                                                gboolean              value);



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