[tracker] libtracker-data: Detect removal of nrl:maxCardinality in ontology and cope



commit 00199c35d704a39981c6c3f7345acdcf071427bc
Author: Philip Van Hoof <philip codeminded be>
Date:   Wed Nov 10 13:41:38 2010 +0100

    libtracker-data: Detect removal of nrl:maxCardinality in ontology and cope
    
    Fixes NB#202275

 src/libtracker-data/tracker-data-manager.c |   43 ++++++++++++++++++++++------
 src/libtracker-data/tracker-property.c     |   26 +++++++++++++++++
 src/libtracker-data/tracker-property.h     |    3 ++
 3 files changed, 63 insertions(+), 9 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 4a73f40..a6a34ec 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -576,9 +576,10 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
 				if (!in_update) {
 					g_critical ("%s: Duplicate definition of property %s", ontology_path, subject);
 				} else {
-					/* Reset for a correct post-check */
+					/* Reset for a correct post and pre-check */
 					tracker_property_reset_domain_indexes (property);
 					tracker_property_set_indexed (property, FALSE);
+					tracker_property_set_last_multiple_values (property, FALSE);
 					tracker_property_set_secondary_index (property, NULL);
 					tracker_property_set_writeback (property, FALSE);
 					tracker_property_set_default_value (property, NULL);
@@ -1254,8 +1255,9 @@ check_for_deleted_domain_index (TrackerClass *class)
 }
 
 static void
-tracker_data_ontology_process_changes_pre_db (GPtrArray *seen_classes,
-                                              GPtrArray *seen_properties)
+tracker_data_ontology_process_changes_pre_db (GPtrArray  *seen_classes,
+                                              GPtrArray  *seen_properties,
+                                              GError    **error)
 {
 	gint i;
 	if (seen_classes) {
@@ -1264,6 +1266,24 @@ tracker_data_ontology_process_changes_pre_db (GPtrArray *seen_classes,
 			check_for_deleted_domain_index (class);
 		}
 	}
+
+	if (seen_properties) {
+		for (i = 0; i < seen_properties->len; i++) {
+			TrackerProperty *property = g_ptr_array_index (seen_properties, i);
+			gboolean last_multiple_values = tracker_property_get_last_multiple_values (property);
+
+			if (last_multiple_values != tracker_property_get_multiple_values (property)) {
+				const gchar *ontology_path = "Unknown";
+				const gchar *subject = tracker_property_get_uri (property);
+
+				handle_unsupported_ontology_change (ontology_path,
+				                                    subject,
+				                                    "nrl:maxCardinality", "1", "0",
+				                                    error);
+				return;
+			}
+		}
+	}
 }
 
 static void
@@ -2175,6 +2195,7 @@ db_get_static_data (TrackerDBInterface *iface)
 			tracker_property_set_domain (property, tracker_ontologies_get_class_by_uri (domain_uri));
 			tracker_property_set_range (property, tracker_ontologies_get_class_by_uri (range_uri));
 			tracker_property_set_multiple_values (property, multi_valued);
+			tracker_property_set_last_multiple_values (property, multi_valued);
 			tracker_property_set_indexed (property, indexed);
 			tracker_property_set_default_value (property, default_value);
 
@@ -3533,14 +3554,18 @@ tracker_data_manager_init (TrackerDBManagerFlags  flags,
 		if (to_reload) {
 			GError *ontology_error = NULL;
 
-			tracker_data_ontology_process_changes_pre_db (seen_classes, seen_properties);
+			tracker_data_ontology_process_changes_pre_db (seen_classes,
+			                                              seen_properties,
+			                                              &ontology_error);
 
-			/* Perform ALTER-TABLE and CREATE-TABLE calls for all that are is_new */
-			tracker_data_ontology_import_into_db (TRUE);
+			if (!ontology_error) {
+				/* Perform ALTER-TABLE and CREATE-TABLE calls for all that are is_new */
+				tracker_data_ontology_import_into_db (TRUE);
 
-			tracker_data_ontology_process_changes_post_db (seen_classes,
-			                                               seen_properties,
-			                                               &ontology_error);
+				tracker_data_ontology_process_changes_post_db (seen_classes,
+				                                               seen_properties,
+				                                               &ontology_error);
+			}
 
 			if (ontology_error && ontology_error->code == TRACKER_DATA_UNSUPPORTED_ONTOLOGY_CHANGE) {
 				g_debug ("\nUnsupported ontology change, replaying journal\n");
diff --git a/src/libtracker-data/tracker-property.c b/src/libtracker-data/tracker-property.c
index d29754f..2f17ded 100644
--- a/src/libtracker-data/tracker-property.c
+++ b/src/libtracker-data/tracker-property.c
@@ -57,6 +57,7 @@ struct _TrackerPropertyPrivate {
 	gboolean       fulltext_no_limit;
 	gboolean       embedded;
 	gboolean       multiple_values;
+	gboolean       last_multiple_values;
 	gboolean       transient;
 	gboolean       is_inverse_functional_property;
 	gboolean       is_new;
@@ -468,6 +469,18 @@ tracker_property_get_multiple_values (TrackerProperty *property)
 }
 
 gboolean
+tracker_property_get_last_multiple_values (TrackerProperty *property)
+{
+	TrackerPropertyPrivate *priv;
+
+	g_return_val_if_fail (TRACKER_IS_PROPERTY (property), FALSE);
+
+	priv = GET_PRIV (property);
+
+	return priv->last_multiple_values;
+}
+
+gboolean
 tracker_property_get_is_inverse_functional_property (TrackerProperty *property)
 {
 	TrackerPropertyPrivate *priv;
@@ -869,6 +882,19 @@ tracker_property_set_multiple_values (TrackerProperty *property,
 }
 
 void
+tracker_property_set_last_multiple_values (TrackerProperty *property,
+                                           gboolean         value)
+{
+	TrackerPropertyPrivate *priv;
+
+	g_return_if_fail (TRACKER_IS_PROPERTY (property));
+
+	priv = GET_PRIV (property);
+
+	priv->last_multiple_values = TRUE;
+}
+
+void
 tracker_property_set_is_inverse_functional_property (TrackerProperty *property,
                                                      gboolean         value)
 {
diff --git a/src/libtracker-data/tracker-property.h b/src/libtracker-data/tracker-property.h
index ee61a8d..d831938 100644
--- a/src/libtracker-data/tracker-property.h
+++ b/src/libtracker-data/tracker-property.h
@@ -89,6 +89,7 @@ gboolean            tracker_property_get_fulltext_indexed    (TrackerProperty
 gboolean            tracker_property_get_fulltext_no_limit   (TrackerProperty      *property);
 gboolean            tracker_property_get_embedded            (TrackerProperty      *property);
 gboolean            tracker_property_get_multiple_values     (TrackerProperty      *property);
+gboolean            tracker_property_get_last_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,
@@ -126,6 +127,8 @@ void                tracker_property_set_embedded            (TrackerProperty
                                                               gboolean              value);
 void                tracker_property_set_multiple_values     (TrackerProperty      *property,
                                                               gboolean              value);
+void                tracker_property_set_last_multiple_values(TrackerProperty      *property,
+                                                              gboolean              value);
 void                tracker_property_set_transient           (TrackerProperty      *property,
                                                               gboolean              value);
 void                tracker_property_set_is_new              (TrackerProperty      *property,



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