1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2025-02-28 00:36:15 +00:00
Sonarr/NzbDrone.Core/Datastore/DbProviderFactory.cs
kay.one 5dbaaee005 Added db4o.
Added guards against most problematic areas.
2013-02-15 16:52:45 -08:00

49 lines
1.3 KiB
C#

using System;
using System.Data.Common;
using System.Data.SqlServerCe;
using Db4objects.Db4o;
using Db4objects.Db4o.IO;
using Db4objects.Db4o.Internal;
using Db4objects.Db4o.Internal.Config;
using StackExchange.Profiling;
using StackExchange.Profiling.Data;
namespace NzbDrone.Core.Datastore
{
class DbProviderFactory : System.Data.Common.DbProviderFactory
{
public Boolean IsProfiled { get; set; }
public override DbConnection CreateConnection()
{
var sqliteConnection = new SqlCeConnection();
DbConnection connection = sqliteConnection;
if (IsProfiled)
{
connection = new ProfiledDbConnection(sqliteConnection, MiniProfiler.Current);
}
return connection;
}
}
public class ObjectDbSessionFactory
{
public IObjectDbSession Create(IStorage storage = null)
{
if (storage == null)
{
storage = new FileStorage();
}
var config = Db4oEmbedded.NewConfiguration();
config.File.Storage = storage;
var objectContainer = Db4oEmbedded.OpenFile(config, "nzbdrone.db4o");
return new ObjectDbSession((ObjectContainerBase)objectContainer);
}
}
}