Initial Commit for Eloquera

This commit is contained in:
Mark McDowall 2013-02-03 14:01:36 -08:00 committed by kay.one
parent f973a42669
commit 23b90ae1c4
14 changed files with 211 additions and 189 deletions

View File

@ -0,0 +1,31 @@
<?xml version="1.0"?>
<Eloquera xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Cache IndexCacheSize="10000"
WriteThru="false"
IndexCleanerPeriod="100"
IndexCleanerBatchSize="100"
CleanerPeriod="100"
CleanerBatchSize="2000"
CommitSequenceMaxLength="2000"
ShallowReadThreshold="1000"
ShallowReadAhead="1000"
ReadAhead="20"
SaturationThreshold="10000"
MemoryFootPrint="60"/>
<MemoryManager Mode="1" />
<Server ServerPort="43962"
Trace="true"
InMemoryAllowed="true"
Secure="false"
AllowUsers=""
AllowGroups="Everyone"
SNMPAddress="net.tcp://localhost:8523/SNMP"
AutoRecovery="false"
NotificationsEnabled="false"
VarSectorSize="40"
IndexNodeSize="512"/>
<SmartRuntime Smart="true"
TypeUpdateAllowed="true"/>
<UserLogin Enabled="false"
PasswordHash="l+on1aCwDrcZ5bGlv+fyyIlYkbuFIOxZFlFwIGKlms0CCwoGn9TZvM0E3Uksjwx64+/yv8nsaUajWLz1kyKG7A==" />
</Eloquera>

View File

@ -32,8 +32,8 @@ namespace NzbDrone.Core.Test.Framework
public abstract class ObjectDbTest : CoreTest
{
private IObjectDbSession _db;
protected IObjectDbSession Db
private EloqueraDb _db;
protected EloqueraDb Db
{
get
{
@ -48,11 +48,12 @@ namespace NzbDrone.Core.Test.Framework
{
if (memory)
{
_db = new ObjectDbSessionFactory().Create(new PagingMemoryStorage());
//Todo: Actually use memory: http://www.eloquera.com/sites/default/files/filepicker/1/Help/Documentation/HTML/In-memory%20database.htm
_db = new EloqueraDbFactory().Create();
}
else
{
_db = new ObjectDbSessionFactory().Create(dbName: Guid.NewGuid().ToString());
_db = new EloqueraDbFactory().Create(dbFilename: Guid.NewGuid().ToString());
}
Mocker.SetConstant(Db);

View File

@ -78,6 +78,15 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libraries\DeskMetrics\DeskMetrics.NET.dll</HintPath>
</Reference>
<Reference Include="Eloquera.Client">
<HintPath>..\packages\EloqueraDB.5.0.0\lib\net40\Eloquera.Client.dll</HintPath>
</Reference>
<Reference Include="Eloquera.Common">
<HintPath>..\packages\EloqueraDB.5.0.0\lib\net40\Eloquera.Common.dll</HintPath>
</Reference>
<Reference Include="Eloquera.Server">
<HintPath>..\packages\EloqueraDB.5.0.0\lib\net40\Eloquera.Server.exe</HintPath>
</Reference>
<Reference Include="FizzWare.NBuilder, Version=3.0.1.0, Culture=neutral, PublicKeyToken=5651b03e12e42c12, processorArchitecture=MSIL">
<HintPath>..\packages\NBuilder.3.0.1.1\lib\FizzWare.NBuilder.dll</HintPath>
</Reference>
@ -317,6 +326,7 @@
<Content Include="Files\JsonError.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="Eloquera.config" />
<None Include="Files\RSS\nzbx_search.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>

View File

@ -4,6 +4,7 @@
<package id="AutoMoq" version="1.6.1" targetFramework="net40" />
<package id="CommonServiceLocator" version="1.0" targetFramework="net40" />
<package id="db4o-devel" version="8.1.184.15492" targetFramework="net40" />
<package id="EloqueraDB" version="5.0.0" targetFramework="net40" />
<package id="FluentAssertions" version="2.0.0.1" targetFramework="net40" />
<package id="Microsoft.SqlServer.Compact" version="4.0.8876.1" targetFramework="net40" />
<package id="Moq" version="4.0.10827" />

View File

@ -1,7 +1,6 @@
using System;
using System.Data.Common;
using System.Data.SqlServerCe;
using Db4objects.Db4o.Internal.Config;
using StackExchange.Profiling;
using StackExchange.Profiling.Data;

View File

@ -0,0 +1,89 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Eloquera.Client;
namespace NzbDrone.Core.Datastore
{
public class EloqueraDb : IDisposable
{
private DB _db;
public EloqueraDb(DB db)
{
_db = db;
}
public int Create(object obj)
{
return Convert.ToInt32(_db.Store(obj));
}
public void Update(object obj)
{
_db.Store(obj);
}
public void Delete(object obj)
{
_db.Delete(obj);
}
public void DeleteAll(object obj)
{
_db.DeleteAll(obj);
}
public IEnumerable<T> Query<T>()
{
return _db.Query<T>();
}
public IEnumerable ExecuteQuery(string query)
{
return _db.ExecuteQuery(query);
}
public IEnumerable ExecuteQuery(string query, int depth)
{
return _db.ExecuteQuery(query, depth);
}
public IEnumerable ExecuteQuery(string query, int depth, Parameters parameters)
{
return _db.ExecuteQuery(query, depth, parameters);
}
public IEnumerable ExecuteQuery(string query, Parameters parameters)
{
return _db.ExecuteQuery(query, parameters);
}
public object ExecutScalar(string query)
{
return _db.ExecuteQuery(query);
}
public object ExecuteScalar(string query, int depth)
{
return _db.ExecuteQuery(query, depth);
}
public object ExecuteScalar(string query, int depth, Parameters parameters)
{
return _db.ExecuteQuery(query, depth, parameters);
}
public object ExecuteScalar(string query, Parameters parameters)
{
return _db.ExecuteQuery(query, parameters);
}
public void Dispose()
{
_db.Dispose();
}
}
}

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Eloquera.Client;
using NzbDrone.Common;
namespace NzbDrone.Core.Datastore
{
public class EloqueraDbFactory
{
private readonly EnvironmentProvider _environmentProvider;
public EloqueraDbFactory()
{
_environmentProvider = new EnvironmentProvider();
}
public EloqueraDb Create(string dbName = "NzbDrone", string dbFilename = "nzbdrone.eloq")
{
DB db = new DB();
DB.Configuration.ServerSettings.DatabasePath = Path.Combine(_environmentProvider.GetAppDataPath(), dbName);
db.CreateDatabase(dbName);
db.OpenDatabase(dbName);
db.RefreshMode = ObjectRefreshMode.AlwaysReturnUpdatedValues;
return new EloqueraDb(db);
}
}
}

View File

@ -1,15 +0,0 @@
using System.Linq;
using Db4objects.Db4o.Internal;
using Db4objects.Db4o.Internal.References;
namespace NzbDrone.Core.Datastore
{
public class NoCacheReferenceSystem : HashcodeReferenceSystem
{
public override ObjectReference ReferenceForId(int id)
{
//never return an in memory instance of objects as query result. always go to db.
return null;
}
}
}

View File

@ -1,127 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Db4objects.Db4o;
using Db4objects.Db4o.Internal;
namespace NzbDrone.Core.Datastore
{
public interface IObjectDbSession : IObjectContainer
{
void Create(object obj);
void Create(object obj, int depth);
void SaveAll<T>(Transaction transaction, IEnumerator<T> objects);
void Update(object obj);
void Update(object obj, int depth);
void UpdateAll<T>(Transaction transaction, IEnumerator<T> objects);
}
public class ObjectDbSession : ObjectContainerSession, IObjectDbSession
{
public ObjectDbSession(ObjectContainerBase server)
: base(server, server.NewTransaction(server.SystemTransaction(), new NoCacheReferenceSystem(), false))
{
_transaction.SetOutSideRepresentation(this);
}
public override void Store(object obj)
{
throw new InvalidOperationException("Store is not supported. please use Create() or Update()");
}
public override void StoreAll(Transaction transaction, IEnumerator objects)
{
throw new InvalidOperationException("Store is not supported. please use Create() or Update()");
}
public override void Store(object obj, int depth)
{
throw new InvalidOperationException("Store is not supported. please use Create() or Update()");
}
public void Create(object obj)
{
ValidateCreate(obj);
base.Store(obj);
}
public void Create(object obj, int depth)
{
ValidateCreate(obj);
base.Store(obj, depth);
}
public void SaveAll<T>(Transaction transaction, IEnumerator<T> objects)
{
var obj = objects.ToIEnumerable().ToList();
obj.ForEach(c => ValidateCreate(c));
base.StoreAll(transaction, obj.GetEnumerator());
}
public void Update(object obj)
{
ValidateUpdate(obj);
base.Store(obj);
}
public void Update(object obj, int depth)
{
ValidateUpdate(obj);
base.Store(obj, depth);
}
public void UpdateAll<T>(Transaction transaction, IEnumerator<T> objects)
{
var obj = objects.ToIEnumerable().ToList();
obj.ForEach(c => ValidateUpdate(c));
base.StoreAll(transaction, obj.GetEnumerator());
}
public void UpdateAll(Transaction transaction, IEnumerator objects)
{
throw new NotImplementedException();
}
private void ValidateCreate(object obj)
{
if (IsAttached(obj))
{
throw new InvalidOperationException("Attempted to save an object that is already attached to database");
}
}
private void ValidateUpdate(object obj)
{
if (!IsAttached(obj))
{
throw new InvalidOperationException("Attempted to update an object that is not attached to database");
}
}
private bool IsAttached(object obj)
{
return base.Ext().GetID(obj) > 0;
}
}
public static class Ext
{
public static IEnumerable<T> ToIEnumerable<T>(this IEnumerator<T> enumerator)
{
while (enumerator.MoveNext())
{
yield return enumerator.Current;
}
}
}
}

View File

@ -1,25 +0,0 @@
using System.Linq;
using Db4objects.Db4o;
using Db4objects.Db4o.IO;
using Db4objects.Db4o.Internal;
namespace NzbDrone.Core.Datastore
{
public class ObjectDbSessionFactory
{
public IObjectDbSession Create(IStorage storage = null, string dbName = "nzbdrone.db4o")
{
if (storage == null)
{
storage = new FileStorage();
}
var config = Db4oEmbedded.NewConfiguration();
config.File.Storage = storage;
var objectContainer = Db4oEmbedded.OpenFile(config, dbName);
return new ObjectDbSession((ObjectContainerBase)objectContainer);
}
}
}

View File

@ -0,0 +1,31 @@
<?xml version="1.0"?>
<Eloquera xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Cache IndexCacheSize="10000"
WriteThru="false"
IndexCleanerPeriod="100"
IndexCleanerBatchSize="100"
CleanerPeriod="100"
CleanerBatchSize="2000"
CommitSequenceMaxLength="2000"
ShallowReadThreshold="1000"
ShallowReadAhead="1000"
ReadAhead="20"
SaturationThreshold="10000"
MemoryFootPrint="60"/>
<MemoryManager Mode="1" />
<Server ServerPort="43962"
Trace="true"
InMemoryAllowed="true"
Secure="false"
AllowUsers=""
AllowGroups="Everyone"
SNMPAddress="net.tcp://localhost:8523/SNMP"
AutoRecovery="false"
NotificationsEnabled="false"
VarSectorSize="40"
IndexNodeSize="512"/>
<SmartRuntime Smart="true"
TypeUpdateAllowed="true"/>
<UserLogin Enabled="false"
PasswordHash="l+on1aCwDrcZ5bGlv+fyyIlYkbuFIOxZFlFwIGKlms0CCwoGn9TZvM0E3Uksjwx64+/yv8nsaUajWLz1kyKG7A==" />
</Eloquera>

View File

@ -133,18 +133,18 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\DataTables.Mvc.Core.0.1.0.85\lib\DataTables.Mvc.Core.dll</HintPath>
</Reference>
<Reference Include="Db4objects.Db4o">
<HintPath>..\packages\db4o-devel.8.1.184.15492\lib\net40\Db4objects.Db4o.dll</HintPath>
</Reference>
<Reference Include="Db4objects.Db4o.Data.Services">
<HintPath>..\packages\db4o-devel.8.1.184.15492\lib\net40\Db4objects.Db4o.Data.Services.dll</HintPath>
</Reference>
<Reference Include="Db4objects.Db4o.Linq">
<HintPath>..\packages\db4o-devel.8.1.184.15492\lib\net40\Db4objects.Db4o.Linq.dll</HintPath>
</Reference>
<Reference Include="DeskMetrics.NET">
<HintPath>..\Libraries\DeskMetrics\DeskMetrics.NET.dll</HintPath>
</Reference>
<Reference Include="Eloquera.Client">
<HintPath>..\packages\EloqueraDB.5.0.0\lib\net40\Eloquera.Client.dll</HintPath>
</Reference>
<Reference Include="Eloquera.Common">
<HintPath>..\packages\EloqueraDB.5.0.0\lib\net40\Eloquera.Common.dll</HintPath>
</Reference>
<Reference Include="Eloquera.Server">
<HintPath>..\packages\EloqueraDB.5.0.0\lib\net40\Eloquera.Server.exe</HintPath>
</Reference>
<Reference Include="Growl.Connector">
<HintPath>..\packages\Growl.0.6\lib\Growl.Connector.dll</HintPath>
</Reference>
@ -177,9 +177,6 @@
<Reference Include="MiniProfiler">
<HintPath>..\packages\MiniProfiler.2.0.2\lib\net40\MiniProfiler.dll</HintPath>
</Reference>
<Reference Include="Mono.Reflection">
<HintPath>..\packages\db4o-devel.8.1.184.15492\lib\net40\Mono.Reflection.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll</HintPath>
@ -235,8 +232,8 @@
<Compile Include="Constants.cs" />
<Compile Include="ContainerExtentions.cs" />
<Compile Include="Datastore\ConnectionFactory.cs" />
<Compile Include="Datastore\NoCacheReferenceSystem.cs" />
<Compile Include="Datastore\ObjectDbSession.cs" />
<Compile Include="Datastore\EloqueraDb.cs" />
<Compile Include="Datastore\EloqueraDbFactory.cs" />
<Compile Include="Datastore\MigrationLogger.cs" />
<Compile Include="Datastore\MigrationsHelper.cs" />
<Compile Include="Datastore\CustomeMapper.cs" />
@ -270,7 +267,6 @@
<Compile Include="Datastore\Migrations\Migration20121223.cs" />
<Compile Include="Datastore\Migrations\NzbDroneMigration.cs" />
<Compile Include="Datastore\Migrations\SchemaInfo.cs" />
<Compile Include="Datastore\ObjectDbSessionFactory.cs" />
<Compile Include="Datastore\PetaPoco\EpisodeSeasonRelator.cs" />
<Compile Include="Fluent.cs" />
<Compile Include="Helpers\Converters\EpochDateTimeConverter.cs" />
@ -644,6 +640,7 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="Eloquera.config" />
<None Include="packages.config" />
<None Include="Properties\AnalysisRules.ruleset" />
</ItemGroup>

View File

@ -2,8 +2,8 @@
<packages>
<package id="Autofac" version="2.6.3.862" targetFramework="net40" />
<package id="DataTables.Mvc.Core" version="0.1.0.85" />
<package id="db4o-devel" version="8.1.184.15492" targetFramework="net40" />
<package id="DotNetZip" version="1.9.1.8" />
<package id="EloqueraDB" version="5.0.0" targetFramework="net40" />
<package id="Growl" version="0.6" />
<package id="MediaInfoNet" version="0.3" targetFramework="net40" />
<package id="Microsoft.SqlServer.Compact" version="4.0.8876.1" targetFramework="net40" />

View File

@ -2,7 +2,6 @@
<FileVersion>1</FileVersion>
<AutoEnableOnStartup>False</AutoEnableOnStartup>
<AllowParallelTestExecution>true</AllowParallelTestExecution>
<AllowTestsToRunInParallelWithThemselves>true</AllowTestsToRunInParallelWithThemselves>
<FrameworkUtilisationTypeForNUnit>UseDynamicAnalysis</FrameworkUtilisationTypeForNUnit>
<FrameworkUtilisationTypeForGallio>Disabled</FrameworkUtilisationTypeForGallio>
<FrameworkUtilisationTypeForMSpec>Disabled</FrameworkUtilisationTypeForMSpec>