From 940ca83195ba1f145a70b9dd0246f4d5aa2a069d Mon Sep 17 00:00:00 2001
From: Michael Gratton <mike@vee.net>
Date: Wed, 9 Sep 2020 18:33:44 +1000
Subject: [PATCH 005/124] Geary.Db.Context: Remove separate `logging_parent`
 property

Since each context type already has access to the object that is its
context parent, don't bother with a stand-alone `logging_parent`
property, just have context types implement it and return the
appropriate object.
---
 src/engine/db/db-context.vala             |  8 +-------
 src/engine/db/db-database-connection.vala |  6 +++++-
 src/engine/db/db-database.vala            | 10 ++++++++--
 src/engine/db/db-result.vala              |  6 ++++--
 src/engine/db/db-statement.vala           |  5 +++++
 5 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/src/engine/db/db-context.vala b/src/engine/db/db-context.vala
index 6713f6c8..2ba8b305 100644
--- a/src/engine/db/db-context.vala
+++ b/src/engine/db/db-context.vala
@@ -33,8 +33,7 @@ public abstract class Geary.Db.Context : BaseObject, Logging.Source {
     }
 
     /** {@inheritDoc} */
-    public Logging.Source? logging_parent { get { return _logging_parent; } }
-    private weak Logging.Source? _logging_parent = null;
+    public abstract Logging.Source? logging_parent { get; }
 
 
     internal virtual Database? get_database() {
@@ -53,11 +52,6 @@ public abstract class Geary.Db.Context : BaseObject, Logging.Source {
         return null;
     }
 
-    /** {@inheritDoc} */
-    public void set_logging_parent(Logging.Source parent) {
-        this._logging_parent = parent;
-    }
-
     /** {@inheritDoc} */
     public abstract Logging.State to_logging_state();
 
diff --git a/src/engine/db/db-database-connection.vala b/src/engine/db/db-database-connection.vala
index d58911e4..54d36160 100644
--- a/src/engine/db/db-database-connection.vala
+++ b/src/engine/db/db-database-connection.vala
@@ -66,6 +66,11 @@ public class Geary.Db.DatabaseConnection : Context, Connection {
     public Database database { get { return this._database; } }
     private weak Database _database;
 
+    /** {@inheritDoc} */
+    public override Logging.Source? logging_parent {
+        get { return this._database; }
+    }
+
     /** {@inheritDoc} */
     internal Sqlite.Database db { get { return this._db; } }
     private Sqlite.Database _db;
@@ -119,7 +124,6 @@ public class Geary.Db.DatabaseConnection : Context, Connection {
     /** {@inheritDoc} */
     public Statement prepare(string sql) throws DatabaseError {
         var prepared = new Statement(this, sql);
-        prepared.set_logging_parent(this);
         return prepared;
     }
 
diff --git a/src/engine/db/db-database.vala b/src/engine/db/db-database.vala
index a807e7ba..df5bed21 100644
--- a/src/engine/db/db-database.vala
+++ b/src/engine/db/db-database.vala
@@ -57,6 +57,10 @@ public class Geary.Db.Database : Context {
         }
     }
 
+    /** {@inheritDoc} */
+    public override Logging.Source? logging_parent { get { return _logging_parent; } }
+    private weak Logging.Source? _logging_parent = null;
+
     private DatabaseConnection? primary = null;
     private int outstanding_async_jobs = 0;
     private ThreadPool<TransactionAsyncJob>? thread_pool = null;
@@ -143,7 +147,6 @@ public class Geary.Db.Database : Context {
             var cx = new DatabaseConnection(
                 this, Sqlite.OPEN_READWRITE, cancellable
             );
-            cx.set_logging_parent(this);
 
             try {
                 // drop existing test table (in case created in prior failed open)
@@ -233,7 +236,6 @@ public class Geary.Db.Database : Context {
         DatabaseConnection cx = new DatabaseConnection(
             this, sqlite_flags, cancellable
         );
-        cx.set_logging_parent(this);
         prepare_connection(cx);
         return cx;
     }
@@ -357,6 +359,10 @@ public class Geary.Db.Database : Context {
         return yield job.wait_for_completion_async();
     }
 
+    /** Sets the logging parent context object for this database. */
+    public void set_logging_parent(Logging.Source parent) {
+        this._logging_parent = parent;
+    }
 
     /** {@inheritDoc} */
     public override Logging.State to_logging_state() {
diff --git a/src/engine/db/db-result.vala b/src/engine/db/db-result.vala
index b5382179..8c40c475 100644
--- a/src/engine/db/db-result.vala
+++ b/src/engine/db/db-result.vala
@@ -10,12 +10,14 @@ public class Geary.Db.Result : Geary.Db.Context {
 
     public Statement statement { get; private set; }
 
+    /** {@inheritDoc} */
+    public override Logging.Source? logging_parent {
+        get { return this.statement; }
+    }
 
     // This results in an automatic first next().
     internal Result(Statement statement, Cancellable? cancellable) throws Error {
         this.statement = statement;
-        set_logging_parent(statement);
-
         statement.was_reset.connect(on_query_finished);
         statement.bindings_cleared.connect(on_query_finished);
 
diff --git a/src/engine/db/db-statement.vala b/src/engine/db/db-statement.vala
index 4d792b42..072692ff 100644
--- a/src/engine/db/db-statement.vala
+++ b/src/engine/db/db-statement.vala
@@ -12,6 +12,11 @@ public class Geary.Db.Statement : Context {
 
     public string sql { get; private set; }
 
+    /** {@inheritDoc} */
+    public override Logging.Source? logging_parent {
+        get { return this.connection; }
+    }
+
     internal DatabaseConnection connection { get; private set; }
 
     internal Sqlite.Statement stmt;
-- 
2.29.2

