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



Author: scottp
Date: Fri Jan 18 05:41:46 2008
New Revision: 2984
URL: http://svn.gnome.org/viewvc/banshee?rev=2984&view=rev

Log:
* src/Core/Hyena/Hyena.Data.Sqlite/ModelProvider.cs: Renamed from
  DatabaseModel for consistancy and rejiggered
* src/Core/Hyena/Hyena.Data.Sqlite/DatabaseAttributes.cs: Added
  DatabaseTableAttribute
* src/Core/Hyena/Hyena.Data.Sqlite/ModelCache.cs: Renamed from
  DatabaseModelCache for consistancy and rijiggered
* src/Core/Hyena/Hyena.Data.Sqlite/DatabaseModel.cs: Renamed
  ModelProvider.cs
* src/Core/Hyena/Hyena.Data.Sqlite/DatabaseColumnAttribute.cs: Renamed
  to DatabaseAttributes.cs
* src/Core/Hyena/Hyena.Data.Sqlite/ICacheableDatabaseModel.cs: Removed
  subsumed and obsolete members
* src/Core/Hyena/Hyena.Data.Sqlite/DatabaseModelCache.cs: Renamed
  ModelCache.cs
* 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:
  Made to use new DatabaseTable attribute
* src/Core/Banshee.Services/Banshee.Collection.Database/AlbumListDatabaseModel.cs,
  src/Core/Banshee.Services/Banshee.Collection.Database/TrackListDatabaseModel.cs,
  src/Core/Banshee.Services/Banshee.Collection.Database/ArtistListDatabaseModel.cs:
  Removal of subsumed and obsolete members
* src/Core/Banshee.Services/Banshee.Database/BansheeDatabaseModel.cs:
  Renamed to BansheeModelProvider.cs
* src/Core/Banshee.Services/Banshee.Database/BansheeDatabaseModelCache.cs:
  Renamed to BansheeModelCache.cs
* src/Core/Banshee.Services/Banshee.Database/BansheeModelProvider.cs:
  Whitespace fixes and TableName/ModelVersion removal
* src/Core/Banshee.Services/Banshee.Database/BansheeModelCache.cs:
  Generics changes

Added:
   trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeModelCache.cs
      - copied, changed from r2983, /trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeDatabaseModelCache.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeModelProvider.cs
      - copied, changed from r2983, /trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeDatabaseModel.cs
   trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/DatabaseAttributes.cs
      - copied, changed from r2983, /trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/DatabaseColumnAttribute.cs
   trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/ModelCache.cs
      - copied, changed from r2983, /trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/DatabaseModelCache.cs
   trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/ModelProvider.cs
      - copied, changed from r2983, /trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/DatabaseModel.cs
Removed:
   trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeDatabaseModel.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeDatabaseModelCache.cs
   trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/DatabaseColumnAttribute.cs
   trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/DatabaseModel.cs
   trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/DatabaseModelCache.cs
Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/AlbumListDatabaseModel.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/ArtistListDatabaseModel.cs
   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.Services.mdp
   trunk/banshee/src/Core/Banshee.Services/Makefile.am
   trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/ICacheableDatabaseModel.cs
   trunk/banshee/src/Core/Hyena/Hyena.mdp
   trunk/banshee/src/Core/Hyena/Makefile.am

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/AlbumListDatabaseModel.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/AlbumListDatabaseModel.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/AlbumListDatabaseModel.cs	Fri Jan 18 05:41:46 2008
@@ -32,18 +32,17 @@
 using System.Text;
 using System.Collections.Generic;
 
-using Hyena.Data;
 using Hyena.Data.Sqlite;
 
 using Banshee.Database;
 
 namespace Banshee.Collection.Database
 {
-    public class AlbumListDatabaseModel : AlbumListModel, ICacheableDatabaseModel<LibraryAlbumInfo>
+    public class AlbumListDatabaseModel : AlbumListModel, ICacheableDatabaseModel
     {
         private BansheeDbConnection connection;
         private BansheeModelProvider<LibraryAlbumInfo> provider;
-        private BansheeDatabaseModelCache<LibraryAlbumInfo> cache;
+        private BansheeModelCache<LibraryAlbumInfo> cache;
         private int count;
         private string artist_id_filter_query;
         private string reload_fragment;
@@ -55,7 +54,7 @@
         public AlbumListDatabaseModel(BansheeDbConnection connection, string uuid)
         {
             provider = LibraryAlbumInfo.Provider;
-            cache = new BansheeDatabaseModelCache <LibraryAlbumInfo> (connection, uuid, this);
+            cache = new BansheeModelCache <LibraryAlbumInfo> (connection, uuid, this, provider);
             this.connection = connection;
         }
 
@@ -129,38 +128,10 @@
             get { return 20; }
         }
 
-        // Implement IDatabaseModel
-        public LibraryAlbumInfo Load (IDataReader reader, int index)
-        {
-            return provider.Load (reader, index);
-        }
-
-        public BansheeModelProvider<LibraryAlbumInfo> Provider {
-            get { return provider; }
-        }
-
         //private const string primary_key = "CoreAlbums.AlbumID";
-        public string PrimaryKey {
-            //get { return primary_key; }
-            get { return provider.PrimaryKey; }
-        }
 
         public string ReloadFragment {
             get { return reload_fragment; }
         }
-
-        public string Select {
-            //get { return "CoreAlbums.AlbumID, CoreAlbums.Title, CoreArtists.Name"; }
-            get { return provider.Select; }
-        }
-
-        public string From {
-            get { return provider.From; }
-        }
-
-        public string Where {
-            get { return provider.Where; }
-            //get { return "CoreArtists.ArtistID = CoreAlbums.ArtistID"; }
-        }
     }
 }

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/ArtistListDatabaseModel.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/ArtistListDatabaseModel.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/ArtistListDatabaseModel.cs	Fri Jan 18 05:41:46 2008
@@ -31,18 +31,17 @@
 using System.Data;
 using System.Collections.Generic;
 
-using Hyena.Data;
 using Hyena.Data.Sqlite;
 
 using Banshee.Database;
 
 namespace Banshee.Collection.Database
 {
-    public class ArtistListDatabaseModel : ArtistListModel, ICacheableDatabaseModel<LibraryArtistInfo>
+    public class ArtistListDatabaseModel : ArtistListModel, ICacheableDatabaseModel
     {
         private BansheeDbConnection connection;
         private BansheeModelProvider<LibraryArtistInfo> provider;
-        private BansheeDatabaseModelCache<LibraryArtistInfo> cache;
+        private BansheeModelCache<LibraryArtistInfo> cache;
         private TrackListDatabaseModel track_model;
         private string reload_fragment;
         private int count;
@@ -53,7 +52,7 @@
         {
             this.connection = connection;
             provider = LibraryArtistInfo.Provider;
-            cache = new BansheeDatabaseModelCache <LibraryArtistInfo> (connection, uuid, this);
+            cache = new BansheeModelCache <LibraryArtistInfo> (connection, uuid, this, provider);
         }
 
         public ArtistListDatabaseModel(TrackListDatabaseModel trackModel, BansheeDbConnection connection, string uuid) : this (connection, uuid)
@@ -102,36 +101,9 @@
         public int FetchCount {
             get { return 20; }
         }
-
-        // Implement IDatabaseModel
-        public LibraryArtistInfo Load (IDataReader reader, int index)
-        {
-            return provider.Load (reader, index);
-        }
-
-        public BansheeModelProvider<LibraryArtistInfo> Provider {
-            get { return provider; }
-        }
-
-        public string PrimaryKey {
-            get { return provider.PrimaryKey; }
-        }
-
+        
         public string ReloadFragment {
             get { return reload_fragment; }
         }
-
-        public string Select {
-            get { return provider.Select; }
-        }
-
-        public string From {
-            get { return provider.From; }
-        }
-
-        public string Where {
-            //get { return String.Format ("1=1"); }
-            get { return provider.Where; }
-        }
     }
 }

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	Fri Jan 18 05:41:46 2008
@@ -31,7 +31,6 @@
 
 using Mono.Unix;
 
-using Hyena.Data;
 using Hyena.Data.Sqlite;
 
 using Banshee.Database;
@@ -39,10 +38,11 @@
 
 namespace Banshee.Collection.Database
 {    
+    [DatabaseTable("CoreAlbums", 1)]
     public class LibraryAlbumInfo : AlbumInfo, IDatabaseItem
     {
         private static BansheeModelProvider<LibraryAlbumInfo> provider = new BansheeModelProvider<LibraryAlbumInfo> (
-            "CoreAlbums", ServiceManager.DbConnection
+            ServiceManager.DbConnection
         );
 
         public static BansheeModelProvider<LibraryAlbumInfo> Provider {

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	Fri Jan 18 05:41:46 2008
@@ -38,10 +38,11 @@
 
 namespace Banshee.Collection.Database
 {    
+    [DatabaseTable("CoreArtists", 1)]
     public class LibraryArtistInfo : ArtistInfo, IDatabaseItem
     {
         private static BansheeModelProvider<LibraryArtistInfo> provider = new BansheeModelProvider<LibraryArtistInfo> (
-            "CoreArtists", ServiceManager.DbConnection
+            ServiceManager.DbConnection
         );
 
         public static BansheeModelProvider<LibraryArtistInfo> Provider {

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	Fri Jan 18 05:41:46 2008
@@ -29,7 +29,6 @@
 using System;
 using System.Data;
 
-using Hyena.Data;
 using Hyena.Data.Sqlite;
 
 using Banshee.Base;
@@ -38,10 +37,11 @@
 
 namespace Banshee.Collection.Database
 {
+    [DatabaseTable("CoreTracks", 1)]
     public class LibraryTrackInfo : TrackInfo, IDatabaseItem
     {
         private static BansheeModelProvider<LibraryTrackInfo> provider = new BansheeModelProvider<LibraryTrackInfo> (
-            "CoreTracks", ServiceManager.DbConnection
+            ServiceManager.DbConnection
         );
 
         public static BansheeModelProvider<LibraryTrackInfo> Provider {

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	Fri Jan 18 05:41:46 2008
@@ -43,11 +43,11 @@
 namespace Banshee.Collection.Database
 {
     public class TrackListDatabaseModel : TrackListModel, IExportableModel, 
-        ICacheableDatabaseModel<LibraryTrackInfo>, IFilterable, ISortable, ICareAboutView
+        ICacheableDatabaseModel, IFilterable, ISortable, ICareAboutView
     {
         private BansheeDbConnection connection;
         private BansheeModelProvider<LibraryTrackInfo> provider;
-        private BansheeDatabaseModelCache<LibraryTrackInfo> cache;
+        private BansheeModelCache<LibraryTrackInfo> cache;
         private int count;
         private int unfiltered_count;
         
@@ -68,7 +68,7 @@
         {
             this.connection = connection;
             provider = LibraryTrackInfo.Provider;
-            cache = new BansheeDatabaseModelCache <LibraryTrackInfo> (connection, uuid, this);
+            cache = new BansheeModelCache <LibraryTrackInfo> (connection, uuid, this, provider);
             Refilter ();
         }
         
@@ -207,7 +207,7 @@
         {
             string unfiltered_query = String.Format (
                 "FROM {0}{1} WHERE {2} {3}",
-                From, JoinFragment, Where, ConditionFragment
+                provider.From, JoinFragment, provider.Where, ConditionFragment
             );
 
             unfiltered_count = connection.QueryInt32 (String.Format (
@@ -372,41 +372,16 @@
             return this[index].GenerateExportable();
         }
 
-        public BansheeModelProvider<LibraryTrackInfo> Provider {
-            get { return provider; }
-        }
-
         // Implement ICacheableModel
         public int FetchCount {
             get { return RowsInView > 0 ? RowsInView * 5 : 100; }
         }
 
         // Implement IDatabaseModel
-        public LibraryTrackInfo Load (IDataReader reader, int index)
-        {
-            return provider.Load (reader, index);
-        }
-        
-        public string PrimaryKey {
-            get { return provider.PrimaryKey; }
-        }
-
         public string ReloadFragment {
             get { return reload_fragment; }
         }
 
-        public string Select {
-            get { return provider.Select; }
-        }
-
-        public string From {
-            get { return provider.From; }
-        }
-
-        public string Where {
-            get { return provider.Where; }
-        }
-
         public static QueryFieldSet FieldSet {
             get { return field_set; }
         }

Copied: trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeModelCache.cs (from r2983, /trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeDatabaseModelCache.cs)
==============================================================================
--- /trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeDatabaseModelCache.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeModelCache.cs	Fri Jan 18 05:41:46 2008
@@ -30,14 +30,17 @@
 using System;
 using System.Data;
 
-using Hyena.Data;
 using Hyena.Data.Sqlite;
 
 namespace Banshee.Database
 {
-    public class BansheeDatabaseModelCache<T> : DatabaseModelCache<T>
+    public class BansheeModelCache<T> : ModelCache<T> where T : IDatabaseItem, new ()
     {
-        public BansheeDatabaseModelCache (HyenaSqliteConnection connection, string uuid, ICacheableDatabaseModel<T> model) : base (connection, uuid, model)
+        public BansheeModelCache (HyenaSqliteConnection connection,
+                                  string uuid,
+                                  ICacheableDatabaseModel model,
+                                  BansheeModelProvider<T> provider)
+            : base (connection, uuid, model, provider)
         {
         }
         

Copied: trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeModelProvider.cs (from r2983, /trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeDatabaseModel.cs)
==============================================================================
--- /trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeDatabaseModel.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeModelProvider.cs	Fri Jan 18 05:41:46 2008
@@ -30,7 +30,6 @@
 using System.Collections.Generic;
 using System.Data;
 
-using Hyena.Data;
 using Hyena.Data.Sqlite;
 
 namespace Banshee.Database
@@ -40,73 +39,61 @@
         int DbIndex { set; }
     }
     
-    public class BansheeModelProvider<T> : DatabaseModel<T> where T : IDatabaseItem, new ()
+    public class BansheeModelProvider<T> : ModelProvider<T> where T : IDatabaseItem, new ()
     {
-        protected string table_name;
+        private BansheeDbConnection connection;
 
-        protected override string TableName {
-            get { return table_name; }
-        }
-        
-        /*protected BansheeModelProvider (BansheeDbConnection connection) : base(connection)
-        {
-        }*/
-
-        public BansheeModelProvider(string table_name, BansheeDbConnection connection) : base(connection)
+        public BansheeModelProvider (BansheeDbConnection connection)
+            : base (connection)
         {
-            Console.WriteLine ("Creating banshee model provider, table name = {0}", table_name);
-            this.table_name = table_name;
+            this.connection = connection;
             Init ();
         }
         
         protected override sealed int DatabaseVersion {
             get { return 1; }
         }
-
-        protected override int ModelVersion {
-            get { return 1; }
-        }
         
-        protected override sealed void CheckVersion()
+        protected override sealed void CheckVersion ()
         {
-            using(IDataReader reader = Connection.ExecuteReader(String.Format(
+            using (IDataReader reader = connection.ExecuteReader (String.Format (
                 "SELECT Value FROM CoreConfiguration WHERE Key = '{0}ModelVersion'", TableName))) {
-                if(reader.Read()) {
-                    int version = Int32.Parse(reader.GetString(0));
-                    if(version < ModelVersion) {
-                        MigrateTable(version);
-                        Connection.Execute(String.Format(
+                if (reader.Read ()) {
+                    int version = Int32.Parse (reader.GetString (0));
+                    if (version < ModelVersion) {
+                        MigrateTable (version);
+                        connection.Execute (String.Format (
                             "UPDATE CoreConfiguration SET Value = '{0}' WHERE Key = '{0}ModelVersion'",
                             ModelVersion, TableName));
                     }
                 } else {
-                    Connection.Execute(String.Format(
+                    connection.Execute (String.Format (
                         "INSERT INTO CoreConfiguration (Key, Value) VALUES ('{0}ModelVersion', '{1}')",
                         TableName, ModelVersion));
                 }
             }
-            using(IDataReader reader = Connection.ExecuteReader("SELECT Value FROM CoreConfiguration WHERE Key = 'DatabaseVersion'")) {
-                if(reader.Read()) {
-                    int version = Int32.Parse(reader.GetString(0));
-                    if(version < DatabaseVersion) {
-                        MigrateDatabase(version);
-                        Connection.Execute(String.Format(
+            using (IDataReader reader = connection.ExecuteReader ("SELECT Value FROM CoreConfiguration WHERE Key = 'DatabaseVersion'")) {
+                if (reader.Read ()) {
+                    int version = Int32.Parse (reader.GetString (0));
+                    if (version < DatabaseVersion) {
+                        MigrateDatabase (version);
+                        connection.Execute (String.Format (
                             "UPDATE CoreConfiguration SET Value = '{0}' WHERE Key = 'DatabaseVersion'",
                             DatabaseVersion));
                     }
                 } else {
-                    Connection.Execute(String.Format(
+                    connection.Execute (String.Format (
                         "INSERT INTO CoreConfiguration (Key, Value) VALUES ('DatabaseVersion', '{0}')",
                         DatabaseVersion));
                 }
             }
         }
 
-        protected override sealed void MigrateDatabase(int old_version)
+        protected override sealed void MigrateDatabase (int old_version)
         {
         }
         
-        protected override void MigrateTable(int old_version)
+        protected override void MigrateTable (int old_version)
         {
         }
         

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Services.mdp
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Services.mdp	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Services.mdp	Fri Jan 18 05:41:46 2008
@@ -77,12 +77,9 @@
     <File name="Banshee.Streaming/RadioTrackInfo.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.Services.addins" subtype="Code" buildaction="EmbedAsResource" />
     <File name="Banshee.Sources/ErrorSource.cs" subtype="Code" buildaction="Compile" />
-    <File name="Banshee.Collection.Database/BansheeCacheableModelAdapter.cs" subtype="Code" buildaction="Compile" />
-    <File name="Banshee.Collection.Database/IDatabaseModel.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.MediaEngine/IPlayerEngineService.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.MediaEngine/IPlaybackController.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.Collection/BansheeListModel.cs" subtype="Code" buildaction="Compile" />
-    <File name="Banshee.Database/TableSchema.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.AudioProfiles/GConfProfileConfiguration.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.AudioProfiles/Pipeline.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.AudioProfiles/PipelineVariable.cs" subtype="Code" buildaction="Compile" />
@@ -110,7 +107,8 @@
     <File name="Banshee.Metadata.Rhapsody/RhapsodyQueryJob.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.Networking/NetworkDetect.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.Networking/NetworkManager.cs" subtype="Code" buildaction="Compile" />
-    <File name="Banshee.Collection.Database/BansheeModelProvider.cs" subtype="Code" buildaction="Compile" />
+    <File name="Banshee.Database/BansheeModelProvider.cs" subtype="Code" buildaction="Compile" />
+    <File name="Banshee.Database/BansheeModelCache.cs" subtype="Code" buildaction="Compile" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

Modified: trunk/banshee/src/Core/Banshee.Services/Makefile.am
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Makefile.am	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Makefile.am	Fri Jan 18 05:41:46 2008
@@ -26,10 +26,10 @@
 	Banshee.Collection/ImportManager.cs \
 	Banshee.Collection/ModelHelper.cs \
 	Banshee.Collection/TrackListModel.cs \
-	Banshee.Database/BansheeDatabaseModel.cs \
-	Banshee.Database/BansheeDatabaseModelCache.cs \
 	Banshee.Database/BansheeDbConnection.cs \
 	Banshee.Database/BansheeDbFormatMigrator.cs \
+	Banshee.Database/BansheeModelCache.cs \
+	Banshee.Database/BansheeModelProvider.cs \
 	Banshee.Library/HomeDirectoryImportSource.cs \
 	Banshee.Library/IImportSource.cs \
 	Banshee.Library/ImportSourceManager.cs \

Copied: trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/DatabaseAttributes.cs (from r2983, /trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/DatabaseColumnAttribute.cs)
==============================================================================
--- /trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/DatabaseColumnAttribute.cs	(original)
+++ trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/DatabaseAttributes.cs	Fri Jan 18 05:41:46 2008
@@ -34,6 +34,19 @@
 
 namespace Hyena.Data.Sqlite
 {
+    [AttributeUsage(AttributeTargets.Class)]
+    public sealed class DatabaseTableAttribute : Attribute
+    {
+        public readonly string Name;
+        public readonly int Version;
+        
+        public DatabaseTableAttribute(string name, int version)
+        {
+            Name = name;
+            Version = version;
+        }
+    }
+    
     [Flags]
     public enum DatabaseColumnConstraints
     {

Modified: trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/ICacheableDatabaseModel.cs
==============================================================================
--- trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/ICacheableDatabaseModel.cs	(original)
+++ trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/ICacheableDatabaseModel.cs	Fri Jan 18 05:41:46 2008
@@ -32,14 +32,8 @@
 
 namespace Hyena.Data.Sqlite
 {
-    public interface ICacheableDatabaseModel<T> : ICacheableModel
+    public interface ICacheableDatabaseModel : ICacheableModel
     {
-        T Load (IDataReader reader, int index);
-
-        string PrimaryKey { get; }
         string ReloadFragment { get; }
-        string Select { get; }
-        string From { get; }
-        string Where { get; }
     }
 }

Copied: trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/ModelCache.cs (from r2983, /trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/DatabaseModelCache.cs)
==============================================================================
--- /trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/DatabaseModelCache.cs	(original)
+++ trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/ModelCache.cs	Fri Jan 18 05:41:46 2008
@@ -32,10 +32,11 @@
 
 namespace Hyena.Data.Sqlite
 {
-    public class DatabaseModelCache<T> : ModelCache<T>
+    public class ModelCache<T> : Hyena.Data.ModelCache<T>
     {
         private HyenaSqliteConnection connection;
-        private ICacheableDatabaseModel<T> db_model;
+        private ICacheableDatabaseModel model;
+        private ModelProvider<T> provider;
         private HyenaSqliteCommand select_range_command;
         private HyenaSqliteCommand count_command;
 
@@ -44,10 +45,16 @@
         private int rows = 0;
         private bool warm = false;
 
-        public DatabaseModelCache (HyenaSqliteConnection connection, string uuid, ICacheableDatabaseModel<T> model) : base (model)
+        public ModelCache (HyenaSqliteConnection connection,
+                           string uuid,
+                           ICacheableDatabaseModel model,
+                           ModelProvider<T> provider)
+            : base (model)
         {
             this.connection = connection;
-            this.db_model = model;
+            this.model = model;
+            this.provider = provider;
+            
             CheckCacheTable ();
 
             count_command = new HyenaSqliteCommand (
@@ -67,9 +74,9 @@
                             {2}.ModelID = ? {5}
                             {4}
                         LIMIT ?, ?",
-                    db_model.Select, db_model.From, CacheTableName,
-                    db_model.PrimaryKey, db_model.Where,
-                    String.IsNullOrEmpty (db_model.Where) ? String.Empty : "AND"
+                    provider.Select, provider.From, CacheTableName,
+                    provider.PrimaryKey, provider.Where,
+                    String.IsNullOrEmpty (provider.Where) ? String.Empty : "AND"
                 ), 3
             );
 
@@ -77,7 +84,7 @@
             reload_sql = String.Format (@"
                 DELETE FROM {0} WHERE ModelID = {1};
                     INSERT INTO {0} SELECT null, {1}, {2} ",
-                CacheTableName, uid, db_model.PrimaryKey
+                CacheTableName, uid, provider.PrimaryKey
             );
         }
 
@@ -105,8 +112,8 @@
         public override int Reload ()
         {
             InvalidateManagedCache ();
-            using (new Timer (String.Format ("Generating cache table for {0}", db_model))) {
-                connection.Execute (reload_sql + db_model.ReloadFragment);
+            using (new Timer (String.Format ("Generating cache table for {0}", model))) {
+                connection.Execute (reload_sql + model.ReloadFragment);
             }
             UpdateCount ();
             return rows;
@@ -114,17 +121,14 @@
 
         protected override void FetchSet (int offset, int limit)
         {
-            using (new Timer (String.Format ("Fetching set for {0}", db_model))) {
+            using (new Timer (String.Format ("Fetching set for {0}", model))) {
                 select_range_command.ApplyValues (uid, offset, limit);
                 using (IDataReader reader = connection.ExecuteReader (select_range_command)) {
-                    int i = offset;
-                    T item;
                     while (reader.Read ()) {
-                        if (!Contains (i)) {
-                            item = db_model.Load (reader, i);
-                            Add (i, item);
+                        if (!Contains (offset)) {
+                            Add (offset, provider.Load (reader, offset));
                         }
-                        i++;
+                        offset++;
                      }
                  }
             }

Copied: trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/ModelProvider.cs (from r2983, /trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/DatabaseModel.cs)
==============================================================================
--- /trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/DatabaseModel.cs	(original)
+++ trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/ModelProvider.cs	Fri Jan 18 05:41:46 2008
@@ -34,7 +34,7 @@
 
 namespace Hyena.Data.Sqlite
 {
-    public abstract class DatabaseModel<T>
+    public abstract class ModelProvider<T>
     {
         private readonly List<DatabaseColumn> columns = new List<DatabaseColumn> ();
         private readonly List<VirtualDatabaseColumn> virtual_columns = new List<VirtualDatabaseColumn> ();
@@ -49,6 +49,9 @@
         private HyenaSqliteCommand select_range_command;
         private HyenaSqliteCommand select_single_command;
         
+        private string table_name;
+        private int model_version;
+        
         private string primary_key;
         private string select;
         private string from;
@@ -56,8 +59,6 @@
         
         private const string HYENA_DATABASE_NAME = "hyena_database_master";
 
-        protected abstract string TableName { get; }
-        protected abstract int ModelVersion { get; }
         protected abstract int DatabaseVersion { get; }
         protected abstract void MigrateTable (int old_version);
         protected abstract void MigrateDatabase (int old_version);
@@ -67,14 +68,29 @@
             get { return "HyenaModelVersions"; }
         }
         
-        protected HyenaSqliteConnection Connection {
-            get { return connection; }
-        }
-        
-        protected DatabaseModel (HyenaSqliteConnection connection)
+        protected ModelProvider (HyenaSqliteConnection connection)
         {
+            foreach (DatabaseTableAttribute attribute in typeof (T).GetCustomAttributes (typeof (DatabaseTableAttribute), true)) {
+                table_name = attribute.Name;
+                model_version = attribute.Version;
+            }
+            
+            if (TableName == null) {
+                throw new Exception (String.Format (
+                    "The type {0} does not have a DatabaseTable attribute",
+                    typeof (T).Name));
+            }
+            
             this.connection = connection;
         }
+        
+        protected string TableName {
+            get { return table_name; }
+        }
+        
+        protected int ModelVersion {
+            get { return model_version; }
+        }
 
         protected void Init ()
         {
@@ -186,9 +202,9 @@
             }
         }
         
-        protected static string GetSchemaSql (string table_name)
+        protected static string GetSchemaSql (string TableName)
         {
-            return String.Format ("SELECT sql FROM sqlite_master WHERE name = '{0}'", table_name);
+            return String.Format ("SELECT sql FROM sqlite_master WHERE name = '{0}'", TableName);
         }
         
         private void AddColumn (MemberInfo member, Attribute attribute)

Modified: trunk/banshee/src/Core/Hyena/Hyena.mdp
==============================================================================
--- trunk/banshee/src/Core/Hyena/Hyena.mdp	(original)
+++ trunk/banshee/src/Core/Hyena/Hyena.mdp	Fri Jan 18 05:41:46 2008
@@ -30,7 +30,6 @@
     <File name="Hyena/IUndoAction.cs" subtype="Code" buildaction="Compile" />
     <File name="Hyena/UndoManager.cs" subtype="Code" buildaction="Compile" />
     <File name="Hyena.Data/ColumnDescription.cs" subtype="Code" buildaction="Compile" />
-    <File name="Hyena.Data/CacheableModelAdapter.cs" subtype="Code" buildaction="Compile" />
     <File name="Hyena.Data/ICacheableModel.cs" subtype="Code" buildaction="Compile" />
     <File name="Hyena.Collections/RangeCollection.cs" subtype="Code" buildaction="Compile" />
     <File name="Hyena.Collections/IStackProvider.cs" subtype="Code" buildaction="Compile" />
@@ -40,9 +39,15 @@
     <File name="Hyena.Data.Query/QueryField.cs" subtype="Code" buildaction="Compile" />
     <File name="Hyena.Data.Query/UserQueryParser.cs" subtype="Code" buildaction="Compile" />
     <File name="Hyena.Data.Query/XmlQueryParser.cs" subtype="Code" buildaction="Compile" />
-    <File name="Hyena.Data/HyenaDbConnection.cs" subtype="Code" buildaction="Compile" />
-    <File name="Hyena.Data/DatabaseModelProvider.cs" subtype="Code" buildaction="Compile" />
-    <File name="Hyena.Data/CacheableDatabaseModelProvider.cs" subtype="Code" buildaction="Compile" />
+    <File name="Hyena.Data.Query/QueryFieldSet.cs" subtype="Code" buildaction="Compile" />
+    <File name="Hyena.Data.Sqlite/DatabaseColumn.cs" subtype="Code" buildaction="Compile" />
+    <File name="Hyena.Data.Sqlite/DatabaseAttributes.cs" subtype="Code" buildaction="Compile" />
+    <File name="Hyena.Data.Sqlite/ModelProvider.cs" subtype="Code" buildaction="Compile" />
+    <File name="Hyena.Data.Sqlite/ModelCache.cs" subtype="Code" buildaction="Compile" />
+    <File name="Hyena.Data.Sqlite/HyenaSqliteCommand.cs" subtype="Code" buildaction="Compile" />
+    <File name="Hyena.Data.Sqlite/HyenaSqliteConnection.cs" subtype="Code" buildaction="Compile" />
+    <File name="Hyena.Data.Sqlite/ICacheableDatabaseModel.cs" subtype="Code" buildaction="Compile" />
+    <File name="Hyena.Data/ModelCache.cs" subtype="Code" buildaction="Compile" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

Modified: trunk/banshee/src/Core/Hyena/Makefile.am
==============================================================================
--- trunk/banshee/src/Core/Hyena/Makefile.am	(original)
+++ trunk/banshee/src/Core/Hyena/Makefile.am	Fri Jan 18 05:41:46 2008
@@ -21,13 +21,13 @@
 	Hyena.Data.Query/QueryToken.cs \
 	Hyena.Data.Query/UserQueryParser.cs \
 	Hyena.Data.Query/XmlQueryParser.cs \
+	Hyena.Data.Sqlite/DatabaseAttributes.cs \
 	Hyena.Data.Sqlite/DatabaseColumn.cs \
-	Hyena.Data.Sqlite/DatabaseColumnAttribute.cs \
-	Hyena.Data.Sqlite/DatabaseModel.cs \
-	Hyena.Data.Sqlite/DatabaseModelCache.cs \
 	Hyena.Data.Sqlite/HyenaSqliteCommand.cs \
 	Hyena.Data.Sqlite/HyenaSqliteConnection.cs \
 	Hyena.Data.Sqlite/ICacheableDatabaseModel.cs \
+	Hyena.Data.Sqlite/ModelCache.cs \
+	Hyena.Data.Sqlite/ModelProvider.cs \
 	Hyena.Data/ColumnDescription.cs \
 	Hyena.Data/ICacheableModel.cs \
 	Hyena.Data/ICareAboutView.cs \



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