89
_tracker_sparql_connection_insert_or_replace_triple (TrackerSparqlConnection *connection,
90
GCancellable *cancellable,
93
const gchar *resource,
94
const gchar *property_name,
95
const gchar *property_value)
99
gboolean retval = TRUE;
101
graph_str = _tracker_utils_format_into_graph (graph);
103
insert = g_string_new (NULL);
104
g_string_append_printf
106
"INSERT OR REPLACE %s { <%s> a nie:InformationElement ; %s \"%s\" }",
107
graph_str, resource, property_name, property_value);
109
g_debug ("Insert or replace triple: query %s", insert->str);
111
tracker_sparql_connection_update (connection, insert->str,
112
G_PRIORITY_DEFAULT, cancellable,
115
g_string_free (insert, TRUE);
126
_tracker_sparql_connection_set_triple (TrackerSparqlConnection *connection,
127
GCancellable *cancellable,
130
const gchar *resource,
131
const gchar *property_name,
132
const gchar *property_value)
135
gboolean retval = TRUE;
137
delete = g_string_new (NULL);
138
g_string_append_printf
140
"DELETE { <%s> %s ?val } WHERE { <%s> %s ?val }", resource,
141
property_name, resource, property_name);
143
tracker_sparql_connection_update (connection, delete->str,
144
G_PRIORITY_DEFAULT, cancellable,
147
g_string_free (delete, TRUE);
155
_tracker_sparql_connection_insert_or_replace_triple (connection,
158
property_name, property_value);
165
84
_tracker_utils_ensure_contact_resource (TrackerSparqlConnection *connection,
166
85
GCancellable *cancellable,
255
_tracker_sparql_connection_ensure_resource (TrackerSparqlConnection *connection,
256
GCancellable *cancellable,
259
const gchar *identifier,
263
GString *select, *insert, *inner;
266
TrackerSparqlCursor *cursor;
268
gchar *retval = NULL;
270
GVariant *insert_res;
272
gchar *key = NULL, *val = NULL;
274
/* build the inner query with all the classes */
275
va_start (args, class);
276
inner = g_string_new (NULL);
278
for (arg = class; arg != NULL; arg = va_arg (args, const gchar *))
279
g_string_append_printf (inner, " a %s; ", arg);
281
g_string_append_printf (inner, "nao:identifier \"%s\"", identifier);
285
/* query if such a resource is already in the DB */
286
select = g_string_new (NULL);
287
g_string_append_printf (select,
288
"SELECT ?urn WHERE { ?urn %s }", inner->str);
290
cursor = tracker_sparql_connection_query (connection,
294
g_string_free (select, TRUE);
299
res = tracker_sparql_cursor_next (cursor, cancellable, error);
306
/* return the found resource */
307
retval = g_strdup (tracker_sparql_cursor_get_string (cursor, 0, NULL));
308
g_debug ("Found resource in the store: %s", retval);
312
/* not found, create the resource */
313
insert = g_string_new (NULL);
314
graph_str = _tracker_utils_format_into_graph (graph);
316
g_string_append_printf (insert, "INSERT %s { _:res %s }",
317
graph_str, inner->str);
319
g_string_free (inner, TRUE);
322
tracker_sparql_connection_update_blank (connection, insert->str,
323
G_PRIORITY_DEFAULT, NULL, error);
325
g_string_free (insert, TRUE);
330
/* the result is an "aaa{ss}" variant */
331
g_variant_get (insert_res, "aaa{ss}", &iter);
332
g_variant_iter_next (iter, "aa{ss}", &iter);
333
g_variant_iter_next (iter, "a{ss}", &iter);
334
g_variant_iter_next (iter, "{ss}", &key, &val);
336
g_variant_iter_free (iter);
337
g_variant_unref (insert_res);
339
if (g_strcmp0 (key, "res") == 0)
349
g_debug ("Created a new resource: %s", retval);
352
g_clear_object (&cursor);
357
175
GdGDataMiner *self;
529
347
datasource_urn = g_strdup_printf ("gd:goa-account:%s",
530
348
goa_account_get_id (job->account));
531
_tracker_sparql_connection_set_triple
349
gd_miner_tracker_sparql_connection_set_triple
532
350
(job->connection, job->cancellable, error,
533
351
identifier, resource,
534
352
"nie:dataSource", datasource_urn);
559
377
parent_resource_id =
560
378
g_strdup_printf ("gd:collection:%s", gdata_link_get_uri (parent));
562
parent_resource_urn = _tracker_sparql_connection_ensure_resource
380
parent_resource_urn = gd_miner_tracker_sparql_connection_ensure_resource
563
381
(job->connection, job->cancellable, error,
564
382
NULL, parent_resource_id,
565
383
"nfo:RemoteDataObject", "nfo:DataContainer", NULL);