Changeset 1128


Ignore:
Timestamp:
01/14/09 17:19:08 (12 years ago)
Author:
svonolfe
Message:

Readded locking (#372)

Location:
trunk/sources/HeuristicLab.Hive.Server.ADODataAccess
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/CachedDataAdapter.cs

    r1125 r1128  
    3030namespace HeuristicLab.Hive.Server.ADODataAccess {
    3131  abstract class CachedDataAdapter<AdapterT, ObjT, RowT, CacheT> :
    32     DataAdapterBase<AdapterT, ObjT, RowT>, 
     32    DataAdapterBase<AdapterT, ObjT, RowT>,
    3333    ICachedDataAdapter
    34     where CacheT: System.Data.TypedTableBase<RowT>, new()
     34    where CacheT : System.Data.TypedTableBase<RowT>, new()
    3535    where AdapterT : new()
    3636    where RowT : System.Data.DataRow
    3737    where ObjT : IHiveObject, new() {
    38     protected CacheT cache = 
     38    protected CacheT cache =
    3939      new CacheT();
     40
     41    protected IDictionary<long, DataTable> dataTable =
     42      new Dictionary<long, DataTable>();
    4043
    4144    protected ICollection<ICachedDataAdapter> parentAdapters =
    4245      new List<ICachedDataAdapter>();
    4346
    44     private DataTable temp = new DataTable();
    45 
    4647    protected CachedDataAdapter() {
    4748      FillCache();
     
    5152    }
    5253
    53     protected virtual RowT FindSingleRow(Selector dbSelector,
     54    [MethodImpl(MethodImplOptions.Synchronized)]
     55    protected virtual RowT FindSingleRow(Selector dbSelector,
    5456      Selector cacheSelector) {
    5557      RowT row =
     
    6567    }
    6668
     69    [MethodImpl(MethodImplOptions.Synchronized)]
    6770    protected virtual IEnumerable<RowT> FindMultipleRows(Selector dbSelector,
    6871        Selector cacheSelector) {
     
    9699    }
    97100
     101    [MethodImpl(MethodImplOptions.Synchronized)]
    98102    protected virtual ICollection<ObjT> FindMultiple(Selector dbSelector,
    99103      Selector cacheSelector) {
     
    124128    protected abstract bool PutInCache(ObjT obj);
    125129
     130    [MethodImpl(MethodImplOptions.Synchronized)]
    126131    protected abstract RowT FindCachedById(long id);
    127132
     
    136141
    137142    [MethodImpl(MethodImplOptions.Synchronized)]
    138     protected virtual void RemoveRowFromCache(RowT row) {     
     143    protected virtual void RemoveRowFromCache(RowT row) {
    139144      cache.Rows.Remove(row);
    140145    }
     
    143148      if (row == null)
    144149        return false;
    145      else
     150      else
    146151        return FindCachedById((long)row[row.Table.PrimaryKey[0]]) != null;
    147152    }
    148153
     154    [MethodImpl(MethodImplOptions.Synchronized)]
    149155    protected override RowT GetRowById(long id) {
    150156      RowT row =
    151157        FindCachedById(id);
    152      
    153       if(row == null)
     158
     159      if (row == null)
    154160        row = FindSingleRow(
    155161          delegate() {
     
    163169    public override void Update(ObjT obj) {
    164170      if (obj != null) {
    165         RowT row = 
     171        RowT row =
    166172          GetRowById(obj.Id);
    167173
     
    182188        if (!IsCached(row))
    183189          UpdateRow(row);
    184        
     190
    185191        if (IsCached(row) &&
    186192            !PutInCache(obj)) {
    187193          //remove from cache
    188           temp.ImportRow(row);
     194          dataTable[obj.Id].ImportRow(row);
     195          dataTable.Remove(obj.Id);
    189196
    190197          UpdateRow(row);
     
    195202          cache.ImportRow(row);
    196203
     204          dataTable[obj.Id] = row.Table;
    197205          row.Table.Rows.Remove(row);
    198206        }
     
    201209  }
    202210}
     211
  • trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/DataAdapterBase.cs

    r1125 r1128  
    2929namespace HeuristicLab.Hive.Server.ADODataAccess {
    3030  abstract class DataAdapterBase<AdapterT, ObjT, RowT>
    31     where AdapterT: new()
    32     where RowT: System.Data.DataRow
    33     where ObjT: IHiveObject, new() {
     31    where AdapterT : new()
     32    where RowT : System.Data.DataRow
     33    where ObjT : IHiveObject, new() {
    3434    protected AdapterT adapter =
    3535      new AdapterT();
     
    4646    protected abstract void UpdateRow(RowT row);
    4747
     48    [MethodImpl(MethodImplOptions.Synchronized)]
    4849    protected abstract IEnumerable<RowT> FindById(long id);
    4950
     51    [MethodImpl(MethodImplOptions.Synchronized)]
    5052    protected abstract IEnumerable<RowT> FindAll();
    5153    #endregion
     
    5355    protected delegate IEnumerable<RowT> Selector();
    5456
     57    [MethodImpl(MethodImplOptions.Synchronized)]
    5558    protected virtual RowT FindSingleRow(Selector selector) {
    5659      RowT row = default(RowT);
     
    7881    }
    7982
     83    [MethodImpl(MethodImplOptions.Synchronized)]
    8084    protected virtual ICollection<ObjT> FindMultiple(Selector selector) {
    8185      IEnumerable<RowT> found =
     
    149153  }
    150154}
     155
Note: See TracChangeset for help on using the changeset viewer.