[tracker/maxcardinality-change-support] Unfinished support for nrl:maxCardinality changing from 1 to null (many)
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/maxcardinality-change-support] Unfinished support for nrl:maxCardinality changing from 1 to null (many)
- Date: Tue, 16 Sep 2014 09:49:38 +0000 (UTC)
commit 2267dcc7f88acd7f5af033ab16dc4e129185b7e0
Author: Philip Van Hoof <philip codeminded be>
Date: Tue Sep 16 11:48:40 2014 +0200
Unfinished support for nrl:maxCardinality changing from 1 to null (many)
src/libtracker-data/tracker-data-manager.c | 81 ++++++++++++++++++++++++++-
src/libtracker-data/tracker-property.c | 27 +++++++++
src/libtracker-data/tracker-property.h | 3 +
3 files changed, 108 insertions(+), 3 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 03cb80b..73175ac 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -90,6 +90,11 @@ static Conversion allowed_boolean_conversions[] = {
{ NULL, NULL }
};
+static Conversion allowed_cardinality_conversions[] = {
+ { "1", "false" },
+ { NULL, NULL }
+};
+
static Conversion allowed_range_conversions[] = {
{ XSD_PREFIX "integer", XSD_PREFIX "string" },
{ XSD_PREFIX "integer", XSD_PREFIX "double" },
@@ -577,6 +582,7 @@ fix_indexed (TrackerProperty *property,
}
}
+
static void
tracker_data_ontology_load_statement (const gchar *ontology_path,
gint subject_id,
@@ -1067,6 +1073,8 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
if (is_new != in_update) {
/* Detect unsupported ontology change (this needs a journal replay) */
if (in_update == TRUE && is_new == FALSE) {
+
+ /* Any change in value is unsupported, only change from 1 to many is
supported */
if (check_unsupported_property_value_change (ontology_path,
"nrl:maxCardinality",
subject,
@@ -1477,7 +1485,8 @@ tracker_data_ontology_process_changes_pre_db (GPtrArray *seen_classes,
}
if (tracker_property_get_is_new (property) == FALSE &&
- last_multiple_values != tracker_property_get_multiple_values (property)) {
+ (last_multiple_values != tracker_property_get_multiple_values (property) &&
+ last_multiple_values == TRUE)) {
const gchar *ontology_path = "Unknown";
const gchar *subject = tracker_property_get_uri (property);
@@ -1600,6 +1609,33 @@ tracker_data_ontology_process_changes_post_db (GPtrArray *seen_classes,
return;
}
+ if (tracker_property_get_multiple_values (property)) {
+ update_property_value (ontology_path,
+ "nrl:maxCardinality",
+ subject,
+ NRL_PREFIX "maxCardinality",
+ "true", allowed_cardinality_conversions,
+ NULL, property, &n_error);
+ tracker_property_set_db_schema_changed (property, TRUE);
+ tracker_property_set_cardinality_changed (property, TRUE);
+ } else {
+ handle_unsupported_ontology_change (ontology_path,
+ subject,
+ "nrl:maxCardinality", "-", "-",
+ &n_error);
+
+ if (n_error) {
+ g_object_unref (cursor);
+ g_propagate_error (error, n_error);
+ return;
+ }
+ }
+
+ if (n_error) {
+ g_propagate_error (error, n_error);
+ return;
+ }
+
if (tracker_property_get_indexed (property)) {
if (update_property_value (ontology_path,
"tracker:indexed",
@@ -2658,7 +2694,8 @@ create_decomposed_metadata_property_table (TrackerDBInterface *iface,
}
}
- if (in_change && !tracker_property_get_is_new (property) && in_col_sql &&
sel_col_sql) {
+ if (in_change && !tracker_property_get_is_new (property) &&
+ !tracker_property_get_cardinality_changed (property) && in_col_sql &&
sel_col_sql) {
gchar *query;
query = g_strdup_printf ("INSERT INTO \"%s_%s\"(%s) "
@@ -3148,6 +3185,7 @@ create_decomposed_metadata_tables (TrackerDBInterface *iface,
}
if (in_change && sel_col_sql && in_col_sql) {
+ guint i;
gchar *query;
query = g_strdup_printf ("INSERT INTO \"%s\"(%s) "
@@ -3163,8 +3201,45 @@ create_decomposed_metadata_tables (TrackerDBInterface *iface,
g_propagate_error (error, internal_error);
goto error_out;
}
-
+
g_free (query);
+
+ for (i = 0; i < n_props; i++) {
+ property = properties[i];
+
+ if (tracker_property_get_domain (property) == service &&
tracker_property_get_cardinality_changed (property)) {
+ GString *n_sel_col_sql, *n_in_col_sql;
+ const gchar *field_name = tracker_property_get_name (property);
+
+ n_in_col_sql = g_string_new ("ID");
+ n_sel_col_sql = g_string_new ("ID");
+
+ /* Function does what it must do, so reusable atm */
+ range_change_for (property, n_in_col_sql, n_sel_col_sql, field_name);
+
+ /* Columns happen to be the same for decomposed multi-value and single value atm
*/
+ query = g_strdup_printf ("INSERT INTO \"%s_%s\"(%s) "
+ "SELECT %s FROM \"%s_TEMP\"",
+ service_name, field_name,
+ n_in_col_sql, n_sel_col_sql,
+ service_name);
+
+ g_string_free (n_in_col_sql, TRUE);
+ g_string_free (n_sel_col_sql, TRUE);
+
+ g_debug ("Copy supported nlr:maxCardinality change: %s", query);
+
+ tracker_db_interface_execute_query (iface, &internal_error, "%s", query);
+
+ if (internal_error) {
+ g_propagate_error (error, internal_error);
+ goto error_out;
+ }
+
+ g_free (query);
+ }
+ }
+
g_debug ("Rename (drop): DROP TABLE \"%s_TEMP\"", service_name);
tracker_db_interface_execute_query (iface, &internal_error,
"DROP TABLE \"%s_TEMP\"", service_name);
diff --git a/src/libtracker-data/tracker-property.c b/src/libtracker-data/tracker-property.c
index f79e2c8..91b6d93 100644
--- a/src/libtracker-data/tracker-property.c
+++ b/src/libtracker-data/tracker-property.c
@@ -70,6 +70,7 @@ struct _TrackerPropertyPrivate {
GArray *super_properties;
GArray *domain_indexes;
GArray *last_super_properties;
+ gboolean cardinality_changed;
};
static void property_finalize (GObject *object);
@@ -141,6 +142,7 @@ tracker_property_init (TrackerProperty *property)
priv->super_properties = g_array_new (TRUE, TRUE, sizeof (TrackerProperty *));
priv->domain_indexes = g_array_new (TRUE, TRUE, sizeof (TrackerClass *));
priv->last_super_properties = NULL;
+ priv->cardinality_changed = FALSE;
/* Make GET_PRIV working */
property->priv = priv;
@@ -549,6 +551,18 @@ tracker_property_get_db_schema_changed (TrackerProperty *property)
}
gboolean
+tracker_property_get_cardinality_changed (TrackerProperty *property)
+{
+ TrackerPropertyPrivate *priv;
+
+ g_return_val_if_fail (TRACKER_IS_PROPERTY (property), FALSE);
+
+ priv = GET_PRIV (property);
+
+ return priv->cardinality_changed;
+}
+
+gboolean
tracker_property_get_multiple_values (TrackerProperty *property)
{
TrackerPropertyPrivate *priv;
@@ -959,6 +973,19 @@ tracker_property_set_db_schema_changed (TrackerProperty *property,
}
void
+tracker_property_set_cardinality_changed (TrackerProperty *property,
+ gboolean value)
+{
+ TrackerPropertyPrivate *priv;
+
+ g_return_if_fail (TRACKER_IS_PROPERTY (property));
+
+ priv = GET_PRIV (property);
+
+ priv->cardinality_changed = value;
+}
+
+void
tracker_property_set_fulltext_indexed (TrackerProperty *property,
gboolean value)
{
diff --git a/src/libtracker-data/tracker-property.h b/src/libtracker-data/tracker-property.h
index c2a75d9..5618a12 100644
--- a/src/libtracker-data/tracker-property.h
+++ b/src/libtracker-data/tracker-property.h
@@ -95,6 +95,7 @@ gboolean tracker_property_get_is_new_domain_index (TrackerProperty
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);
+gboolean tracker_property_get_cardinality_changed (TrackerProperty *property);
gboolean tracker_property_get_is_inverse_functional_property
(TrackerProperty *property);
gboolean tracker_property_get_force_journal (TrackerProperty *property);
@@ -137,6 +138,8 @@ void tracker_property_set_default_value (TrackerProperty
const gchar *value);
void tracker_property_set_db_schema_changed (TrackerProperty *property,
gboolean value);
+void tracker_property_set_cardinality_changed (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]