From 0155de4d9293f2d106315bf05e4b39d6834373aa Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 3 Feb 2013 17:27:34 -0800 Subject: [PATCH] registered eloquere db with autofac. --- NzbDrone.Common/PathExtentions.cs | 27 ++++++++--- .../Datastore/ObjectDatabaseFixture.cs | 45 +++++++++++-------- NzbDrone.Core/ContainerExtentions.cs | 6 +++ NzbDrone.Core/Datastore/ConnectionFactory.cs | 4 +- NzbDrone.Core/Datastore/EloqueraDb.cs | 6 +-- .../Datastore/Migrations/NzbDroneMigration.cs | 4 +- NzbDrone.Core/Providers/BackupProvider.cs | 2 +- 7 files changed, 61 insertions(+), 33 deletions(-) diff --git a/NzbDrone.Common/PathExtentions.cs b/NzbDrone.Common/PathExtentions.cs index 38e1fa78a..6a3058115 100644 --- a/NzbDrone.Common/PathExtentions.cs +++ b/NzbDrone.Common/PathExtentions.cs @@ -9,13 +9,16 @@ namespace NzbDrone.Common private const string APP_DATA = "App_Data\\"; public const string IIS_FOLDER = "IISExpress"; public const string IIS_EXE = "iisexpress.exe"; - + private const string LOG_CONFIG_FILE = "log.config"; private const string APP_CONFIG_FILE = "config.xml"; public const string NZBDRONE_EXE = "NzbDrone.exe"; - public const string NZBDRONE_DB_FILE = "nzbdrone.sdf"; - public const string LOG_DB_FILE = "log.sdf"; + public const string NZBDRONE_SQLCE_DB_FILE = "nzbdrone.sdf"; + public const string NZBDRONE_ELQ_DB_FILE = "nzbdrone.eq"; + + public const string LOG_SQLCE_DB_FILE = "log.sdf"; + public const string LOG_ELQ_DB_FILE = "log.eq"; private const string BACKUP_ZIP_FILE = "NzbDrone_Backup.zip"; @@ -77,14 +80,24 @@ namespace NzbDrone.Common return Path.Combine(environmentProvider.ApplicationPath, APP_CONFIG_FILE); } - public static string GetNzbDroneDbFile(this EnvironmentProvider environmentProvider) + public static string GetSqlCeMainDbPath(this EnvironmentProvider environmentProvider) + { + return Path.Combine(environmentProvider.GetAppDataPath(), NZBDRONE_SQLCE_DB_FILE); + } + + public static string GetSqlCeLogDbPath(this EnvironmentProvider environmentProvider) + { + return Path.Combine(environmentProvider.GetAppDataPath(), LOG_SQLCE_DB_FILE); + } + + public static string GetElqMainDbPath(this EnvironmentProvider environmentProvider) { - return Path.Combine(environmentProvider.GetAppDataPath(), NZBDRONE_DB_FILE); + return Path.Combine(environmentProvider.GetAppDataPath(), NZBDRONE_ELQ_DB_FILE); } - public static string GetLogDbFileDbFile(this EnvironmentProvider environmentProvider) + public static string GetElqLogDbPath(this EnvironmentProvider environmentProvider) { - return Path.Combine(environmentProvider.GetAppDataPath(), LOG_DB_FILE); + return Path.Combine(environmentProvider.GetAppDataPath(), LOG_ELQ_DB_FILE); } public static string GetMediaCoverPath(this EnvironmentProvider environmentProvider) diff --git a/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs b/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs index abbf8a106..cd96feb4e 100644 --- a/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs +++ b/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs @@ -10,20 +10,25 @@ namespace NzbDrone.Core.Test.Datastore [TestFixture] public class ObjectDatabaseFixture : ObjectDbTest { + private Series testSeries; + private Episode testEpisode; + + [SetUp] public void SetUp() { WithObjectDb(); + + testSeries = Builder.CreateNew().Build(); + testEpisode = Builder.CreateNew().Build(); + + } [Test] public void should_be_able_to_write_to_database() { - - var series = Builder.CreateNew().Build(); - - Db.Create(series); - + Db.Insert(testSeries); Db.AsQueryable().Should().HaveCount(1); @@ -32,14 +37,11 @@ namespace NzbDrone.Core.Test.Datastore [Test] public void should_not_store_dirty_data_in_cache() { - var episode = Builder.CreateNew().Build(); - - //Save series without episode attached - Db.Create(episode); + Db.Insert(testEpisode); Db.AsQueryable().Single().Series.Should().BeNull(); - episode.Series = Builder.CreateNew().Build(); + testEpisode.Series = Builder.CreateNew().Build(); Db.AsQueryable().Single().Series.Should().BeNull(); } @@ -49,10 +51,9 @@ namespace NzbDrone.Core.Test.Datastore [Test] public void should_store_nested_objects() { - var episode = Builder.CreateNew().Build(); - episode.Series = Builder.CreateNew().Build(); + testEpisode.Series = testSeries; - Db.Create(episode); + Db.Insert(testEpisode); Db.AsQueryable().Should().HaveCount(1); Db.AsQueryable().Single().Series.Should().NotBeNull(); @@ -61,18 +62,26 @@ namespace NzbDrone.Core.Test.Datastore [Test] public void should_update_nested_objects() { - var episode = Builder.CreateNew().Build(); - episode.Series = Builder.CreateNew().Build(); + testEpisode.Series = Builder.CreateNew().Build(); - Db.Create(episode); + Db.Insert(testEpisode); - episode.Series.Title = "UpdatedTitle"; + testEpisode.Series.Title = "UpdatedTitle"; - Db.Update(episode); + Db.Update(testEpisode); Db.AsQueryable().Should().HaveCount(1); Db.AsQueryable().Single().Series.Should().NotBeNull(); Db.AsQueryable().Single().Series.Title.Should().Be("UpdatedTitle"); } + + + [Test] + public void new_objects_should_get_id() + { + Db.Insert(testSeries); + testSeries.Id.Should().NotBe(0); + } } } + diff --git a/NzbDrone.Core/ContainerExtentions.cs b/NzbDrone.Core/ContainerExtentions.cs index b305f3e28..c76b35397 100644 --- a/NzbDrone.Core/ContainerExtentions.cs +++ b/NzbDrone.Core/ContainerExtentions.cs @@ -80,6 +80,12 @@ namespace NzbDrone.Core container.Register(c => c.Resolve().GetLogPetaPocoDb()) .Named("LogProvider"); + container.Register(c => + { + var env = c.Resolve(); + return c.Resolve().Create(env.GetElqMainDbPath()); + }).As().SingleInstance(); + container.RegisterType().WithParameter(ResolvedParameter.ForNamed("DatabaseTarget")); container.RegisterType().WithParameter(ResolvedParameter.ForNamed("LogProvider")); } diff --git a/NzbDrone.Core/Datastore/ConnectionFactory.cs b/NzbDrone.Core/Datastore/ConnectionFactory.cs index 56eab6b39..330f15fca 100644 --- a/NzbDrone.Core/Datastore/ConnectionFactory.cs +++ b/NzbDrone.Core/Datastore/ConnectionFactory.cs @@ -35,7 +35,7 @@ namespace NzbDrone.Core.Datastore { get { - return GetConnectionString(_environmentProvider.GetNzbDroneDbFile()); + return GetConnectionString(_environmentProvider.GetSqlCeMainDbPath()); } } @@ -43,7 +43,7 @@ namespace NzbDrone.Core.Datastore { get { - return GetConnectionString(_environmentProvider.GetLogDbFileDbFile()); + return GetConnectionString(_environmentProvider.GetSqlCeLogDbPath()); } } diff --git a/NzbDrone.Core/Datastore/EloqueraDb.cs b/NzbDrone.Core/Datastore/EloqueraDb.cs index 7a55c5097..4cf96e9a1 100644 --- a/NzbDrone.Core/Datastore/EloqueraDb.cs +++ b/NzbDrone.Core/Datastore/EloqueraDb.cs @@ -20,15 +20,15 @@ namespace NzbDrone.Core.Datastore } - public T Create(T obj) + public T Insert(T obj) { _db.Store(obj); return obj; } - public IList CreateMany(IEnumerable objects) + public IList InsertMany(IEnumerable objects) { - return DoMany(objects, Create); + return DoMany(objects, Insert); } public T Update(T obj) diff --git a/NzbDrone.Core/Datastore/Migrations/NzbDroneMigration.cs b/NzbDrone.Core/Datastore/Migrations/NzbDroneMigration.cs index 560df46fe..cef596c3d 100644 --- a/NzbDrone.Core/Datastore/Migrations/NzbDroneMigration.cs +++ b/NzbDrone.Core/Datastore/Migrations/NzbDroneMigration.cs @@ -17,11 +17,11 @@ namespace NzbDrone.Core.Datastore.Migrations public override void Up() { - if (Database.ConnectionString.Contains(PathExtentions.NZBDRONE_DB_FILE)) + if (Database.ConnectionString.Contains(PathExtentions.NZBDRONE_SQLCE_DB_FILE)) { MainDbUpgrade(); } - else if (Database.ConnectionString.Contains(PathExtentions.LOG_DB_FILE)) + else if (Database.ConnectionString.Contains(PathExtentions.LOG_SQLCE_DB_FILE)) { LogDbUpgrade(); } diff --git a/NzbDrone.Core/Providers/BackupProvider.cs b/NzbDrone.Core/Providers/BackupProvider.cs index 5fad7a641..303ac9142 100644 --- a/NzbDrone.Core/Providers/BackupProvider.cs +++ b/NzbDrone.Core/Providers/BackupProvider.cs @@ -23,7 +23,7 @@ namespace NzbDrone.Core.Providers public virtual string CreateBackupZip() { - var dbFile = _environmentProvider.GetNzbDroneDbFile(); + var dbFile = _environmentProvider.GetSqlCeMainDbPath(); var configFile = _environmentProvider.GetConfigPath(); var zipFile = _environmentProvider.GetConfigBackupFile();