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



Author: gburt
Date: Tue Jan 15 19:07:17 2008
New Revision: 2972
URL: http://svn.gnome.org/viewvc/banshee?rev=2972&view=rev

Log:
2008-01-15  Gabriel Burt  <gabriel burt gmail com>

	* src/Core/Banshee.Services/Banshee.Database/BansheeDbConnection.cs:
	* src/Core/Hyena/Hyena.Data.Sqlite/CacheableDatabaseModelProvider.cs:
	* src/Core/Hyena/Hyena.Data.Sqlite/DatabaseModelProvider.cs:
	* src/Core/Hyena/Hyena.Data.Sqlite/HyenaDbConnection.cs:
	* src/Core/Hyena/Hyena.Data.Sqlite/HyenaSqliteCommand.cs:
	* src/Core/Hyena/Hyena.Data.Sqlite/HyenaSqliteConnection.cs:
	* src/Core/Hyena/Makefile.am: Rename HyenaDbConnection/Command to
	HyenaSqliteConnection/Command and split HyenaDbCommand into its own file.


Added:
   trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/HyenaSqliteCommand.cs
   trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/HyenaSqliteConnection.cs
      - copied, changed from r2971, /trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/HyenaDbConnection.cs
Removed:
   trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/HyenaDbConnection.cs
Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeDbConnection.cs
   trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/CacheableDatabaseModelProvider.cs
   trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/DatabaseModelProvider.cs
   trunk/banshee/src/Core/Hyena/Makefile.am

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeDbConnection.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeDbConnection.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeDbConnection.cs	Tue Jan 15 19:07:17 2008
@@ -39,7 +39,7 @@
 
 namespace Banshee.Database
 {
-    public sealed class BansheeDbConnection : HyenaDbConnection, IService
+    public sealed class BansheeDbConnection : HyenaSqliteConnection, IService
     {
         public BansheeDbConnection () : this (true)
         {
@@ -156,7 +156,7 @@
         }
     }
     
-    public sealed class BansheeDbCommand : HyenaDbCommand
+    public sealed class BansheeDbCommand : HyenaSqliteCommand
     {
         public BansheeDbCommand(string command)
             : base(command)

Modified: trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/CacheableDatabaseModelProvider.cs
==============================================================================
--- trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/CacheableDatabaseModelProvider.cs	(original)
+++ trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/CacheableDatabaseModelProvider.cs	Tue Jan 15 19:07:17 2008
@@ -104,9 +104,9 @@
         }
         
         private DatabaseCacheableModelProvider cache;
-        private HyenaDbConnection connection;
-        private HyenaDbCommand select_range_command;
-        private HyenaDbCommand count_command;
+        private HyenaSqliteConnection connection;
+        private HyenaSqliteCommand select_range_command;
+        private HyenaSqliteCommand count_command;
         private string reload_sql;
         private int uid;
         private int rows;
@@ -125,7 +125,7 @@
             get { return "HyenaCache"; }
         }
         
-        public CacheableDatabaseModelProvider(HyenaDbConnection connection, ICacheableModel model)
+        public CacheableDatabaseModelProvider(HyenaSqliteConnection connection, ICacheableModel model)
             : base(connection)
         {
             this.connection = connection;
@@ -133,7 +133,7 @@
             
             CheckCacheTable();
             
-            count_command = new HyenaDbCommand(String.Format(
+            count_command = new HyenaSqliteCommand(String.Format(
                 "SELECT COUNT(*) FROM {0} WHERE ModelID = ?", CacheTableName), 1);
             
             if(Persistent) {
@@ -142,7 +142,7 @@
                 uid = DatabaseCacheTable.ModelCount++;
             }
                 
-            select_range_command = new HyenaDbCommand(Where.Length > 0
+            select_range_command = new HyenaSqliteCommand(Where.Length > 0
                 ? String.Format(@"
                                 SELECT {0} FROM {1}
                                     INNER JOIN {2}
@@ -188,7 +188,7 @@
             SelectRangeCommand.ApplyValues(uid, offset, limit);
         }
         
-        protected override HyenaDbCommand SelectRangeCommand {
+        protected override HyenaSqliteCommand SelectRangeCommand {
             get { return select_range_command; }
         }
             
@@ -252,7 +252,7 @@
                     ));
                     if(uid == 0) {
                         //Console.WriteLine ("Didn't find existing cache for {0}, creating", id);
-                        uid = connection.Execute(new HyenaDbCommand(String.Format(
+                        uid = connection.Execute(new HyenaSqliteCommand(String.Format(
                             "INSERT INTO {0} (ModelID) VALUES (?)",
                             CacheModelsTableName),
                             id
@@ -268,7 +268,7 @@
                     connection.Execute(String.Format(
                         "CREATE TABLE {0} (CacheID INTEGER PRIMARY KEY, ModelID TEXT UNIQUE)",
                         CacheModelsTableName));
-                    uid = connection.Execute(new HyenaDbCommand(String.Format(
+                    uid = connection.Execute(new HyenaSqliteCommand(String.Format(
                         "INSERT INTO {0} (ModelID) VALUES (?)",
                         CacheModelsTableName),
                         id

Modified: trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/DatabaseModelProvider.cs
==============================================================================
--- trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/DatabaseModelProvider.cs	(original)
+++ trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/DatabaseModelProvider.cs	Tue Jan 15 19:07:17 2008
@@ -317,14 +317,14 @@
         private readonly List<VirtualColumn> virtual_columns = new List<VirtualColumn>();
         
         private Column key;
-        private HyenaDbConnection connection;
+        private HyenaSqliteConnection connection;
         
-        private HyenaDbCommand create_command;
-        private HyenaDbCommand insert_command;
-        private HyenaDbCommand update_command;
-        private HyenaDbCommand select_command;
-        private HyenaDbCommand select_range_command;
-        private HyenaDbCommand select_single_command;
+        private HyenaSqliteCommand create_command;
+        private HyenaSqliteCommand insert_command;
+        private HyenaSqliteCommand update_command;
+        private HyenaSqliteCommand select_command;
+        private HyenaSqliteCommand select_range_command;
+        private HyenaSqliteCommand select_single_command;
         
         private string primary_key;
         private string select;
@@ -344,11 +344,11 @@
             get { return "HyenaModelVersions"; }
         }
         
-        protected HyenaDbConnection Connection {
+        protected HyenaSqliteConnection Connection {
             get { return connection; }
         }
         
-        protected DatabaseModelProvider(HyenaDbConnection connection)
+        protected DatabaseModelProvider(HyenaSqliteConnection connection)
         {
             foreach(FieldInfo field in typeof(T).GetFields(BindingFlags.Instance | BindingFlags.NonPublic)) {
                 foreach(Attribute attribute in field.GetCustomAttributes(true)) {
@@ -603,7 +603,7 @@
             return default(T);
         }
         
-        protected virtual HyenaDbCommand CreateCommand {
+        protected virtual HyenaSqliteCommand CreateCommand {
             get {
                 if(create_command == null) {
                     StringBuilder builder = new StringBuilder();
@@ -620,13 +620,13 @@
                         builder.Append(column.Schema);
                     }
                     builder.Append(')');
-                    create_command = new HyenaDbCommand(builder.ToString());
+                    create_command = new HyenaSqliteCommand(builder.ToString());
                 }
                 return create_command;
             }
         }
         
-        protected virtual HyenaDbCommand InsertCommand {
+        protected virtual HyenaSqliteCommand InsertCommand {
             get {
                 // FIXME can this string building be done more nicely?
                 if(insert_command == null) {
@@ -646,7 +646,7 @@
                         count++;
                     }
 
-                    insert_command = new HyenaDbCommand(String.Format(
+                    insert_command = new HyenaSqliteCommand(String.Format(
                             "INSERT INTO {0} ({1}) VALUES ({2})",
                             TableName, cols.ToString(), vals.ToString()), count);
                 }
@@ -654,7 +654,7 @@
             }
         }
         
-        protected virtual HyenaDbCommand UpdateCommand {
+        protected virtual HyenaSqliteCommand UpdateCommand {
             get {
                 if(update_command == null) {
                     StringBuilder builder = new StringBuilder();
@@ -677,16 +677,16 @@
                     builder.Append(key.Name);
                     builder.Append(" = ?");
                     count++;
-                    update_command = new HyenaDbCommand(builder.ToString(), count);
+                    update_command = new HyenaSqliteCommand(builder.ToString(), count);
                 }
                 return update_command;
             }
         }
         
-        protected virtual HyenaDbCommand SelectCommand {
+        protected virtual HyenaSqliteCommand SelectCommand {
             get {
                 if(select_command == null) {
-                    select_command = new HyenaDbCommand(Where.Length > 0
+                    select_command = new HyenaSqliteCommand(Where.Length > 0
                         ? String.Format("SELECT {0} FROM {1} WHERE {2}", Select, From, Where)
                         : String.Format("SELECT {0} FROM {1}", Select, From));
                 }
@@ -694,10 +694,10 @@
             }
         }
         
-        protected virtual HyenaDbCommand SelectRangeCommand {
+        protected virtual HyenaSqliteCommand SelectRangeCommand {
             get {
                 if(select_range_command == null) {
-                    select_range_command = new HyenaDbCommand(Where.Length > 0
+                    select_range_command = new HyenaSqliteCommand(Where.Length > 0
                         ? String.Format("SELECT {0} FROM {1} WHERE {2} LIMIT ?, ?", Select, From, Where)
                         : String.Format("SELECT {0} FROM {1} LIMIT ?, ?", Select, From), 2);
                 }
@@ -705,10 +705,10 @@
             }
         }
         
-        protected virtual HyenaDbCommand SelectSingleCommand {
+        protected virtual HyenaSqliteCommand SelectSingleCommand {
             get {
                 if(select_single_command == null) {
-                    select_single_command = new HyenaDbCommand(Where.Length > 0
+                    select_single_command = new HyenaSqliteCommand(Where.Length > 0
                         ? String.Format("SELECT {0} FROM {1} WHERE {2} AND {3} = ?", Select, From, Where, PrimaryKey)
                         : String.Format("SELECT {0} FROM {1} WHERE {2} = ?", Select, From, PrimaryKey), 1);
                 }

Added: trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/HyenaSqliteCommand.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/HyenaSqliteCommand.cs	Tue Jan 15 19:07:17 2008
@@ -0,0 +1,138 @@
+//
+// HyenaSqliteCommand.cs
+//
+// Author:
+//   Aaron Bockover <abockover novell com>
+//   Gabriel Burt <gburt novell com>
+//
+// Copyright (C) 2007 Novell, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.IO;
+using System.Data;
+using Mono.Data.Sqlite;
+
+namespace Hyena.Data.Sqlite
+{
+    public class HyenaSqliteCommand
+    {
+        private SqliteCommand command;
+
+#region Properties
+
+        public SqliteCommand Command {
+            get { return command; }
+        }
+
+        public SqliteParameterCollection Parameters {
+            get { return command.Parameters; }
+        }
+
+        public string CommandText {
+            get { return command.CommandText; }
+        }
+
+#endregion
+
+        public HyenaSqliteCommand(string command)
+        {
+            this.command = new SqliteCommand (command);
+        }
+
+        public HyenaSqliteCommand (string command, int num_params) : this (command)
+        {
+            for (int i = 0; i < num_params; i++) {
+                Parameters.Add (new SqliteParameter ());
+            }
+        }
+
+        public HyenaSqliteCommand (string command, params object [] param_values) : this (command, param_values.Length)
+        {
+            ApplyValues (param_values);
+        }
+
+        public HyenaSqliteCommand ApplyValues (params object [] param_values)
+        {
+            if (param_values.Length != Parameters.Count) {
+                throw new ArgumentException (String.Format (
+                    "Command has {0} parameters, but {1} values given.", Parameters.Count, param_values.Length
+                ));
+            }
+
+            for (int i = 0; i < param_values.Length; i++) {
+                Parameters[i].Value = param_values[i];
+            }
+
+            return this;
+        }
+        
+        public void AddNamedParameter (string name, object value)
+        {
+            SqliteParameter param = new SqliteParameter (name, DbType.String);
+            param.Value = value;
+            Parameters.Add (param);
+        }
+                
+        /*public DbCommand(string command, params object [] parameters) : this(command)
+        {
+            for(int i = 0; i < parameters.Length;) {
+                SqliteParameter param;
+                
+                if(parameters[i] is SqliteParameter) {
+                    param = (SqliteParameter)parameters[i];
+                    if(i < parameters.Length - 1 && !(parameters[i + 1] is SqliteParameter)) {
+                        param.Value = parameters[i + 1];
+                        i += 2;
+                    } else {
+                        i++;
+                    }
+                } else {
+                    param = new SqliteParameter();
+                    param.ParameterName = (string)parameters[i];
+                    param.Value = parameters[i + 1];
+                    i += 2;
+                }
+                
+                Parameters.Add(param);
+            }
+        }
+        
+        public void AddParameter (object value)
+        {
+            SqliteParameter param = new SqliteParameter ();
+            param.Value = value;
+            Parameters.Add (param);
+        }
+        
+        public void AddParameter<T>(string name, T value)
+        {
+            AddParameter<T>(new DbParameter<T>(name), value);
+        }
+        
+        public void AddParameter<T>(DbParameter<T> param, T value)
+        {
+            param.Value = value;
+            Parameters.Add(param);
+        }*/
+    }
+}

Copied: trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/HyenaSqliteConnection.cs (from r2971, /trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/HyenaDbConnection.cs)
==============================================================================
--- /trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/HyenaDbConnection.cs	(original)
+++ trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/HyenaSqliteConnection.cs	Tue Jan 15 19:07:17 2008
@@ -1,5 +1,5 @@
 //
-// BansheeDbConnection.cs
+// HyenaSqliteConnection.cs
 //
 // Author:
 //   Aaron Bockover <abockover novell com>
@@ -33,15 +33,15 @@
 
 namespace Hyena.Data.Sqlite
 {
-    public abstract class HyenaDbConnection : IDisposable
+    public abstract class HyenaSqliteConnection : IDisposable
     {
         private SqliteConnection connection;
 
-        public HyenaDbConnection() : this(true)
+        public HyenaSqliteConnection() : this(true)
         {
         }
 
-        public HyenaDbConnection(bool connect)
+        public HyenaSqliteConnection(bool connect)
         {
             if (connect) {
                 Open ();
@@ -90,7 +90,7 @@
             return command.ExecuteReader ();
         }
 
-        public IDataReader ExecuteReader (HyenaDbCommand command)
+        public IDataReader ExecuteReader (HyenaSqliteCommand command)
         {
             return ExecuteReader (command.Command);
         }
@@ -107,7 +107,7 @@
             return command.ExecuteScalar ();
         }
 
-        public object ExecuteScalar (HyenaDbCommand command)
+        public object ExecuteScalar (HyenaSqliteCommand command)
         {
             return ExecuteScalar (command.Command);
         }
@@ -130,7 +130,7 @@
             return command.LastInsertRowID ();
         }
 
-        public int Execute (HyenaDbCommand command)
+        public int Execute (HyenaSqliteCommand command)
         {
             return Execute (command.Command);
         }
@@ -148,106 +148,4 @@
             get { return connection; }
         }
     }
-    
-    public class HyenaDbCommand
-    {
-        private SqliteCommand command;
-
-#region Properties
-
-        public SqliteCommand Command {
-            get { return command; }
-        }
-
-        public SqliteParameterCollection Parameters {
-            get { return command.Parameters; }
-        }
-
-        public string CommandText {
-            get { return command.CommandText; }
-        }
-
-#endregion
-
-        public HyenaDbCommand(string command)
-        {
-            this.command = new SqliteCommand (command);
-        }
-
-        public HyenaDbCommand (string command, int num_params) : this (command)
-        {
-            for (int i = 0; i < num_params; i++) {
-                Parameters.Add (new SqliteParameter ());
-            }
-        }
-
-        public HyenaDbCommand (string command, params object [] param_values) : this (command, param_values.Length)
-        {
-            ApplyValues (param_values);
-        }
-
-        public HyenaDbCommand ApplyValues (params object [] param_values)
-        {
-            if (param_values.Length != Parameters.Count) {
-                throw new ArgumentException (String.Format (
-                    "Command has {0} parameters, but {1} values given.", Parameters.Count, param_values.Length
-                ));
-            }
-
-            for (int i = 0; i < param_values.Length; i++) {
-                Parameters[i].Value = param_values[i];
-            }
-
-            return this;
-        }
-        
-        public void AddNamedParameter (string name, object value)
-        {
-            SqliteParameter param = new SqliteParameter (name, DbType.String);
-            param.Value = value;
-            Parameters.Add (param);
-        }
-                
-        /*public DbCommand(string command, params object [] parameters) : this(command)
-        {
-            for(int i = 0; i < parameters.Length;) {
-                SqliteParameter param;
-                
-                if(parameters[i] is SqliteParameter) {
-                    param = (SqliteParameter)parameters[i];
-                    if(i < parameters.Length - 1 && !(parameters[i + 1] is SqliteParameter)) {
-                        param.Value = parameters[i + 1];
-                        i += 2;
-                    } else {
-                        i++;
-                    }
-                } else {
-                    param = new SqliteParameter();
-                    param.ParameterName = (string)parameters[i];
-                    param.Value = parameters[i + 1];
-                    i += 2;
-                }
-                
-                Parameters.Add(param);
-            }
-        }
-        
-        public void AddParameter (object value)
-        {
-            SqliteParameter param = new SqliteParameter ();
-            param.Value = value;
-            Parameters.Add (param);
-        }
-        
-        public void AddParameter<T>(string name, T value)
-        {
-            AddParameter<T>(new DbParameter<T>(name), value);
-        }
-        
-        public void AddParameter<T>(DbParameter<T> param, T value)
-        {
-            param.Value = value;
-            Parameters.Add(param);
-        }*/
-    }
 }

Modified: trunk/banshee/src/Core/Hyena/Makefile.am
==============================================================================
--- trunk/banshee/src/Core/Hyena/Makefile.am	(original)
+++ trunk/banshee/src/Core/Hyena/Makefile.am	Tue Jan 15 19:07:17 2008
@@ -22,7 +22,8 @@
 	Hyena.Data.Query/XmlQueryParser.cs \
 	Hyena.Data.Sqlite/CacheableDatabaseModelProvider.cs \
 	Hyena.Data.Sqlite/DatabaseModelProvider.cs \
-	Hyena.Data.Sqlite/HyenaDbConnection.cs \
+	Hyena.Data.Sqlite/HyenaSqliteCommand.cs \
+	Hyena.Data.Sqlite/HyenaSqliteConnection.cs \
 	Hyena.Data/CacheableModelAdapter.cs \
 	Hyena.Data/ColumnDescription.cs \
 	Hyena.Data/ICacheableModel.cs \



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