[tracker/wip/sam/resource: 20/22] libtracker-sparql: addition of namespacemanager to sparql writer
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/sam/resource: 20/22] libtracker-sparql: addition of namespacemanager to sparql writer
- Date: Fri, 8 Apr 2016 17:19:15 +0000 (UTC)
commit dbb864a7aa0a7635cdb66ee781f99682d1f21522
Author: Sam Thursfield <sam afuera me uk>
Date: Fri Apr 8 18:08:07 2016 +0100
libtracker-sparql: addition of namespacemanager to sparql writer
src/libtracker-sparql/tracker-resource.c | 43 ++++++++++++++---------------
src/libtracker-sparql/tracker-resource.h | 2 +-
2 files changed, 22 insertions(+), 23 deletions(-)
---
diff --git a/src/libtracker-sparql/tracker-resource.c b/src/libtracker-sparql/tracker-resource.c
index e3148a2..e930a8b 100644
--- a/src/libtracker-sparql/tracker-resource.c
+++ b/src/libtracker-sparql/tracker-resource.c
@@ -638,15 +638,12 @@ tracker_resource_print_jsonld (TrackerResource *resource,
}
typedef struct {
+ TrackerNamespaceManager *namespaces;
TrackerSparqlBuilder *builder;
const char *graph_id;
GList *done_list;
-} GenerateSparqlRelationsData;
-
-typedef struct {
- TrackerSparqlBuilder *builder;
GHashTable *overwrite_flags;
-} GenerateSparqlDeletesData;
+} GenerateSparqlData;
static void
generate_sparql_relations_foreach (gpointer key,
@@ -655,7 +652,7 @@ generate_sparql_relations_foreach (gpointer key,
{
const char *property = key;
const GValue *value = value_ptr;
- GenerateSparqlRelationsData *data = user_data;
+ GenerateSparqlData *data = user_data;
GError *error = NULL;
if (G_VALUE_HOLDS (value, TRACKER_TYPE_RESOURCE)) {
@@ -685,7 +682,7 @@ generate_sparql_deletes_foreach (gpointer key,
{
const char *property = key;
const GValue *value = value_ptr;
- GenerateSparqlDeletesData *data = user_data;
+ GenerateSparqlData *data = user_data;
/* Whether to generate the DELETE is based on whether set_value was ever
* called for this property. That's tracked in a hash table.
@@ -750,19 +747,23 @@ generate_sparql_inserts_foreach (gpointer key,
{
const char *property = key;
const GValue *value = value_ptr;
- TrackerSparqlBuilder *builder = TRACKER_SPARQL_BUILDER (user_data);
+ GenerateSparqlData *data = user_data;
+ char *full_property;
- /* FIXME: shouldn't be hardcoding this compact URI... */
- if (strcmp (property, "rdf:type") == 0) {
- tracker_sparql_builder_predicate (builder, "a");
+ full_property = tracker_namespace_manager_expand_uri (data->namespaces, property);
+
+ if (strcmp (full_property, TRACKER_PREFIX_RDF "type") == 0) {
+ tracker_sparql_builder_predicate (data->builder, "a");
} else {
- tracker_sparql_builder_predicate (builder, property);
+ tracker_sparql_builder_predicate (data->builder, property);
}
+ g_free (full_property);
+
if (G_VALUE_TYPE (value) == G_TYPE_PTR_ARRAY) {
- g_ptr_array_foreach (g_value_get_boxed (value), (GFunc)append_value_to_sparql_builder,
builder);
+ g_ptr_array_foreach (g_value_get_boxed (value), (GFunc)append_value_to_sparql_builder,
data->builder);
} else {
- append_value_to_sparql_builder (value, builder);
+ append_value_to_sparql_builder (value, data->builder);
}
}
@@ -783,12 +784,12 @@ generate_sparql_inserts_foreach (gpointer key,
void
tracker_resource_generate_sparql_update (TrackerResource *resource,
TrackerSparqlBuilder *builder,
+ TrackerNamespaceManager *namespaces,
const char *graph_id,
GError **error)
{
TrackerResourcePrivate *priv = GET_PRIVATE (resource);
- GenerateSparqlRelationsData relations_data;
- GenerateSparqlDeletesData deletes_data;
+ GenerateSparqlData data;
if (! priv->identifier) {
/* FIXME: use GError? */
@@ -808,8 +809,10 @@ tracker_resource_generate_sparql_update (TrackerResource *resource,
tracker_sparql_builder_subject_iri (builder, priv->identifier);
- deletes_data.builder = builder;
- deletes_data.overwrite_flags = priv->overwrite;
+ data.builder = builder;
+ data.overwrite_flags = priv->overwrite;
+ data.graph_id = graph_id;
+ data.done_list = NULL;
g_hash_table_foreach (priv->properties, generate_sparql_deletes_foreach, &deletes_data);
@@ -819,10 +822,6 @@ tracker_resource_generate_sparql_update (TrackerResource *resource,
tracker_sparql_builder_where_close (builder);
/* Now emit any sub-resources. */
- relations_data.builder = builder;
- relations_data.graph_id = graph_id;
- relations_data.done_list = NULL;
-
g_hash_table_foreach (priv->properties, generate_sparql_relations_foreach, &relations_data);
/* Finally insert the rest of the data */
diff --git a/src/libtracker-sparql/tracker-resource.h b/src/libtracker-sparql/tracker-resource.h
index e6daff9..e300534 100644
--- a/src/libtracker-sparql/tracker-resource.h
+++ b/src/libtracker-sparql/tracker-resource.h
@@ -66,7 +66,7 @@ gint tracker_resource_identifier_compare_func (TrackerResource *resource, const
char *tracker_resource_print_jsonld (TrackerResource *self, GError **error);
-void tracker_resource_generate_sparql_update (TrackerResource *self, TrackerSparqlBuilder *builder, const
char *graph_id, GError **error);
+void tracker_resource_generate_sparql_update (TrackerResource *self, TrackerSparqlBuilder *builder,
TrackerNamespaceManager *namespaces, const char *graph_id, GError **error);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]