- Timestamp:
- 01/14/09 17:19:08 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.Hive.Server.ADODataAccess
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/CachedDataAdapter.cs
r1125 r1128 30 30 namespace HeuristicLab.Hive.Server.ADODataAccess { 31 31 abstract class CachedDataAdapter<AdapterT, ObjT, RowT, CacheT> : 32 DataAdapterBase<AdapterT, ObjT, RowT>, 32 DataAdapterBase<AdapterT, ObjT, RowT>, 33 33 ICachedDataAdapter 34 where CacheT : System.Data.TypedTableBase<RowT>, new()34 where CacheT : System.Data.TypedTableBase<RowT>, new() 35 35 where AdapterT : new() 36 36 where RowT : System.Data.DataRow 37 37 where ObjT : IHiveObject, new() { 38 protected CacheT cache = 38 protected CacheT cache = 39 39 new CacheT(); 40 41 protected IDictionary<long, DataTable> dataTable = 42 new Dictionary<long, DataTable>(); 40 43 41 44 protected ICollection<ICachedDataAdapter> parentAdapters = 42 45 new List<ICachedDataAdapter>(); 43 46 44 private DataTable temp = new DataTable();45 46 47 protected CachedDataAdapter() { 47 48 FillCache(); … … 51 52 } 52 53 53 protected virtual RowT FindSingleRow(Selector dbSelector, 54 [MethodImpl(MethodImplOptions.Synchronized)] 55 protected virtual RowT FindSingleRow(Selector dbSelector, 54 56 Selector cacheSelector) { 55 57 RowT row = … … 65 67 } 66 68 69 [MethodImpl(MethodImplOptions.Synchronized)] 67 70 protected virtual IEnumerable<RowT> FindMultipleRows(Selector dbSelector, 68 71 Selector cacheSelector) { … … 96 99 } 97 100 101 [MethodImpl(MethodImplOptions.Synchronized)] 98 102 protected virtual ICollection<ObjT> FindMultiple(Selector dbSelector, 99 103 Selector cacheSelector) { … … 124 128 protected abstract bool PutInCache(ObjT obj); 125 129 130 [MethodImpl(MethodImplOptions.Synchronized)] 126 131 protected abstract RowT FindCachedById(long id); 127 132 … … 136 141 137 142 [MethodImpl(MethodImplOptions.Synchronized)] 138 protected virtual void RemoveRowFromCache(RowT row) { 143 protected virtual void RemoveRowFromCache(RowT row) { 139 144 cache.Rows.Remove(row); 140 145 } … … 143 148 if (row == null) 144 149 return false; 145 else150 else 146 151 return FindCachedById((long)row[row.Table.PrimaryKey[0]]) != null; 147 152 } 148 153 154 [MethodImpl(MethodImplOptions.Synchronized)] 149 155 protected override RowT GetRowById(long id) { 150 156 RowT row = 151 157 FindCachedById(id); 152 153 if (row == null)158 159 if (row == null) 154 160 row = FindSingleRow( 155 161 delegate() { … … 163 169 public override void Update(ObjT obj) { 164 170 if (obj != null) { 165 RowT row = 171 RowT row = 166 172 GetRowById(obj.Id); 167 173 … … 182 188 if (!IsCached(row)) 183 189 UpdateRow(row); 184 190 185 191 if (IsCached(row) && 186 192 !PutInCache(obj)) { 187 193 //remove from cache 188 temp.ImportRow(row); 194 dataTable[obj.Id].ImportRow(row); 195 dataTable.Remove(obj.Id); 189 196 190 197 UpdateRow(row); … … 195 202 cache.ImportRow(row); 196 203 204 dataTable[obj.Id] = row.Table; 197 205 row.Table.Rows.Remove(row); 198 206 } … … 201 209 } 202 210 } 211 -
trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/DataAdapterBase.cs
r1125 r1128 29 29 namespace HeuristicLab.Hive.Server.ADODataAccess { 30 30 abstract class DataAdapterBase<AdapterT, ObjT, RowT> 31 where AdapterT : new()32 where RowT : System.Data.DataRow33 where ObjT : IHiveObject, new() {31 where AdapterT : new() 32 where RowT : System.Data.DataRow 33 where ObjT : IHiveObject, new() { 34 34 protected AdapterT adapter = 35 35 new AdapterT(); … … 46 46 protected abstract void UpdateRow(RowT row); 47 47 48 [MethodImpl(MethodImplOptions.Synchronized)] 48 49 protected abstract IEnumerable<RowT> FindById(long id); 49 50 51 [MethodImpl(MethodImplOptions.Synchronized)] 50 52 protected abstract IEnumerable<RowT> FindAll(); 51 53 #endregion … … 53 55 protected delegate IEnumerable<RowT> Selector(); 54 56 57 [MethodImpl(MethodImplOptions.Synchronized)] 55 58 protected virtual RowT FindSingleRow(Selector selector) { 56 59 RowT row = default(RowT); … … 78 81 } 79 82 83 [MethodImpl(MethodImplOptions.Synchronized)] 80 84 protected virtual ICollection<ObjT> FindMultiple(Selector selector) { 81 85 IEnumerable<RowT> found = … … 149 153 } 150 154 } 155
Note: See TracChangeset
for help on using the changeset viewer.