You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Readarr/NzbDrone.Core/Datastore/SiaqodbProxy.cs

88 lines
2.3 KiB

using System;
using System.Collections.Generic;
using System.Linq;
12 years ago
using Sqo;
namespace NzbDrone.Core.Datastore
{
12 years ago
public interface IObjectDatabase : IDisposable
{
12 years ago
IEnumerable<T> AsQueryable<T>();
T Insert<T>(T obj) where T : BaseRepositoryModel;
T Update<T>(T obj) where T : BaseRepositoryModel;
IList<T> InsertMany<T>(IList<T> objects) where T : BaseRepositoryModel;
IList<T> UpdateMany<T>(IList<T> objects) where T : BaseRepositoryModel;
void Delete<T>(T obj) where T : BaseRepositoryModel;
void DeleteMany<T>(IEnumerable<T> objects) where T : BaseRepositoryModel;
}
public class SiaqodbProxy : IObjectDatabase
{
private readonly Siaqodb _db;
public SiaqodbProxy(Siaqodb db)
{
_db = db;
}
12 years ago
public void Dispose()
{
12 years ago
}
public IEnumerable<T> AsQueryable<T>()
{
12 years ago
return _db.Cast<T>();
}
public T Insert<T>(T obj) where T : BaseRepositoryModel
{
12 years ago
if (obj.OID != 0)
{
throw new InvalidOperationException("Attempted to insert object with existing ID as new object");
}
12 years ago
_db.StoreObject(obj);
return obj;
}
public T Update<T>(T obj) where T : BaseRepositoryModel
{
12 years ago
if (obj.OID == 0)
{
12 years ago
throw new InvalidOperationException("Attempted to update object without an ID");
}
12 years ago
_db.StoreObject(obj);
return obj;
}
public IList<T> InsertMany<T>(IList<T> objects) where T : BaseRepositoryModel
{
12 years ago
return DoMany(objects,Insert);
}
12 years ago
public IList<T> UpdateMany<T>(IList<T> objects) where T : BaseRepositoryModel
{
return DoMany(objects, Update);
12 years ago
}
public void Delete<T>(T obj) where T : BaseRepositoryModel
{
12 years ago
throw new NotImplementedException();
}
public void DeleteMany<T>(IEnumerable<T> objects) where T : BaseRepositoryModel
{
12 years ago
throw new NotImplementedException();
}
private IList<T> DoMany<T>(IEnumerable<T> objects, Func<T, T> function) where T : BaseRepositoryModel
{
return objects.Select(function).ToList();
}
}
}