banshee r2992 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Collection.Database src/Core/Banshee.Services/Banshee.Database src/Core/Hyena/Hyena.Data.Sqlite



Author: scottp
Date: Sat Jan 19 03:47:06 2008
New Revision: 2992
URL: http://svn.gnome.org/viewvc/banshee?rev=2992&view=rev

Log:
* src/Core/Hyena/Hyena.Data.Sqlite/SqliteModelCache.cs: Implimented
  IndexOf() using SQL MAGIC!

* src/Core/Banshee.Services/Banshee.Collection.Database/LibraryAlbumInfo.cs,
* src/Core/Banshee.Services/Banshee.Collection.Database/LibraryTrackInfo.cs,
* src/Core/Banshee.Services/Banshee.Collection.Database/LibraryArtistInfo.cs:
  Removed now superfluous DbIndex

* src/Core/Banshee.Services/Banshee.Collection.Database/TrackListDatabaseModel.cs:
  Rejiggered IndexOf

* src/Core/Banshee.Services/Banshee.Database/BansheeModelProvider.cs:
  Got rid of now superfluous IDatabaseItem type

* src/Core/Banshee.Services/Banshee.Database/BansheeModelCache.cs:
  Rejiggered generic constraints

Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryAlbumInfo.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryArtistInfo.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryTrackInfo.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/TrackListDatabaseModel.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeModelCache.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeModelProvider.cs
   trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/SqliteModelCache.cs

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryAlbumInfo.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryAlbumInfo.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryAlbumInfo.cs	Sat Jan 19 03:47:06 2008
@@ -38,7 +38,7 @@
 
 namespace Banshee.Collection.Database
 {
-    public class LibraryAlbumInfo : AlbumInfo, IDatabaseItem
+    public class LibraryAlbumInfo : AlbumInfo
     {
         private static BansheeModelProvider<LibraryAlbumInfo> provider = new BansheeModelProvider<LibraryAlbumInfo> (
             ServiceManager.DbConnection, "CoreAlbums"
@@ -116,11 +116,5 @@
             get { return base.ArtistName; }
             set { base.ArtistName = value; }
         }
-        
-        private int db_index;
-        public int DbIndex {
-            get { return db_index; }
-            set { db_index = value; }
-        }
     }
 }

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryArtistInfo.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryArtistInfo.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryArtistInfo.cs	Sat Jan 19 03:47:06 2008
@@ -38,7 +38,7 @@
 
 namespace Banshee.Collection.Database
 {
-    public class LibraryArtistInfo : ArtistInfo, IDatabaseItem
+    public class LibraryArtistInfo : ArtistInfo
     {
         private static BansheeModelProvider<LibraryArtistInfo> provider = new BansheeModelProvider<LibraryArtistInfo> (
             ServiceManager.DbConnection, "CoreArtists"
@@ -112,11 +112,5 @@
             get { return base.Name; }
             set { base.Name = value; }
         }
-        
-        private int db_index;
-        public int DbIndex {
-            get { return db_index; }
-            set { db_index = value; }
-        }
     }
 }

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryTrackInfo.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryTrackInfo.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryTrackInfo.cs	Sat Jan 19 03:47:06 2008
@@ -37,7 +37,7 @@
 
 namespace Banshee.Collection.Database
 {
-    public class LibraryTrackInfo : TrackInfo, IDatabaseItem
+    public class LibraryTrackInfo : TrackInfo
     {
         private static BansheeModelProvider<LibraryTrackInfo> provider = new BansheeModelProvider<LibraryTrackInfo> (
             ServiceManager.DbConnection, "CoreTracks"
@@ -60,12 +60,6 @@
             Attributes |= TrackAttributes.CanPlay;
         }
 
-        public LibraryTrackInfo (int index) : base ()
-        {
-            Attributes |= TrackAttributes.CanPlay;
-            DbIndex = index;
-        }
-
         public override void Save ()
         {
             if (DbId < 0) {
@@ -80,12 +74,6 @@
             get { return dbid; }
             internal set { dbid = value; }
         }
-        
-        private int db_index;
-        public int DbIndex {
-            get { return db_index; }
-            set { db_index = value; }
-        }
 
         [DatabaseColumn("ArtistID", Index = "CoreTracksArtistIndex")]
         private int artist_id;

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/TrackListDatabaseModel.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/TrackListDatabaseModel.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/TrackListDatabaseModel.cs	Sat Jan 19 03:47:06 2008
@@ -252,11 +252,8 @@
 
         public override int IndexOf (TrackInfo track)
         {
-            if (track is LibraryTrackInfo) {
-                return ((LibraryTrackInfo)track).DbIndex;
-            }
-            
-            return -1;
+            LibraryTrackInfo library_track = track as LibraryTrackInfo;
+            return library_track == null ? -1 : cache.IndexOf (library_track.DbId);
         }
 
         public override TrackInfo this[int index] {

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeModelCache.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeModelCache.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeModelCache.cs	Sat Jan 19 03:47:06 2008
@@ -34,7 +34,7 @@
 
 namespace Banshee.Database
 {
-    public class BansheeModelCache <T> : SqliteModelCache <T> where T : IDatabaseItem, new ()
+    public class BansheeModelCache <T> : SqliteModelCache <T> where T : new ()
     {
         public BansheeModelCache (HyenaSqliteConnection connection,
                                   string uuid,

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeModelProvider.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeModelProvider.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeModelProvider.cs	Sat Jan 19 03:47:06 2008
@@ -34,12 +34,7 @@
 
 namespace Banshee.Database
 {
-    public interface IDatabaseItem
-    {
-        int DbIndex { set; }
-    }
-    
-    public class BansheeModelProvider<T> : SqliteModelProvider<T> where T : IDatabaseItem, new ()
+    public class BansheeModelProvider<T> : SqliteModelProvider<T> where T : new ()
     {
         private BansheeDbConnection connection;
         private string table_name;
@@ -109,9 +104,7 @@
         
         protected override T MakeNewObject (int index)
         {
-            T item = new T ();
-            item.DbIndex = index;
-            return item;
+            return new T ();
         }
     }
 }

Modified: trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/SqliteModelCache.cs
==============================================================================
--- trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/SqliteModelCache.cs	(original)
+++ trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/SqliteModelCache.cs	Sat Jan 19 03:47:06 2008
@@ -38,6 +38,8 @@
         private ICacheableDatabaseModel model;
         private SqliteModelProvider<T> provider;
         private HyenaSqliteCommand select_range_command;
+        private HyenaSqliteCommand select_single_command;
+        private HyenaSqliteCommand select_first_command;
         private HyenaSqliteCommand count_command;
 
         private string reload_sql;
@@ -71,15 +73,32 @@
                         INNER JOIN {2}
                             ON {3} = {2}.ItemID
                         WHERE
-                            {2}.ModelID = ? {5}
-                            {4}
+                            {2}.ModelID = {4} {5}
+                            {6}
                         LIMIT ?, ?",
                     provider.Select, provider.From, CacheTableName,
-                    provider.PrimaryKey, provider.Where,
-                    String.IsNullOrEmpty (provider.Where) ? String.Empty : "AND"
-                ), 3
+                    provider.PrimaryKey, uid,
+                    String.IsNullOrEmpty (provider.Where) ? String.Empty : "AND",
+                    provider.Where
+                ), 2
+            );
+            
+            select_single_command = new HyenaSqliteCommand (
+                String.Format (@"
+                    SELECT OrderID FROM {0}
+                        WHERE
+                            ModelID = {1} AND
+                            ItemID = ?",
+                    CacheTableName, uid
+                ), 1
+            );
+            
+            select_first_command = new HyenaSqliteCommand (
+                String.Format (
+                    "SELECT OrderID FROM {0} WHERE ModelID = {1} LIMIT 1",
+                    CacheTableName, uid
+                )
             );
-
 
             reload_sql = String.Format (@"
                 DELETE FROM {0} WHERE ModelID = {1};
@@ -108,6 +127,20 @@
         protected virtual string CacheTableName {
             get { return "HyenaCache"; }
         }
+        
+        public int IndexOf (int id)
+        {
+            select_single_command.ApplyValues (id);
+            using (IDataReader target_reader = connection.ExecuteReader (select_single_command)) {
+                if (!target_reader.Read ()) {
+                    return -1;
+                }
+                int target = target_reader.GetInt32 (0);
+                using (IDataReader first_reader = connection.ExecuteReader (select_first_command)) {
+                    return first_reader.Read () ? first_reader.GetInt32 (0) - target : -1;
+                }
+            }
+        }
 
         public override int Reload ()
         {
@@ -122,7 +155,7 @@
         protected override void FetchSet (int offset, int limit)
         {
             using (new Timer (String.Format ("Fetching set for {0}", model))) {
-                select_range_command.ApplyValues (uid, offset, limit);
+                select_range_command.ApplyValues (offset, limit);
                 using (IDataReader reader = connection.ExecuteReader (select_range_command)) {
                     while (reader.Read ()) {
                         if (!Contains (offset)) {



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