[geary/mjog/db-result-timing: 6/8] Geary.Db.Context: Remove separate `logging_parent` property




commit 14318775a5133d1771f8f6cb0a5304bad1666eba
Author: Michael Gratton <mike vee net>
Date:   Wed Sep 9 18:33:44 2020 +1000

    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 a59f6c4c0..3894583c5 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 1c5301e7b..0470b9afd 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 a807e7baa..df5bed216 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 300d3afa9..b57dd0f92 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 4d792b42b..072692ffb 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;


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