summaryrefslogtreecommitdiff
path: root/src/libtracker-sparql/bus
diff options
context:
space:
mode:
authorCarlos Garnacho <carlosg@gnome.org>2021-03-24 12:16:14 +0100
committerCarlos Garnacho <carlosg@gnome.org>2021-04-07 11:24:13 +0200
commit8ae513e9c1025cacad488782feba5b4d2f5d443d (patch)
tree679c56ee2cd1946ba34cb116befc4eeccb1e1e6b /src/libtracker-sparql/bus
parent260cd483a581bbc672af6b8e4e1bce76341676f9 (diff)
downloadtracker-8ae513e9c1025cacad488782feba5b4d2f5d443d.tar.gz
libtracker-sparql: Implement TrackerBatch for bus connection
This ATM uses the UpdateArray DBus method underneath, thus resources are converted to SPARQL update strings before sending. It could be argued that variant serialization is more compact than SPARQL updates, but I am not sure if the difference in payload is the bigger factor to take into account.
Diffstat (limited to 'src/libtracker-sparql/bus')
-rw-r--r--src/libtracker-sparql/bus/meson.build1
-rw-r--r--src/libtracker-sparql/bus/tracker-bus-batch.vala63
-rw-r--r--src/libtracker-sparql/bus/tracker-bus.vala7
3 files changed, 71 insertions, 0 deletions
diff --git a/src/libtracker-sparql/bus/meson.build b/src/libtracker-sparql/bus/meson.build
index 54629e09a..53d93c057 100644
--- a/src/libtracker-sparql/bus/meson.build
+++ b/src/libtracker-sparql/bus/meson.build
@@ -1,6 +1,7 @@
libtracker_bus = static_library('tracker-bus',
'tracker-bus.vala',
'tracker-namespace.vala',
+ 'tracker-bus-batch.vala',
'tracker-bus-fd-cursor.vala',
'tracker-bus-statement.vala',
'../../libtracker-common/libtracker-common.vapi',
diff --git a/src/libtracker-sparql/bus/tracker-bus-batch.vala b/src/libtracker-sparql/bus/tracker-bus-batch.vala
new file mode 100644
index 000000000..1993775b3
--- /dev/null
+++ b/src/libtracker-sparql/bus/tracker-bus-batch.vala
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2021, Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * Author: Carlos Garnacho <carlosg@gnome.org>
+ */
+
+public class Tracker.Bus.Batch : Tracker.Batch {
+ private DBusConnection bus;
+ private string dbus_name;
+ private string object_path;
+ private string[] updates;
+
+ public Batch (DBusConnection bus, string dbus_name, string object_path) {
+ Object ();
+ this.bus = bus;
+ this.dbus_name = dbus_name;
+ this.object_path = object_path;
+ }
+
+ public override void add_sparql (string sparql) {
+ updates += sparql;
+ }
+
+ public override void add_resource (string? graph, Resource resource) {
+ var namespaces = this.connection.get_namespace_manager ();
+ var sparql = resource.print_sparql_update (namespaces, graph);
+ updates += sparql;
+ }
+
+ public override bool execute (GLib.Cancellable? cancellable) throws Sparql.Error, GLib.Error, GLib.IOError, GLib.DBusError {
+ // use separate main context for sync operation
+ var context = new MainContext ();
+ var loop = new MainLoop (context, false);
+ context.push_thread_default ();
+ AsyncResult async_res = null;
+ execute_async.begin (cancellable, (o, res) => {
+ async_res = res;
+ loop.quit ();
+ });
+ loop.run ();
+ context.pop_thread_default ();
+ return execute_async.end (async_res);
+ }
+
+ public async override bool execute_async (GLib.Cancellable? cancellable) throws Sparql.Error, GLib.Error, GLib.IOError, GLib.DBusError {
+ return yield Tracker.Bus.Connection.perform_update_array (bus, dbus_name, object_path, updates, cancellable);
+ }
+}
diff --git a/src/libtracker-sparql/bus/tracker-bus.vala b/src/libtracker-sparql/bus/tracker-bus.vala
index d238f12e2..a31b2df10 100644
--- a/src/libtracker-sparql/bus/tracker-bus.vala
+++ b/src/libtracker-sparql/bus/tracker-bus.vala
@@ -372,4 +372,11 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
public override Tracker.NamespaceManager? get_namespace_manager () {
return namespaces;
}
+
+ public override Tracker.Batch? create_batch () {
+ var batch = (Tracker.Batch) Object.new (typeof (Tracker.Bus.Batch),
+ "connection", this,
+ null);
+ return batch;
+ }
}