[rygel] lms: Let LMS.Database inherit Rygel's Database



commit 469e3ad28f44e0644f73ac951252cddfb04edd37
Author: Jens Georg <mail jensge org>
Date:   Sun Feb 7 14:59:26 2016 +0100

    lms: Let LMS.Database inherit Rygel's Database
    
    Signed-off-by: Jens Georg <mail jensge org>

 src/plugins/lms/rygel-lms-albums.vala         |    1 +
 src/plugins/lms/rygel-lms-all-videos.vala     |    1 +
 src/plugins/lms/rygel-lms-database.vala       |   62 +++++-------------------
 src/plugins/lms/rygel-lms-root-container.vala |    2 +-
 4 files changed, 16 insertions(+), 50 deletions(-)
---
diff --git a/src/plugins/lms/rygel-lms-albums.vala b/src/plugins/lms/rygel-lms-albums.vala
index 89d9323..8b93f28 100644
--- a/src/plugins/lms/rygel-lms-albums.vala
+++ b/src/plugins/lms/rygel-lms-albums.vala
@@ -21,6 +21,7 @@
  */
 
 using Rygel;
+using Rygel.Database;
 using Sqlite;
 
 public class Rygel.LMS.Albums : Rygel.LMS.CategoryContainer {
diff --git a/src/plugins/lms/rygel-lms-all-videos.vala b/src/plugins/lms/rygel-lms-all-videos.vala
index 0cc0731..7f01f85 100644
--- a/src/plugins/lms/rygel-lms-all-videos.vala
+++ b/src/plugins/lms/rygel-lms-all-videos.vala
@@ -21,6 +21,7 @@
  */
 
 using Rygel;
+using Rygel.Database;
 using Sqlite;
 
 public class Rygel.LMS.AllVideos : Rygel.LMS.CategoryContainer {
diff --git a/src/plugins/lms/rygel-lms-database.vala b/src/plugins/lms/rygel-lms-database.vala
index 8749006..82c4b83 100644
--- a/src/plugins/lms/rygel-lms-database.vala
+++ b/src/plugins/lms/rygel-lms-database.vala
@@ -1,8 +1,9 @@
 /*
- * Copyright (C) 2009,2011 Jens Georg <mail jensge org>,
+ * Copyright (C) 2009,2011,2016 Jens Georg <mail jensge org>,
  *           (C) 2013 Intel Corporation.
  *
  * Author: Jussi Kukkonen <jussi kukkonen intel com>
+ *         Jens Georg <mail jensge org>
  *
  * This file is part of Rygel.
  *
@@ -22,26 +23,23 @@
  */
 
 using Rygel;
+using Rygel.Database;
 using Gee;
 using Sqlite;
 
-public errordomain Rygel.LMS.DatabaseError {
-    OPEN,
-    PREPARE,
-    BIND,
-    STEP,
-    NOT_FOUND
-}
-
-public class Rygel.LMS.Database {
+public class Rygel.LMS.Database : Rygel.Database.Database, Initable {
 
     public signal void db_updated(uint64 old_update_id, uint64 new_update_id);
 
-    private Sqlite.Database db;
     private LMS.DBus lms_proxy;
     private uint64 update_id;
 
-    public Database () throws DatabaseError {
+    public Database () throws DatabaseError, Error {
+        Object (name: ":memory:");
+        init ();
+    }
+
+    public bool init (Cancellable? cancellable = null) throws Error {
         string db_path;
         try {
             lms_proxy = Bus.get_proxy_sync (BusType.SESSION,
@@ -60,25 +58,9 @@ public class Rygel.LMS.Database {
             debug  ("Using default sqlite database location %s", db_path);
         }
 
-        Sqlite.Database.open (db_path, out this.db);
-        if (this.db.errcode () != Sqlite.OK) {
-            throw new DatabaseError.OPEN ("Failed to open '%s': %d",
-                                          db_path,
-                                          this.db.errcode () );
-        }
-
-        this.db.create_function ("contains",
-                                 2,
-                                 Sqlite.UTF8,
-                                 null,
-                                 Rygel.Database.Database.utf8_contains,
-                                 null,
-                                 null);
-
-        this.db.create_collation ("CASEFOLD",
-                                  Sqlite.UTF8,
-                                  Rygel.Database.Database.utf8_collate);
+        this.name = db_path;
 
+        return base.init ();
     }
 
     private void on_lms_properties_changed (DBusProxy lms_proxy,
@@ -104,29 +86,11 @@ public class Rygel.LMS.Database {
     }
 
 
-    public Statement prepare (string query_string) throws DatabaseError {
-        Statement statement;
-
-        var err = this.db.prepare_v2 (query_string, -1, out statement);
-        if (err != Sqlite.OK)
-            throw new DatabaseError.PREPARE ("Unable to create statement '%s': %d",
-                                             query_string,
-                                             err);
-        return statement;
-    }
-
-
     public Statement prepare_and_init (string   query,
                                        GLib.Value[]? arguments)
                                         throws DatabaseError {
 
-        Statement statement;
-
-        var err = this.db.prepare_v2 (query, -1, out statement);
-        if (err != Sqlite.OK)
-            throw new DatabaseError.PREPARE ("Unable to create statement '%s': %d",
-                                             query,
-                                             err);
+        var statement = this.prepare (query);
 
         for (var i = 1; i <= arguments.length; ++i) {
             int sqlite_err;
diff --git a/src/plugins/lms/rygel-lms-root-container.vala b/src/plugins/lms/rygel-lms-root-container.vala
index de832a2..0052a85 100644
--- a/src/plugins/lms/rygel-lms-root-container.vala
+++ b/src/plugins/lms/rygel-lms-root-container.vala
@@ -54,7 +54,7 @@ public class Rygel.LMS.RootContainer : Rygel.SimpleContainer {
                                                      _("Pictures"),
                                                      this.lms_db));
 
-        } catch (DatabaseError e) {
+        } catch (Error e) {
             warning ("%s\n", e.message);
 
             /* TODO if db does not exist we should


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