[tracker/wip/carlosg/tracker-3.0-api-breaks: 42/63] libtracker-sparql: Drop tracker_sparql_connection_get()



commit 0ac69c3db89e50bda2485717195693d1a08501bc
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Dec 15 18:26:26 2019 +0100

    libtracker-sparql: Drop tracker_sparql_connection_get()
    
    We shall no longer have a single canonical location for the triple
    store, nor a single dbus name that you can query through SPARQL.
    This singleton getter fits no longer.

 .../libtracker-sparql-sections.txt                 |   3 -
 .../reference/libtracker-sparql/migrating-2to3.xml |  34 +++
 src/libtracker-sparql-backend/tracker-backend.vala | 299 ---------------------
 src/libtracker-sparql/tracker-connection.vala      |  67 -----
 4 files changed, 34 insertions(+), 369 deletions(-)
---
diff --git a/docs/reference/libtracker-sparql/libtracker-sparql-sections.txt 
b/docs/reference/libtracker-sparql/libtracker-sparql-sections.txt
index e8519f80c..df5399e02 100644
--- a/docs/reference/libtracker-sparql/libtracker-sparql-sections.txt
+++ b/docs/reference/libtracker-sparql/libtracker-sparql-sections.txt
@@ -103,9 +103,6 @@ TRACKER_TYPE_NAMESPACE_MANAGER
 TrackerSparqlError
 TrackerSparqlConnection
 TrackerSparqlConnectionFlags
-tracker_sparql_connection_get
-tracker_sparql_connection_get_async
-tracker_sparql_connection_get_finish
 tracker_sparql_connection_new
 tracker_sparql_connection_new_async
 tracker_sparql_connection_new_finish
diff --git a/docs/reference/libtracker-sparql/migrating-2to3.xml 
b/docs/reference/libtracker-sparql/migrating-2to3.xml
index afd3f132b..c0a666d8f 100644
--- a/docs/reference/libtracker-sparql/migrating-2to3.xml
+++ b/docs/reference/libtracker-sparql/migrating-2to3.xml
@@ -150,4 +150,38 @@ ORDER BY DESC ?count
       simply returns a boolean return value.
     </para>
   </section>
+  <section>
+    <title>No tracker_sparql_connection_get()/get_async()</title>
+    <para>
+      There is no longer a singleton SPARQL connection. If you are only interested in
+      tracker-miner-fs data, you can create a dedicated DBus connection to it through:
+    </para>
+    <programlisting>
+      conn = tracker_sparql_connection_bus_new ("org.freedesktop.Tracker1.Miner.Files", ...);
+    </programlisting>
+    <para>
+      If you are interested in storing your own data, you can do it through:
+    </para>
+    <programlisting>
+      conn = tracker_sparql_connection_new (...);
+    </programlisting>
+    <para>
+      Note that you still may access other endpoints in SELECT queries, eg. for
+      tracker-miner-fs:
+    </para>
+    <programlisting>
+SELECT ?url ?tag {
+  SERVICE &lt;dbus:org.freedesktop.Tracker1.Miner.Files&gt; {
+    ?a a rdfs:Resource;
+       nie:url ?url .
+  }
+  ?b nie:url ?url;
+     nao:hasTag ?tag
+}
+    </programlisting>
+    <para>
+      This SELECT query merges together data from the tracker-miner-fs endpoint
+      with data from the local endpoint.
+    </para>
+  </section>
 </chapter>
diff --git a/src/libtracker-sparql-backend/tracker-backend.vala 
b/src/libtracker-sparql-backend/tracker-backend.vala
index 2ef9bccb1..040e3ec2b 100644
--- a/src/libtracker-sparql-backend/tracker-backend.vala
+++ b/src/libtracker-sparql-backend/tracker-backend.vala
@@ -18,307 +18,8 @@
  */
 
 static string domain_name = null;
-static Tracker.DomainOntology domain_ontology = null;
 static DBusConnection global_dbus_connection = null;
 
-class Tracker.Sparql.Backend : Connection {
-       bool initialized;
-       Tracker.Sparql.Connection direct = null;
-       Tracker.Sparql.Connection bus = null;
-       enum Backend {
-               AUTO,
-               DIRECT,
-               BUS
-       }
-
-       public Backend () throws Sparql.Error, IOError, DBusError, SpawnError {
-               try {
-                       domain_ontology = new Tracker.DomainOntology (domain_name, null);
-                       load_plugins ();
-               } catch (GLib.Error e) {
-                       throw new Sparql.Error.INTERNAL ("Failed to load SPARQL backend: " + e.message);
-               }
-
-               initialized = true;
-       }
-
-       public override void dispose () {
-               // trying to lock on partially initialized instances will deadlock
-               if (initialized) {
-                       door.lock ();
-
-                       try {
-                               // Ensure this instance is not used for any new calls to 
Tracker.Sparql.Connection.get.
-                               // However, a call to Tracker.Sparql.Connection.get between g_object_unref 
and the
-                               // above lock might have increased the reference count of this instance to 2 
(or more).
-                               // Therefore, we must not clean up direct/bus connection in dispose.
-                               if (singleton == this) {
-                                       singleton = null;
-                               }
-                       } finally {
-                               door.unlock ();
-                       }
-               }
-
-               base.dispose ();
-       }
-
-       public override Cursor query (string sparql, Cancellable? cancellable = null) throws Sparql.Error, 
IOError, DBusError, GLib.Error {
-               debug ("%s(): '%s'", GLib.Log.METHOD, sparql);
-               if (direct != null) {
-                       return direct.query (sparql, cancellable);
-               } else {
-                       return bus.query (sparql, cancellable);
-               }
-       }
-
-       public async override Cursor query_async (string sparql, Cancellable? cancellable = null) throws 
Sparql.Error, IOError, DBusError, GLib.Error {
-               debug ("%s(): '%s'", GLib.Log.METHOD, sparql);
-               if (direct != null) {
-                       return yield direct.query_async (sparql, cancellable);
-               } else {
-                       return yield bus.query_async (sparql, cancellable);
-               }
-       }
-
-       public override Statement? query_statement (string sparql, Cancellable? cancellable = null) throws 
Sparql.Error {
-               debug ("%s(): '%s'", GLib.Log.METHOD, sparql);
-               if (direct != null) {
-                       return direct.query_statement (sparql, cancellable);
-               } else {
-                       warning ("Interface 'query_statement' not implemented on dbus interface");
-                       return null;
-               }
-       }
-
-       public override void update (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? 
cancellable = null) throws Sparql.Error, IOError, DBusError, GLib.Error {
-               debug ("%s(priority:%d): '%s'", GLib.Log.METHOD, priority, sparql);
-               if (bus == null) {
-                       throw new Sparql.Error.UNSUPPORTED ("Update support not available for direct-only 
connection");
-               }
-               bus.update (sparql, priority, cancellable);
-       }
-
-       public override GLib.Variant? update_blank (string sparql, int priority = GLib.Priority.DEFAULT, 
Cancellable? cancellable = null) throws Sparql.Error, IOError, DBusError, GLib.Error {
-               debug ("%s(priority:%d): '%s'", GLib.Log.METHOD, priority, sparql);
-               if (bus == null) {
-                       throw new Sparql.Error.UNSUPPORTED ("Update support not available for direct-only 
connection");
-               }
-               return bus.update_blank (sparql, priority, cancellable);
-       }
-
-       public async override void update_async (string sparql, int priority = GLib.Priority.DEFAULT, 
Cancellable? cancellable = null) throws Sparql.Error, IOError, DBusError, GLib.Error {
-               debug ("%s(priority:%d): '%s'", GLib.Log.METHOD, priority, sparql);
-               if (bus == null) {
-                       throw new Sparql.Error.UNSUPPORTED ("Update support not available for direct-only 
connection");
-               }
-               yield bus.update_async (sparql, priority, cancellable);
-       }
-
-       public async override bool update_array_async (string[] sparql, int priority = GLib.Priority.DEFAULT, 
Cancellable? cancellable = null) throws Sparql.Error, IOError, DBusError, GLib.Error {
-               if (bus == null) {
-                       throw new Sparql.Error.UNSUPPORTED ("Update support not available for direct-only 
connection");
-               }
-               return yield bus.update_array_async (sparql, priority, cancellable);
-       }
-
-       public async override GLib.Variant? update_blank_async (string sparql, int priority = 
GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, IOError, DBusError, GLib.Error {
-               debug ("%s(priority:%d): '%s'", GLib.Log.METHOD, priority, sparql);
-               if (bus == null) {
-                       throw new Sparql.Error.UNSUPPORTED ("Update support not available for direct-only 
connection");
-               }
-               return yield bus.update_blank_async (sparql, priority, cancellable);
-       }
-
-       public override NamespaceManager? get_namespace_manager () {
-               if (direct != null)
-                       return direct.get_namespace_manager ();
-               else
-                       return NamespaceManager.get_default ();
-       }
-
-       private Connection create_readonly_direct () throws GLib.Error, Sparql.Error, IOError, DBusError {
-               var conn = new Tracker.Direct.Connection (Tracker.Sparql.ConnectionFlags.READONLY,
-                                                         domain_ontology.get_cache (),
-                                                         domain_ontology.get_ontology ());
-               conn.init ();
-               return conn;
-       }
-
-       // Plugin loading functions
-       private void load_plugins () throws GLib.Error {
-               string env_backend = Environment.get_variable ("TRACKER_SPARQL_BACKEND");
-               Backend backend = Backend.AUTO;
-
-               if (env_backend != null) {
-                       if (env_backend.ascii_casecmp ("direct") == 0) {
-                               backend = Backend.DIRECT;
-                               debug ("Using backend = 'DIRECT'");
-                       } else if (env_backend.ascii_casecmp ("bus") == 0) {
-                               backend = Backend.BUS;
-                               debug ("Using backend = 'BUS'");
-                       } else {
-                               warning ("Environment variable TRACKER_SPARQL_BACKEND set to unknown value 
'%s'", env_backend);
-                       }
-               }
-
-               if (backend == Backend.AUTO) {
-                       debug ("Using backend = 'AUTO'");
-               }
-
-               switch (backend) {
-               case Backend.AUTO:
-                       bool direct_failed = false;
-
-                       try {
-                               direct = create_readonly_direct ();
-                       } catch (DBInterfaceError e) {
-                               direct_failed = true;
-                       }
-
-                       bus = new Tracker.Bus.Connection (domain_ontology.get_domain ("Tracker1"), 
global_dbus_connection);
-
-                       if (direct_failed) {
-                               try {
-                                       direct = create_readonly_direct ();
-                               } catch (DBInterfaceError e) {
-                                       warning ("Falling back to bus backend, the direct backend failed to 
initialize: " + e.message);
-                               }
-                       }
-
-                       break;
-
-               case Backend.DIRECT:
-                       direct = create_readonly_direct ();
-                       break;
-
-               case Backend.BUS:
-                       bus = new Tracker.Bus.Connection (domain_ontology.get_domain ("Tracker1"), 
global_dbus_connection);
-                       break;
-
-               default:
-                       assert_not_reached ();
-               }
-       }
-
-       static weak Connection? singleton;
-       static Mutex door;
-
-       static new Connection get (Cancellable? cancellable = null) throws Sparql.Error, IOError, DBusError, 
SpawnError {
-               door.lock ();
-
-               try {
-                       // assign to owned variable to ensure it doesn't get freed between check and return
-                       var result = singleton;
-
-                       if (result == null) {
-                               result = new Tracker.Sparql.Backend ();
-
-                               if (cancellable != null && cancellable.is_cancelled ()) {
-                                       throw new IOError.CANCELLED ("Operation was cancelled");
-                               }
-
-                               singleton = result;
-                       }
-
-                       return result;
-               } finally {
-                       door.unlock ();
-               }
-       }
-
-       public static new Connection get_internal (Cancellable? cancellable = null) throws Sparql.Error, 
IOError, DBusError, SpawnError {
-               if (MainContext.get_thread_default () == null) {
-                       // ok to initialize without extra thread
-                       return get (cancellable);
-               }
-
-               // run with separate main context to be able to wait for async method
-               var context = new MainContext ();
-               var loop = new MainLoop (context);
-               AsyncResult async_result = null;
-
-               context.push_thread_default ();
-
-               get_internal_async.begin (cancellable, (obj, res) => {
-                       async_result = res;
-                       loop.quit ();
-               });
-
-               loop.run ();
-
-               context.pop_thread_default ();
-
-               return get_internal_async.end (async_result);
-       }
-
-       public async static new Connection get_internal_async (Cancellable? cancellable = null) throws 
Sparql.Error, IOError, DBusError, SpawnError {
-               // fast path: avoid extra thread if connection is already available
-               if (door.trylock ()) {
-                       // assign to owned variable to ensure it doesn't get freed between unlock and return
-                       var result = singleton;
-
-                       door.unlock ();
-
-                       if (result != null) {
-                               return result;
-                       }
-               }
-
-               // run in a separate thread
-               Sparql.Error sparql_error = null;
-               IOError io_error = null;
-               DBusError dbus_error = null;
-               SpawnError spawn_error = null;
-               Connection result = null;
-               var context = MainContext.get_thread_default ();
-
-               IOSchedulerJob.push (job => {
-                       try {
-                               result = get (cancellable);
-                       } catch (IOError e_io) {
-                               io_error = e_io;
-                       } catch (Sparql.Error e_spql) {
-                               sparql_error = e_spql;
-                       } catch (DBusError e_dbus) {
-                               dbus_error = e_dbus;
-                       } catch (SpawnError e_spawn) {
-                               spawn_error = e_spawn;
-                       }
-
-                       var source = new IdleSource ();
-                       source.set_callback (() => {
-                               get_internal_async.callback ();
-                               return false;
-                       });
-                       source.attach (context);
-
-                       return false;
-               }, GLib.Priority.DEFAULT);
-               yield;
-
-               if (sparql_error != null) {
-                       throw sparql_error;
-               } else if (io_error != null) {
-                       throw io_error;
-               } else if (dbus_error != null) {
-                       throw dbus_error;
-               } else if (spawn_error != null) {
-                       throw spawn_error;
-               } else {
-                       return result;
-               }
-       }
-}
-
-public async static Tracker.Sparql.Connection tracker_sparql_connection_get_async (Cancellable? cancellable 
= null) throws Tracker.Sparql.Error, IOError, DBusError, SpawnError {
-       return yield Tracker.Sparql.Backend.get_internal_async (cancellable);
-}
-
-public static Tracker.Sparql.Connection tracker_sparql_connection_get (Cancellable? cancellable = null) 
throws Tracker.Sparql.Error, IOError, DBusError, SpawnError {
-       return Tracker.Sparql.Backend.get_internal (cancellable);
-}
-
 public static Tracker.Sparql.Connection tracker_sparql_connection_remote_new (string url_base) {
        return new Tracker.Remote.Connection (url_base);
 }
diff --git a/src/libtracker-sparql/tracker-connection.vala b/src/libtracker-sparql/tracker-connection.vala
index e1fa1ff73..faabd47d8 100644
--- a/src/libtracker-sparql/tracker-connection.vala
+++ b/src/libtracker-sparql/tracker-connection.vala
@@ -76,73 +76,6 @@ public enum Tracker.Sparql.ConnectionFlags {
  * non-direct requests.
  */
 public abstract class Tracker.Sparql.Connection : Object {
-       /**
-        * tracker_sparql_connection_get_finish:
-        * @_res_: The #GAsyncResult from the callback used to return the #TrackerSparqlConnection
-        * @error: The error which occurred or %NULL
-        *
-        * This function is called from the callback provided for
-        * tracker_sparql_connection_get_async() to return the connection requested
-        * or an error in cases of failure.
-        *
-        * Returns: a new #TrackerSparqlConnection. Call g_object_unref() on the
-        * object when no longer used.
-        *
-        * Since: 0.10
-        */
-
-       /**
-        * tracker_sparql_connection_get_async:
-        * @cancellable: a #GCancellable used to cancel the operation
-        * @_callback_: user-defined #GAsyncReadyCallback to be called when
-        *              asynchronous operation is finished.
-        * @_user_data_: user-defined data to be passed to @_callback_
-        *
-        * A #TrackerSparqlConnection is returned asynchronously in the @_callback_ of
-        * your choosing. You must call tracker_sparql_connection_get_finish() to
-        * find out if the connection was returned without error.
-        *
-        * See also: tracker_sparql_connection_get().
-        *
-        * Since: 0.10
-        */
-       public extern async static new Connection get_async (Cancellable? cancellable = null) throws 
Sparql.Error, IOError, DBusError, SpawnError;
-
-       /**
-        * tracker_sparql_connection_get:
-        * @cancellable: a #GCancellable used to cancel the operation
-        * @error: #GError for error reporting.
-        *
-        * This function is used to give the caller a connection to Tracker they can
-        * use for future requests. The best backend available to connect to
-        * Tracker is returned. These backends include direct-access (for read-only
-        * queries) and D-Bus (for both read and write queries).
-        *
-        * You can use <link linkend="tracker-overview-environment-variables">
-        * environment variables</link> to influence how backends are used. If
-        * no environment variables are provided, both backends are loaded and
-        * chosen based on their merits. If you try to force a backend for a query
-        * which it won't support (i.e. an update for a read-only backend), you will
-        * see critical warnings.
-        *
-        * When calling either tracker_sparql_connection_get(),  or the asynchronous
-        * variants of these functions, a mutex is used to protect the loading of
-        * backends against potential race conditions. For synchronous calls, this
-        * function will always block if a previous connection get method has been
-        * called.
-        *
-        * All backends will call the D-Bus tracker-store API Wait() to make sure
-        * the store and databases are in the right state before any user based
-        * requests can proceed. There may be a small delay during this call if the
-        * databases weren't shutdown cleanly and need to be checked on start up.
-        *
-        * Returns: a new #TrackerSparqlConnection. Call g_object_unref() on the
-        * object when no longer used.
-        *
-        * Since: 0.10
-        */
-       public extern static new Connection get (Cancellable? cancellable = null) throws Sparql.Error, 
IOError, DBusError, SpawnError;
-
        /**
         * tracker_sparql_connection_remote_new:
         * @uri_base: Base URI of the remote connection


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]