[tracker/wip/carlosg/deserialize-api: 12/17] core: Handle conversion of values for superproperties with differing types
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/deserialize-api: 12/17] core: Handle conversion of values for superproperties with differing types
- Date: Thu, 30 Jun 2022 21:57:56 +0000 (UTC)
commit 1bb8184792b5c62d27916090a99f2323b7974f01
Author: Carlos Garnacho <carlosg gnome org>
Date: Thu Jun 30 00:30:36 2022 +0200
core: Handle conversion of values for superproperties with differing types
This is not quite correct, but it is the most straightforward way to sort
of handle situations in our own Nepomuk ontology that superproperties have
different rdfs:range than their subproperties.
For these cases, handle the conversion of the value. Since the worst case
(and the one we happen to exercise) is about converting resource ROWIDs to
strings, handle this specific situation.
This helps in serialization and deserialization of this data, since the
ROWIDs were not something that could be replicated in other databases
without mismatches (e.g. the resource having a different ROWID in the
new database importing the data) or worse (e.g. cardinality or other
constraints broken).
src/libtracker-sparql/core/tracker-data-update.c | 60 +++++++++++++++++++++++-
1 file changed, 58 insertions(+), 2 deletions(-)
---
diff --git a/src/libtracker-sparql/core/tracker-data-update.c
b/src/libtracker-sparql/core/tracker-data-update.c
index 3626ac514..8880ea52b 100644
--- a/src/libtracker-sparql/core/tracker-data-update.c
+++ b/src/libtracker-sparql/core/tracker-data-update.c
@@ -1784,6 +1784,36 @@ process_domain_indexes (TrackerData *data,
}
}
+static gboolean
+maybe_convert_value (TrackerData *data,
+ TrackerPropertyType source,
+ TrackerPropertyType target,
+ const GValue *value,
+ GValue *value_out)
+{
+ if (source == TRACKER_PROPERTY_TYPE_RESOURCE &&
+ target == TRACKER_PROPERTY_TYPE_STRING &&
+ G_VALUE_HOLDS_INT64 (value)) {
+ TrackerDBInterface *iface;
+ gchar *str;
+
+ iface = tracker_data_manager_get_writable_db_interface (data->manager);
+ str = tracker_data_query_resource_urn (data->manager, iface,
+ g_value_get_int64 (value));
+
+ if (!str) {
+ str = g_strdup_printf ("urn:bnode:%" G_GINT64_FORMAT,
+ g_value_get_int64 (value));
+ }
+
+ g_value_init (value_out, G_TYPE_STRING);
+ g_value_take_string (value_out, str);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
static gboolean
cache_insert_metadata_decomposed (TrackerData *data,
TrackerProperty *property,
@@ -1815,6 +1845,8 @@ cache_insert_metadata_decomposed (TrackerData *data,
while (*super_properties) {
gboolean super_is_multi;
GArray *super_old_values;
+ GValue converted = G_VALUE_INIT;
+ const GValue *val;
super_is_multi = tracker_property_get_multiple_values (*super_properties);
super_old_values = get_old_property_values (data, *super_properties, &new_error);
@@ -1826,14 +1858,25 @@ cache_insert_metadata_decomposed (TrackerData *data,
data->resource_buffer->fts_updated |=
tracker_property_get_fulltext_indexed (*super_properties);
+ if (maybe_convert_value (data,
+ tracker_property_get_data_type (property),
+ tracker_property_get_data_type (*super_properties),
+ object,
+ &converted))
+ val = &converted;
+ else
+ val = object;
+
if (super_is_multi || super_old_values->len == 0) {
- change |= cache_insert_metadata_decomposed (data, *super_properties, object,
+ change |= cache_insert_metadata_decomposed (data, *super_properties, val,
&new_error);
if (new_error) {
+ g_value_unset (&converted);
g_propagate_error (error, new_error);
return FALSE;
}
}
+ g_value_unset (&converted);
super_properties++;
}
@@ -1960,8 +2003,21 @@ delete_metadata_decomposed (TrackerData *data,
/* also delete super property values */
super_properties = tracker_property_get_super_properties (property);
while (*super_properties) {
- change |= delete_metadata_decomposed (data, *super_properties, object, error);
+ GValue converted = G_VALUE_INIT;
+ const GValue *val;
+
+ if (maybe_convert_value (data,
+ tracker_property_get_data_type (property),
+ tracker_property_get_data_type (*super_properties),
+ object,
+ &converted))
+ val = &converted;
+ else
+ val = object;
+
+ change |= delete_metadata_decomposed (data, *super_properties, val, error);
super_properties++;
+ g_value_unset (&converted);
}
return change;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]