using System;
using System.Collections.ObjectModel;
using System.Linq.Expressions;
using Pfz.Collections;
using Pfz.Databasing.Filtering;
using Pfz.Databasing.Managers;
namespace Pfz.Databasing.Tiers
{
/// <summary>
/// Base class to create a "tier" over another database manager.
/// </summary>
public abstract class TierBase:
IDatabaseManager
{
/// <summary>
/// Gets the BaseManager for this tier.
/// </summary>
public virtual IDatabaseManager BaseManager { get; set; }
/// <summary>
/// By default, only calls the BaseManager.
/// Can be reimplemented to do whatever you think is needed.
/// </summary>
public virtual bool MustCloneBeforeApply
{
get
{
return BaseManager.MustCloneBeforeApply;
}
}
/// <summary>
/// By default, only calls the BaseManager.
/// Can be reimplemented to do whatever you think is needed.
/// </summary>
public virtual IDatabaseConnection CreateConnection(string name)
{
return BaseManager.CreateConnection(name);
}
/// <summary>
/// By default, only calls the BaseManager.
/// Can be reimplemented to do whatever you think is needed.
/// </summary>
public virtual T TryLoadByPrimaryKey<T>(IDatabaseConnection connection, object primaryKeyValue)
where
T: class, IRecord
{
return BaseManager.TryLoadByPrimaryKey<T>(connection, primaryKeyValue);
}
/// <summary>
/// By default, only calls the BaseManager.
/// Can be reimplemented to do whatever you think is needed.
/// </summary>
public virtual T Create<T>(IDatabaseConnection connection)
where
T: class, IRecord
{
return BaseManager.Create<T>(connection);
}
/// <summary>
/// By default, only calls the BaseManager.
/// Can be reimplemented to do whatever you think is needed.
/// </summary>
public virtual T Apply<T>(IDatabaseConnection connection, T record)
where
T: class, IRecord
{
return BaseManager.Apply(connection, record);
}
/// <summary>
/// By default, only calls the BaseManager.
/// Can be reimplemented to do whatever you think is needed.
/// </summary>
public virtual IFastEnumerator<T> FastLoadByPartialSql<T>(IDatabaseConnection connection, string sql, params object[] parameterValues)
where
T: class, IRecord
{
return BaseManager.FastLoadByPartialSql<T>(connection, sql, parameterValues);
}
/// <summary>
/// By default, only calls the BaseManager.
/// Can be reimplemented to do whatever you think is needed.
/// </summary>
public virtual IFastEnumerator<T> FastLoadByFilter<T>(IDatabaseConnection connection, Filter filter, ReadOnlyCollection<OrderByIndex> orderByIndexes = null)
where
T: class, IRecord
{
return BaseManager.FastLoadByFilter<T>(connection, filter, orderByIndexes);
}
/// <summary>
/// By default, only calls the BaseManager.
/// Can be reimplemented to do whatever you think is needed.
/// </summary>
public virtual int CountRecordsByFilter<T>(IDatabaseConnection connection, Filter filter)
where
T: class, IRecord
{
return BaseManager.CountRecordsByFilter<T>(connection, filter);
}
/// <summary>
/// By default, only calls the BaseManager.
/// Can be reimplemented to do whatever you think is needed.
/// </summary>
public virtual IFastEnumerator<object[]> AdvancedLoad(IDatabaseConnection connection, AdvancedLoadParameters parameters)
{
return BaseManager.AdvancedLoad(connection, parameters);
}
/// <summary>
/// By default, only calls the BaseManager.
/// Can be reimplemented to do whatever you think is needed.
/// </summary>
public virtual Type GetImplementedTypeFor(Type recordInterfaceType)
{
return BaseManager.GetImplementedTypeFor(recordInterfaceType);
}
/// <summary>
/// By default, only calls the BaseManager.
/// Can be reimplemented to do whatever you think is needed.
/// </summary>
public int Delete<T>(IDatabaseConnection databaseConnection, Expression<Func<T, bool>> expression)
where
T: class, IRecord
{
return BaseManager.Delete<T>(databaseConnection, expression);
}
/// <summary>
/// By default, only calls the BaseManager.
/// Can be reimplemented to do whatever you think is needed.
/// </summary>
public int Update<T>(IDatabaseConnection databaseConnection, Expression<Func<T, bool>> setExpression, Expression<Func<T, bool>> whereExpression) where T : class, IRecord
{
return BaseManager.Update<T>(databaseConnection, setExpression, whereExpression);
}
}
}