[tracker/wip/carlosg/resources-as-cursors: 4/18] libtracker-sparql: Pass namespace manager explicitly to TrackerSerializer
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/resources-as-cursors: 4/18] libtracker-sparql: Pass namespace manager explicitly to TrackerSerializer
- Date: Mon, 11 Jul 2022 18:57:49 +0000 (UTC)
commit a2efb8b6b3c1d1b3ed611cc648fe29c74cc7ee7d
Author: Carlos Garnacho <carlosg gnome org>
Date: Sat Jul 2 19:46:17 2022 +0200
libtracker-sparql: Pass namespace manager explicitly to TrackerSerializer
Implementations of this object poked the given cursor's connection in order
to get a TrackerNamespaceManager. This usually works with cursors from
queries, but we want to use serializers with data not necessarily coming
from a connection, so pass explicitly the TrackerNamespaceManager to use
during serialization.
.../direct/tracker-direct-statement.c | 4 ++-
src/libtracker-sparql/direct/tracker-direct.c | 5 +++-
src/libtracker-sparql/tracker-endpoint-http.c | 6 +++-
src/libtracker-sparql/tracker-serializer-trig.c | 4 +--
src/libtracker-sparql/tracker-serializer-turtle.c | 4 +--
src/libtracker-sparql/tracker-serializer.c | 35 +++++++++++++++++++++-
src/libtracker-sparql/tracker-serializer.h | 3 ++
7 files changed, 51 insertions(+), 10 deletions(-)
---
diff --git a/src/libtracker-sparql/direct/tracker-direct-statement.c
b/src/libtracker-sparql/direct/tracker-direct-statement.c
index f23901213..8ff95c8fb 100644
--- a/src/libtracker-sparql/direct/tracker-direct-statement.c
+++ b/src/libtracker-sparql/direct/tracker-direct-statement.c
@@ -253,7 +253,9 @@ serialize_in_thread (GTask *task,
conn = tracker_sparql_statement_get_connection (object);
tracker_direct_connection_update_timestamp (TRACKER_DIRECT_CONNECTION (conn));
tracker_sparql_cursor_set_connection (cursor, conn);
- istream = tracker_serializer_new (cursor, convert_format (data->format));
+ istream = tracker_serializer_new (cursor,
+ tracker_sparql_connection_get_namespace_manager (conn),
+ convert_format (data->format));
out:
g_clear_object (&cursor);
diff --git a/src/libtracker-sparql/direct/tracker-direct.c b/src/libtracker-sparql/direct/tracker-direct.c
index 7b8b1fab1..0cef224e0 100644
--- a/src/libtracker-sparql/direct/tracker-direct.c
+++ b/src/libtracker-sparql/direct/tracker-direct.c
@@ -322,6 +322,7 @@ serialize_in_thread (GTask *task,
TrackerDirectConnection *conn;
TrackerSparql *query = NULL;
TrackerSparqlCursor *cursor = NULL;
+ TrackerNamespaceManager *namespaces;
GInputStream *istream = NULL;
SerializeRdf *data = task_data->data;
GError *error = NULL;
@@ -345,7 +346,9 @@ serialize_in_thread (GTask *task,
goto out;
tracker_sparql_cursor_set_connection (cursor, TRACKER_SPARQL_CONNECTION (conn));
- istream = tracker_serializer_new (cursor, convert_format (data->format));
+ namespaces = tracker_sparql_connection_get_namespace_manager (TRACKER_SPARQL_CONNECTION (conn));
+ istream = tracker_serializer_new (cursor, namespaces,
+ convert_format (data->format));
out:
g_clear_object (&query);
diff --git a/src/libtracker-sparql/tracker-endpoint-http.c b/src/libtracker-sparql/tracker-endpoint-http.c
index 00395a690..c5829494f 100644
--- a/src/libtracker-sparql/tracker-endpoint-http.c
+++ b/src/libtracker-sparql/tracker-endpoint-http.c
@@ -107,6 +107,7 @@ query_async_cb (GObject *object,
{
TrackerEndpointHttp *endpoint_http;
TrackerSparqlCursor *cursor;
+ TrackerSparqlConnection *conn;
Request *request = user_data;
GInputStream *stream;
GError *error = NULL;
@@ -124,7 +125,10 @@ query_async_cb (GObject *object,
return;
}
- stream = tracker_serializer_new (cursor, request->format);
+ conn = tracker_sparql_cursor_get_connection (cursor);
+ stream = tracker_serializer_new (cursor,
+ tracker_sparql_connection_get_namespace_manager (conn),
+ request->format);
/* Consumes the input stream */
tracker_http_server_response (endpoint_http->server,
request->request,
diff --git a/src/libtracker-sparql/tracker-serializer-trig.c b/src/libtracker-sparql/tracker-serializer-trig.c
index 71952e8ff..307bfb78c 100644
--- a/src/libtracker-sparql/tracker-serializer-trig.c
+++ b/src/libtracker-sparql/tracker-serializer-trig.c
@@ -196,7 +196,6 @@ serialize_up_to_size (TrackerSerializerTrig *serializer_trig,
{
TrackerSparqlCursor *cursor;
TrackerNamespaceManager *namespaces;
- TrackerSparqlConnection *conn;
GError *inner_error = NULL;
TrackerQuad *cur;
@@ -204,8 +203,7 @@ serialize_up_to_size (TrackerSerializerTrig *serializer_trig,
serializer_trig->data = g_string_new (NULL);
cursor = tracker_serializer_get_cursor (TRACKER_SERIALIZER (serializer_trig));
- conn = tracker_sparql_cursor_get_connection (cursor);
- namespaces = tracker_sparql_connection_get_namespace_manager (conn);
+ namespaces = tracker_serializer_get_namespaces (TRACKER_SERIALIZER (serializer_trig));
if (!serializer_trig->head_printed) {
gchar *str;
diff --git a/src/libtracker-sparql/tracker-serializer-turtle.c
b/src/libtracker-sparql/tracker-serializer-turtle.c
index b94fc85e7..fc60f2325 100644
--- a/src/libtracker-sparql/tracker-serializer-turtle.c
+++ b/src/libtracker-sparql/tracker-serializer-turtle.c
@@ -187,7 +187,6 @@ serialize_up_to_size (TrackerSerializerTurtle *serializer_ttl,
{
TrackerSparqlCursor *cursor;
TrackerNamespaceManager *namespaces;
- TrackerSparqlConnection *conn;
GError *inner_error = NULL;
TrackerTriple *cur;
@@ -195,8 +194,7 @@ serialize_up_to_size (TrackerSerializerTurtle *serializer_ttl,
serializer_ttl->data = g_string_new (NULL);
cursor = tracker_serializer_get_cursor (TRACKER_SERIALIZER (serializer_ttl));
- conn = tracker_sparql_cursor_get_connection (cursor);
- namespaces = tracker_sparql_connection_get_namespace_manager (conn);
+ namespaces = tracker_serializer_get_namespaces (TRACKER_SERIALIZER (serializer_ttl));
if (!serializer_ttl->head_printed) {
gchar *str;
diff --git a/src/libtracker-sparql/tracker-serializer.c b/src/libtracker-sparql/tracker-serializer.c
index c5ac3fe54..a95961d92 100644
--- a/src/libtracker-sparql/tracker-serializer.c
+++ b/src/libtracker-sparql/tracker-serializer.c
@@ -32,6 +32,7 @@
enum {
PROP_0,
PROP_CURSOR,
+ PROP_NAMESPACE_MANAGER,
N_PROPS
};
@@ -42,6 +43,7 @@ typedef struct _TrackerSerializerPrivate TrackerSerializerPrivate;
struct _TrackerSerializerPrivate
{
TrackerSparqlCursor *cursor;
+ TrackerNamespaceManager *namespaces;
};
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (TrackerSerializer, tracker_serializer,
@@ -55,6 +57,7 @@ tracker_serializer_finalize (GObject *object)
tracker_serializer_get_instance_private (serializer);
g_object_unref (priv->cursor);
+ g_object_unref (priv->namespaces);
G_OBJECT_CLASS (tracker_serializer_parent_class)->finalize (object);
}
@@ -72,6 +75,9 @@ tracker_serializer_set_property (GObject *object,
case PROP_CURSOR:
priv->cursor = g_value_dup_object (value);
break;
+ case PROP_NAMESPACE_MANAGER:
+ priv->namespaces = g_value_dup_object (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -92,6 +98,9 @@ tracker_serializer_get_property (GObject *object,
case PROP_CURSOR:
g_value_set_object (value, priv->cursor);
break;
+ case PROP_NAMESPACE_MANAGER:
+ g_value_set_object (value, priv->namespaces);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -116,6 +125,15 @@ tracker_serializer_class_init (TrackerSerializerClass *klass)
G_PARAM_STATIC_STRINGS |
G_PARAM_READABLE |
G_PARAM_WRITABLE);
+ props[PROP_NAMESPACE_MANAGER] =
+ g_param_spec_object ("namespace-manager",
+ "Namespace Manager",
+ "Namespace Manager",
+ TRACKER_TYPE_NAMESPACE_MANAGER,
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS |
+ G_PARAM_READABLE |
+ G_PARAM_WRITABLE);
g_object_class_install_properties (object_class, N_PROPS, props);
}
@@ -127,6 +145,7 @@ tracker_serializer_init (TrackerSerializer *serializer)
GInputStream *
tracker_serializer_new (TrackerSparqlCursor *cursor,
+ TrackerNamespaceManager *namespaces,
TrackerSerializerFormat format)
{
GType type;
@@ -151,7 +170,10 @@ tracker_serializer_new (TrackerSparqlCursor *cursor,
return NULL;
}
- return g_object_new (type, "cursor", cursor, NULL);
+ return g_object_new (type,
+ "cursor", cursor,
+ "namespace-manager", namespaces,
+ NULL);
}
TrackerSparqlCursor *
@@ -164,3 +186,14 @@ tracker_serializer_get_cursor (TrackerSerializer *serializer)
return priv->cursor;
}
+
+TrackerNamespaceManager *
+tracker_serializer_get_namespaces (TrackerSerializer *serializer)
+{
+ TrackerSerializerPrivate *priv =
+ tracker_serializer_get_instance_private (serializer);
+
+ g_return_val_if_fail (TRACKER_IS_SERIALIZER (serializer), NULL);
+
+ return priv->namespaces;
+}
diff --git a/src/libtracker-sparql/tracker-serializer.h b/src/libtracker-sparql/tracker-serializer.h
index b0c54d8e0..37a58c8b6 100644
--- a/src/libtracker-sparql/tracker-serializer.h
+++ b/src/libtracker-sparql/tracker-serializer.h
@@ -33,8 +33,11 @@ G_DECLARE_DERIVABLE_TYPE (TrackerSerializer,
GInputStream)
GInputStream * tracker_serializer_new (TrackerSparqlCursor *cursor,
+ TrackerNamespaceManager *namespaces,
TrackerSerializerFormat format);
TrackerSparqlCursor * tracker_serializer_get_cursor (TrackerSerializer *serializer);
+TrackerNamespaceManager * tracker_serializer_get_namespaces (TrackerSerializer *serializer);
+
#endif /* TRACKER_SERIALIZER_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]