Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/27/09 14:04:47 (16 years ago)
Author:
svonolfe
Message:

Refactored DAL (now using GUIDs as IDs instead of longs) (#527)

Location:
trunk/sources/HeuristicLab.DataAccess.ADOHelper
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.DataAccess.ADOHelper/CachedDataAdapter.cs

    r1377 r1449  
    145145    protected abstract bool PutInCache(ObjT obj);
    146146
    147     protected abstract RowT FindCachedById(long id);
     147    protected abstract RowT FindCachedById(Guid id);
    148148
    149149    public void SyncWithDb() {
     
    169169        cacheLock.EnterReadLock();
    170170
    171         bool cached = FindCachedById((long)row[row.Table.PrimaryKey[0]]) != null;
     171        bool cached = FindCachedById((Guid)row[row.Table.PrimaryKey[0]]) != null;
    172172
    173173        cacheLock.ExitReadLock();
     
    177177    }
    178178
    179     protected override RowT GetRowById(long id) {
     179    protected override RowT GetRowById(Guid id) {
    180180      cacheLock.EnterReadLock();
    181181
     
    227227      if (obj != null) {
    228228        RowT row = null;
    229         long locked = default(long);
    230 
    231         if (obj.Id != default(long)) {
     229        Guid locked = Guid.Empty;
     230
     231        if (obj.Id != Guid.Empty) {
    232232          LockRow(obj.Id);
    233233          locked = obj.Id;
    234234
    235235          row = GetRowById(obj.Id);
     236        } else {
     237          obj.Id = Guid.NewGuid();
    236238        }
    237239
     
    241243          } else {
    242244            row = InsertNewRow(obj);
     245            UpdateRow(row);
    243246          }
    244 
    245           UpdateRow(row);
    246           obj.Id = (long)row[row.Table.PrimaryKey[0]];
    247         }
    248 
    249         if (locked == default(long)) {
     247        }
     248
     249        if (locked == Guid.Empty)
     250        {
    250251          LockRow(obj.Id);
    251252          locked = obj.Id;
  • trunk/sources/HeuristicLab.DataAccess.ADOHelper/DataAdapterBase.cs

    r1377 r1449  
    9292    protected abstract void UpdateRow(RowT row);
    9393
    94     protected abstract IEnumerable<RowT> FindById(long id);
     94    protected abstract IEnumerable<RowT> FindById(Guid id);
    9595
    9696    protected abstract IEnumerable<RowT> FindAll();
     
    154154    }
    155155
    156     protected virtual RowT GetRowById(long id) {
     156    protected virtual RowT GetRowById(Guid id) {
    157157      return FindSingleRow(
    158158        delegate() {
     
    164164      if (obj != null) {
    165165        RowT row = null;
    166         long locked = default(long);
    167        
    168         if (obj.Id != default(long)) {
    169            LockRow(obj.Id);
    170            locked = obj.Id;
    171 
    172            row = GetRowById(obj.Id);
    173         }         
     166        Guid locked = Guid.Empty;
     167
     168        if (obj.Id != Guid.Empty) {
     169          LockRow(obj.Id);
     170          locked = obj.Id;
     171
     172          row = GetRowById(obj.Id);
     173        } else {
     174          obj.Id = Guid.NewGuid();
     175        }
    174176
    175177        if (row == null) {
    176178          row = InsertNewRow(obj);
    177179          UpdateRow(row);
    178 
    179           obj.Id = (long)row[row.Table.PrimaryKey[0]];
    180         }
    181 
    182         if (locked == default(long)) {
     180        }
     181
     182        if (locked == Guid.Empty) {
    183183          LockRow(obj.Id);
    184184          locked = obj.Id;
     
    192192    }
    193193
    194     public virtual ObjT GetById(long id) {
     194    public virtual ObjT GetById(Guid id) {
    195195      return FindSingle(delegate() {
    196196        return FindById(id);
Note: See TracChangeset for help on using the changeset viewer.