banshee r3129 - in trunk/banshee: . src/Core/Banshee.Services src/Core/Banshee.Services/Banshee.Configuration src/Core/Banshee.Services/Banshee.Database src/Core/Banshee.ThickClient
- From: scottp svn gnome org
- To: svn-commits-list gnome org
- Subject: banshee r3129 - in trunk/banshee: . src/Core/Banshee.Services src/Core/Banshee.Services/Banshee.Configuration src/Core/Banshee.Services/Banshee.Database src/Core/Banshee.ThickClient
- Date: Fri, 1 Feb 2008 07:41:46 +0000 (GMT)
Author: scottp
Date: Fri Feb 1 07:41:45 2008
New Revision: 3129
URL: http://svn.gnome.org/viewvc/banshee?rev=3129&view=rev
Log:
* src/Core/Banshee.Services/Banshee.Database/BansheeModelProvider.cs:
Made to use DatabaseConfigurationClient when checking for version.
* src/Core/Banshee.Services/Banshee.Configuration:
* src/Core/Banshee.Services/Banshee.Configuration/DatabaseConfigurationClient.cs:
Added DatabaseConfigurationClient, an IConfigurationClient wrapper
for the CoreConfiguration table.
Added:
trunk/banshee/src/Core/Banshee.Services/Banshee.Configuration/
trunk/banshee/src/Core/Banshee.Services/Banshee.Configuration/DatabaseConfigurationClient.cs
Modified:
trunk/banshee/ChangeLog
trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeModelProvider.cs
trunk/banshee/src/Core/Banshee.Services/Banshee.Services.mdp
trunk/banshee/src/Core/Banshee.Services/Makefile.am
trunk/banshee/src/Core/Banshee.ThickClient/Banshee.ThickClient.mdp
Added: trunk/banshee/src/Core/Banshee.Services/Banshee.Configuration/DatabaseConfigurationClient.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Configuration/DatabaseConfigurationClient.cs Fri Feb 1 07:41:45 2008
@@ -0,0 +1,137 @@
+/***************************************************************************
+ * DatabaseConfigurationClient.cs
+ *
+ * Written by Scott Peterson <lunchtimemama gmail com>
+ ****************************************************************************/
+
+/* THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW:
+ *
+ * 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.Data;
+
+using Hyena.Data.Sqlite;
+
+using Banshee.Database;
+using Banshee.ServiceStack;
+
+namespace Banshee.Configuration
+{
+ public class DatabaseConfigurationClient : IConfigurationClient
+ {
+ private static DatabaseConfigurationClient instance = new DatabaseConfigurationClient (
+ ServiceManager.DbConnection);
+
+ public static DatabaseConfigurationClient Client {
+ get { return instance; }
+ }
+
+ private readonly BansheeDbConnection connection;
+ private readonly HyenaSqliteCommand select_value_command;
+ private readonly HyenaSqliteCommand select_id_command;
+ private readonly HyenaSqliteCommand insert_command;
+ private readonly HyenaSqliteCommand update_command;
+
+ public DatabaseConfigurationClient(BansheeDbConnection connection)
+ {
+ this.connection = connection;
+
+ select_value_command = new HyenaSqliteCommand (String.Format (
+ "SELECT Value FROM {0} WHERE Key=?", TableName));
+
+ select_id_command = new HyenaSqliteCommand (String.Format (
+ "SELECT EntryID FROM {0} WHERE Key=?", TableName));
+
+ insert_command = new HyenaSqliteCommand (String.Format (
+ "INSERT INTO {0} VALUES (NULL, ?, ?)", TableName));
+
+ update_command = new HyenaSqliteCommand (String.Format (
+ "UPDATE {0} SET Value=? WHERE Key=?", TableName));
+ }
+
+ public T Get <T> (SchemaEntry<T> entry)
+ {
+ return Get (entry.Namespace, entry.Key, entry.DefaultValue);
+ }
+
+ public T Get <T> (SchemaEntry<T> entry, T fallback)
+ {
+ return Get (entry.Namespace, entry.Key, fallback);
+ }
+
+ public T Get <T> (string key, T fallback)
+ {
+ return Get (null, key, fallback);
+ }
+
+ public T Get <T> (string namespce, string key, T fallback)
+ {
+ using (IDataReader reader = Get (namespce, key)) {
+ if (reader.Read ()) {
+ return (T) Convert.ChangeType (reader.GetString (0), typeof (T));
+ } else {
+ return fallback;
+ }
+ }
+ }
+
+ private IDataReader Get (string namespce, string key)
+ {
+ return connection.ExecuteReader (
+ select_value_command.ApplyValues (MakeKey (namespce, key)));
+ }
+
+ public void Set <T> (SchemaEntry<T> entry, T value)
+ {
+ Set (entry.Namespace, entry.Key, value);
+ }
+
+ public void Set <T> (string key, T value)
+ {
+ Set (null, key, value);
+ }
+
+ public void Set <T> (string namespce, string key, T value)
+ {
+ if (connection.QueryInt32 (select_id_command.ApplyValues (MakeKey (namespce, key))) > 0) {
+ connection.Execute (
+ update_command.ApplyValues (value.ToString (), MakeKey (namespce, key))
+ );
+ } else {
+ connection.Execute (
+ insert_command.ApplyValues (MakeKey (namespce, key), value.ToString ())
+ );
+ }
+ }
+
+ private static string MakeKey (string namespce, string key)
+ {
+ return String.Format (
+ "{0}{1}{2}",
+ namespce, String.IsNullOrEmpty (namespce) ? String.Empty : ".", key
+ );
+ }
+
+ protected virtual string TableName {
+ get { return "CoreConfiguration"; }
+ }
+ }
+}
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 Fri Feb 1 07:41:45 2008
@@ -32,6 +32,8 @@
using Hyena.Data.Sqlite;
+using Banshee.Configuration;
+
namespace Banshee.Database
{
public class BansheeModelProvider<T> : SqliteModelProvider<T> where T : new ()
@@ -61,36 +63,22 @@
protected override sealed void CheckVersion ()
{
- 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 (
- "UPDATE CoreConfiguration SET Value = '{0}' WHERE Key = '{0}ModelVersion'",
- ModelVersion, TableName));
- }
- } else {
- connection.Execute (String.Format (
- "INSERT INTO CoreConfiguration (Key, Value) VALUES ('{0}ModelVersion', '{1}')",
- TableName, ModelVersion));
- }
+ CheckVersion (TableName, "ModelVersion", ModelVersion, MigrateTable);
+ CheckVersion ("Database", "Version", DatabaseVersion, MigrateDatabase);
+ }
+
+ private delegate void MigrateDel (int version);
+
+ private static void CheckVersion (string namespce, string key, int new_version, MigrateDel func)
+ {
+ int old_version = DatabaseConfigurationClient.Client.Get <int> (
+ namespce, key, -1);
+ if (old_version != -1 && old_version < new_version) {
+ func (old_version);
}
- 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 (
- "INSERT INTO CoreConfiguration (Key, Value) VALUES ('DatabaseVersion', '{0}')",
- DatabaseVersion));
- }
+ if (old_version != new_version) {
+ DatabaseConfigurationClient.Client.Set <int> (
+ namespce, key, new_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 Feb 1 07:41:45 2008
@@ -118,6 +118,8 @@
<File name="Banshee.Sources/IDurationAggregator.cs" subtype="Code" buildaction="Compile" />
<File name="Banshee.Sources/IFileSizeAggregator.cs" subtype="Code" buildaction="Compile" />
<File name="Banshee.ServiceStack/IExtensionService.cs" subtype="Code" buildaction="Compile" />
+ <File name="Banshee.Configuration" subtype="Directory" buildaction="Compile" />
+ <File name="Banshee.Configuration/DatabaseConfigurationClient.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 Feb 1 07:41:45 2008
@@ -25,6 +25,7 @@
Banshee.Collection/ImportManager.cs \
Banshee.Collection/ModelHelper.cs \
Banshee.Collection/TrackListModel.cs \
+ Banshee.Configuration/DatabaseConfigurationClient.cs \
Banshee.Database/BansheeDbConnection.cs \
Banshee.Database/BansheeDbFormatMigrator.cs \
Banshee.Database/BansheeModelCache.cs \
Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.ThickClient.mdp
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.ThickClient.mdp (original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.ThickClient.mdp Fri Feb 1 07:41:45 2008
@@ -79,6 +79,7 @@
<File name="Banshee.Sources.Gui/CellEditEntry.cs" subtype="Code" buildaction="Compile" />
<File name="Banshee.Sources.Gui/SourceRowRenderer.cs" subtype="Code" buildaction="Compile" />
<File name="Banshee.Sources.Gui/SourceView_DragAndDrop.cs" subtype="Code" buildaction="Compile" />
+ <File name="Banshee.Gui.Dialogs/PreferencesDialog.cs" subtype="Code" buildaction="Compile" />
</Contents>
<References>
<ProjectReference type="Project" localcopy="False" refto="Hyena.Gui" />
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]