[rygel] media-export: Reshuffle some code in MediaCache



commit 54b75094e8829d5ef31b00a8495a24b1ebf92c00
Author: Jens Georg <mail jensge org>
Date:   Sat Apr 23 18:16:35 2011 +0300

    media-export: Reshuffle some code in MediaCache

 .../rygel-media-export-media-cache.vala            |  255 ++++++++++----------
 1 files changed, 125 insertions(+), 130 deletions(-)
---
diff --git a/src/plugins/media-export/rygel-media-export-media-cache.vala b/src/plugins/media-export/rygel-media-export-media-cache.vala
index 65ae0fa..57e0979 100644
--- a/src/plugins/media-export/rygel-media-export-media-cache.vala
+++ b/src/plugins/media-export/rygel-media-export-media-cache.vala
@@ -48,18 +48,38 @@ internal struct Rygel.MediaExport.ExistsCacheEntry {
  *  MediaExportDB is a sqlite3 backed persistent storage of media objects
  */
 public class Rygel.MediaExport.MediaCache : Object {
+    // Private members
     private Database                           db;
     private ObjectFactory                      factory;
     private SQLFactory                         sql;
     private HashMap<string, ExistsCacheEntry?> exists_cache;
 
+    // Private static members
     private static MediaCache instance;
 
+    // Constructors
+    private MediaCache () throws Error {
+        this.sql = new SQLFactory ();
+        this.open_db ("media-export");
+        this.factory = new ObjectFactory ();
+        this.get_exists_cache ();
+    }
+
+    // Public static functions
     public static string get_id (File file) {
         return Checksum.compute_for_string (ChecksumType.MD5,
                                             file.get_uri ());
     }
 
+    public static MediaCache get_default () throws Error {
+        if (instance == null) {
+            instance = new MediaCache ();
+        }
+
+        return instance;
+    }
+
+    // Public functions
     public void remove_by_id (string id) throws DatabaseError {
         GLib.Value[] values = { id };
         this.db.exec (this.sql.make (SQLString.DELETE), values);
@@ -116,18 +136,6 @@ public class Rygel.MediaExport.MediaCache : Object {
         return parent;
     }
 
-    public MediaItem? get_item (string item_id)
-                                throws DatabaseError, MediaCacheError {
-        var object = get_object (item_id);
-        if (object != null && !(object is MediaItem)) {
-            throw new MediaCacheError.INVALID_TYPE
-                                        (_("Object %s is not an item"),
-                                         item_id);
-        }
-
-        return object as MediaItem;
-    }
-
     public MediaContainer? get_container (string container_id)
                                           throws DatabaseError,
                                                  MediaCacheError {
@@ -148,17 +156,6 @@ public class Rygel.MediaExport.MediaCache : Object {
     }
 
 
-    private void get_exists_cache () throws DatabaseError {
-        this.exists_cache = new HashMap<string, ExistsCacheEntry?> ();
-        var cursor = this.exec_cursor (SQLString.EXISTS_CACHE);
-        foreach (var statement in cursor) {
-            var entry = ExistsCacheEntry ();
-            entry.mtime = statement.column_int64 (1);
-            entry.size = statement.column_int64 (0);
-            this.exists_cache.set (statement.column_text (2), entry);
-        }
-    }
-
     public bool exists (File      file,
                         out int64 timestamp,
                         out int64 size) throws DatabaseError {
@@ -203,14 +200,6 @@ public class Rygel.MediaExport.MediaCache : Object {
         return children;
     }
 
-    private uint modify_limit (uint max_count) {
-        if (max_count == 0) {
-            return -1;
-        } else {
-            return max_count;
-        }
-    }
-
     public MediaObjects get_objects_by_search_expression
                                         (SearchExpression? expression,
                                          string            container_id,
@@ -319,19 +308,115 @@ public class Rygel.MediaExport.MediaCache : Object {
         return children;
     }
 
-    public static MediaCache get_default () throws Error {
-        if (instance == null) {
-            instance = new MediaCache ();
+    public void debug_statistics () {
+        try {
+            debug ("Database statistics:");
+            var cursor = this.exec_cursor (SQLString.STATISTICS);
+            foreach (var statement in cursor) {
+                debug ("%s: %d",
+                       statement.column_text (0),
+                       statement.column_int (1));
+            }
+        } catch (Error error) { }
+    }
+
+    public ArrayList<string> get_child_ids (string container_id)
+                                            throws DatabaseError {
+        ArrayList<string> children = new ArrayList<string> (str_equal);
+        GLib.Value[] values = { container_id  };
+
+        var cursor = this.exec_cursor (SQLString.CHILD_IDS, values);
+        foreach (var statement in cursor) {
+            children.add (statement.column_text (0));
         }
 
-        return instance;
+        return children;
     }
 
-    private MediaCache () throws Error {
-        this.sql = new SQLFactory ();
-        this.open_db ("media-export");
-        this.factory = new ObjectFactory ();
-        this.get_exists_cache ();
+    public Gee.List<string> get_meta_data_column_by_filter
+                                        (string          column,
+                                         string          filter,
+                                         GLib.ValueArray args,
+                                         long            offset,
+                                         long            max_count)
+                                         throws Error {
+        GLib.Value v = offset;
+        args.append (v);
+        v = max_count;
+        args.append (v);
+
+        var data = new ArrayList<string> ();
+
+        unowned string sql = this.sql.make (SQLString.GET_META_DATA_COLUMN);
+        var cursor = this.db.exec_cursor (sql.printf (column, filter),
+                                          args.values);
+        foreach (var statement in cursor) {
+            data.add (statement.column_text (0));
+        }
+
+        return data;
+    }
+
+    public Gee.List<string> get_object_attribute_by_search_expression
+                                        (string            attribute,
+                                         SearchExpression? expression,
+                                         long              offset,
+                                         uint              max_count)
+                                         throws Error {
+        var args = new ValueArray (0);
+        var filter = this.translate_search_expression (expression,
+                                                       args,
+                                                       "AND");
+
+        debug ("Parsed filter: %s", filter);
+
+        var column = this.map_operand_to_column (attribute);
+        var max_objects = modify_limit (max_count);
+
+        return this.get_meta_data_column_by_filter (column,
+                                                    filter,
+                                                    args,
+                                                    offset,
+                                                    max_objects);
+    }
+
+    public void flag_object (File file, string flag) throws Error {
+        GLib.Value[] args = { flag, file.get_uri () };
+        this.db.exec ("UPDATE Object SET flags = ? WHERE uri = ?", args);
+    }
+
+    public Gee.List<string> get_flagged_uris (string flag) throws Error {
+        var uris = new ArrayList<string> ();
+        const string query = "SELECT uri FROM object WHERE flags = ?";
+
+        GLib.Value[] args = { flag };
+
+        var cursor = this.db.exec_cursor (query, args);
+        foreach (var statement in cursor) {
+            uris.add (statement.column_text (0));
+        }
+
+        return uris;
+    }
+
+    // Private functions
+    private void get_exists_cache () throws DatabaseError {
+        this.exists_cache = new HashMap<string, ExistsCacheEntry?> ();
+        var cursor = this.exec_cursor (SQLString.EXISTS_CACHE);
+        foreach (var statement in cursor) {
+            var entry = ExistsCacheEntry ();
+            entry.mtime = statement.column_int64 (1);
+            entry.size = statement.column_int64 (0);
+            this.exists_cache.set (statement.column_text (2), entry);
+        }
+    }
+
+    private uint modify_limit (uint max_count) {
+        if (max_count == 0) {
+            return -1;
+        } else {
+            return max_count;
+        }
     }
 
     private void open_db (string name) throws Error {
@@ -385,18 +470,6 @@ public class Rygel.MediaExport.MediaCache : Object {
         }
     }
 
-    public void debug_statistics () {
-        try {
-            debug ("Database statistics:");
-            var cursor = this.exec_cursor (SQLString.STATISTICS);
-            foreach (var statement in cursor) {
-                debug ("%s: %d",
-                       statement.column_text (0),
-                       statement.column_int (1));
-            }
-        } catch (Error error) { }
-    }
-
     private void save_metadata (Rygel.MediaItem item) throws Error {
         // Fill common properties
         GLib.Value[] values = { item.size,
@@ -584,19 +657,6 @@ public class Rygel.MediaExport.MediaCache : Object {
         }
     }
 
-    public ArrayList<string> get_child_ids (string container_id)
-                                            throws DatabaseError {
-        ArrayList<string> children = new ArrayList<string> (str_equal);
-        GLib.Value[] values = { container_id  };
-
-        var cursor = this.exec_cursor (SQLString.CHILD_IDS, values);
-        foreach (var statement in cursor) {
-            children.add (statement.column_text (0));
-        }
-
-        return children;
-    }
-
     private string translate_search_expression
                                         (SearchExpression? expression,
                                          ValueArray        args,
@@ -761,71 +821,6 @@ public class Rygel.MediaExport.MediaCache : Object {
         return operator.to_string ();
     }
 
-    public Gee.List<string> get_meta_data_column_by_filter
-                                        (string          column,
-                                         string          filter,
-                                         GLib.ValueArray args,
-                                         long            offset,
-                                         long            max_count)
-                                         throws Error {
-        GLib.Value v = offset;
-        args.append (v);
-        v = max_count;
-        args.append (v);
-
-        var data = new ArrayList<string> ();
-
-        unowned string sql = this.sql.make (SQLString.GET_META_DATA_COLUMN);
-        var cursor = this.db.exec_cursor (sql.printf (column, filter),
-                                          args.values);
-        foreach (var statement in cursor) {
-            data.add (statement.column_text (0));
-        }
-
-        return data;
-    }
-
-    public Gee.List<string> get_object_attribute_by_search_expression
-                                        (string            attribute,
-                                         SearchExpression? expression,
-                                         long              offset,
-                                         uint              max_count)
-                                         throws Error {
-        var args = new ValueArray (0);
-        var filter = this.translate_search_expression (expression,
-                                                       args,
-                                                       "AND");
-
-        debug ("Parsed filter: %s", filter);
-
-        var column = this.map_operand_to_column (attribute);
-        var max_objects = modify_limit (max_count);
-
-        return this.get_meta_data_column_by_filter (column,
-                                                    filter,
-                                                    args,
-                                                    offset,
-                                                    max_objects);
-    }
-
-    public void flag_object (File file, string flag) throws Error {
-        GLib.Value[] args = { flag, file.get_uri () };
-        this.db.exec ("UPDATE Object SET flags = ? WHERE uri = ?", args);
-    }
-
-    public Gee.List<string> get_flagged_uris (string flag) throws Error {
-        var uris = new ArrayList<string> ();
-        const string query = "SELECT uri FROM object WHERE flags = ?";
-
-        GLib.Value[] args = { flag };
-
-        var cursor = this.db.exec_cursor (query, args);
-        foreach (var statement in cursor) {
-            uris.add (statement.column_text (0));
-        }
-
-        return uris;
-    }
     private DatabaseCursor exec_cursor (SQLString      id,
                                         GLib.Value[]?  values = null)
                                         throws DatabaseError {



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