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



Author: scottp
Date: Sun Jan 20 07:01:45 2008
New Revision: 3001
URL: http://svn.gnome.org/viewvc/banshee?rev=3001&view=rev

Log:
* src/Core/Hyena/Hyena.Data.Sqlite/SqliteModelProvider.cs,
  src/Core/Hyena/Hyena.Data.Sqlite/DatabaseColumn.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:
  Consolidated save logic.

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/Hyena/Hyena.Data.Sqlite/DatabaseColumn.cs
   trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/SqliteModelProvider.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	Sun Jan 20 07:01:45 2008
@@ -86,11 +86,7 @@
 
         public void Save ()
         {
-            if (DbId < 0) {
-                DbId = Provider.Insert (this);
-            } else {
-                Provider.Update (this);
-            }
+            Provider.Save (this);
         }
 
         [DatabaseColumn("AlbumID", Constraints = DatabaseColumnConstraints.PrimaryKey)]

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	Sun Jan 20 07:01:45 2008
@@ -88,11 +88,7 @@
 
         public void Save ()
         {
-            if (DbId < 0) {
-                dbid = Provider.Insert (this);
-            } else {
-                Provider.Update (this);
-            }
+            Provider.Save (this);
         }
 
         private void LoadFromReader(IDataReader reader)

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	Sun Jan 20 07:01:45 2008
@@ -62,11 +62,7 @@
 
         public override void Save ()
         {
-            if (DbId < 0) {
-                DbId = Provider.Insert (this);
-            } else {
-                Provider.Update (this);
-            }
+            Provider.Save (this);
         }
         
         [DatabaseColumn("TrackID", Constraints = DatabaseColumnConstraints.PrimaryKey)]

Modified: trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/DatabaseColumn.cs
==============================================================================
--- trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/DatabaseColumn.cs	(original)
+++ trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/DatabaseColumn.cs	Sun Jan 20 07:01:45 2008
@@ -88,10 +88,15 @@
         
         public void SetValue (object target, IDataReader reader, int column)
         {
+            SetValue (target, SetValue (type, reader, column));
+        }
+        
+        public void SetValue (object target, object value)
+        {
             if (field_info != null) {
-                field_info.SetValue (target, SetValue (type, reader, column));
+                field_info.SetValue (target, value);
             } else {
-                property_info.GetSetMethod (true).Invoke (target, new object[] { SetValue (type, reader, column) });
+                property_info.GetSetMethod (true).Invoke (target, new object[] { value });
             }
         }
         

Modified: trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/SqliteModelProvider.cs
==============================================================================
--- trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/SqliteModelProvider.cs	(original)
+++ trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/SqliteModelProvider.cs	Sun Jan 20 07:01:45 2008
@@ -235,6 +235,15 @@
             }
         }
         
+        public void Save (T target)
+        {
+            if (((int)key.GetValue (target)) > 0) {
+                Update (target);
+            } else {
+                key.SetValue (target, Insert (target));
+            }
+        }
+        
         protected virtual void PrepareInsertCommand (T target)
         {
             for (int i = 0; i < columns.Count; i++) {
@@ -242,7 +251,7 @@
             }
         }
         
-        public int Insert (T target)
+        protected int Insert (T target)
         {
             PrepareInsertCommand (target);
             return connection.Execute (InsertCommand);
@@ -256,7 +265,7 @@
             UpdateCommand.Parameters[columns.Count].Value = key.GetValue (target);
         }
         
-        public void Update (T target)
+        protected void Update (T target)
         {
             PrepareUpdateCommand (target);
             connection.Execute (UpdateCommand);



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