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



commit abfacee626ef594735d41d4f6449c1fb38005ab5
Author: Philip Van Hoof <philip codeminded be>
Date:   Thu Nov 11 10:48:13 2010 +0100

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

 src/libtracker-data/tracker-data-manager.c |   55 +++++++++++++++++++++++-----
 src/libtracker-data/tracker-property.c     |   26 +++++++++++++
 src/libtracker-data/tracker-property.h     |    3 ++
 3 files changed, 74 insertions(+), 10 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 1303bf2..9fc7da8 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -539,7 +539,17 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
 				if (!in_update) {
 					g_critical ("%s: Duplicate definition of class %s", ontology_path, subject);
 				} else {
+					TrackerProperty **properties;
+					guint n_props, i;
 					/* Reset for a correct post-check */
+
+					properties = tracker_ontologies_get_properties (&n_props);
+					for (i = 0; i < n_props; i++) {
+						if (tracker_property_get_domain (properties[i]) == class) {
+							tracker_property_set_last_multiple_values (properties[i],
+							                                           tracker_property_get_multiple_values (properties[i]));
+						}
+					}
 					tracker_class_reset_domain_indexes (class);
 					tracker_class_set_notify (class, FALSE);
 				}
@@ -576,7 +586,7 @@ 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_secondary_index (property, NULL);
@@ -683,6 +693,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
 				 * detecting the removal of a rdfs:subClassOf, please check the
 				 * tracker_data_ontology_process_changes_pre_db stuff */
 
+
 				if (found == FALSE) {
 					handle_unsupported_ontology_change (ontology_path,
 					                                    tracker_class_get_name (class),
@@ -692,6 +703,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
 					                                    error);
 				}
 			}
+
 			return;
 		}
 
@@ -1266,8 +1278,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) {
@@ -1276,6 +1289,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
@@ -3331,7 +3362,7 @@ tracker_data_manager_init (TrackerDBManagerFlags  flags,
 		 * has changed since we dealt with the file last time. */
 
 		stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
-		        "SELECT Resource.Uri, \"rdfs:Resource\".\"nao:lastModified\" FROM \"tracker:Ontology\""
+		        "SELECT Resource.Uri, \"rdfs:Resource\".\"nao:lastModified\" FROM \"tracker:Ontology\" "
 		        "INNER JOIN Resource ON Resource.ID = \"tracker:Ontology\".ID "
 		        "INNER JOIN \"rdfs:Resource\" ON \"tracker:Ontology\".ID = \"rdfs:Resource\".ID");
 
@@ -3545,14 +3576,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..9a111a4 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 = value;
+}
+
+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]