Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1175 for trunk


Ignore:
Timestamp:
01/25/09 11:32:31 (16 years ago)
Author:
svonolfe
Message:

Refactored DAL, avoided possible race conditions (#372)

Location:
trunk/sources
Files:
1 added
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Contracts/BusinessObjects/ClientConfig.cs

    r995 r1175  
    2929
    3030  [DataContract]
    31   public class ClientConfig: IHiveObject {
    32     [DataMember]
    33     public long Id { get; set; }
     31  public class ClientConfig: HiveBaseObject {
    3432    [DataMember]
    3533    public String UpDownTimeCalendar { get; set; } // TODO define DataStructure
  • trunk/sources/HeuristicLab.Hive.Contracts/BusinessObjects/GrantedPermissions.cs

    r995 r1175  
    2929 
    3030  [DataContract]
    31   public class GrantedPermissions: IHiveObject {
    32     [DataMember]
    33     public long Id { get; set; }
     31  public class GrantedPermissions: HiveBaseObject {
    3432    [DataMember]
    3533    public Permission Permission { get; set; }
  • trunk/sources/HeuristicLab.Hive.Contracts/BusinessObjects/Job.cs

    r1168 r1175  
    2929
    3030  [DataContract]
    31   public class Job: IHiveObject {
    32     [DataMember]
    33     public long Id { get; set; }
     31  public class Job : HiveBaseObject {
    3432    [DataMember]
    3533    public State State { get; set; }
     
    5048    [DataMember]
    5149    public int Priority { get; set; }
    52 
    53     public override bool Equals(object obj) {
    54       if (obj is Job) {
    55         return (obj as Job).Id.Equals(Id);
    56       } else     
    57         return base.Equals(obj);
    58     }
    59 
    60     public override int GetHashCode() {
    61       return Id.GetHashCode();
    62     }
    6350  }
    6451}
  • trunk/sources/HeuristicLab.Hive.Contracts/BusinessObjects/JobResult.cs

    r1168 r1175  
    2929
    3030  [DataContract]
    31   public class JobResult: IHiveObject {
    32     [DataMember]
    33     public long Id { get; set; }
     31  public class JobResult: HiveBaseObject {
    3432    [DataMember]
    3533    public Job Job { get; set; }
  • trunk/sources/HeuristicLab.Hive.Contracts/BusinessObjects/Permission.cs

    r995 r1175  
    2929
    3030  [DataContract]
    31   public class Permission: IHiveObject {
    32     [DataMember]
    33     public long Id { get; set; }
     31  public class Permission: HiveBaseObject {
    3432    [DataMember]
    3533    public String Name { get; set; }
  • trunk/sources/HeuristicLab.Hive.Contracts/BusinessObjects/PermissionOwner.cs

    r995 r1175  
    2929
    3030  [DataContract]
    31   public class PermissionOwner: IHiveObject {
    32     [DataMember]
    33     public long Id { get; set; }
     31  public class PermissionOwner: HiveBaseObject {
    3432    [DataMember]
    3533    public string Name { get; set; }
    36 
    37     public override bool Equals(object obj) {
    38       if (obj is PermissionOwner)
    39         return this.Id.Equals(
    40           (obj as PermissionOwner).Id);
    41       else
    42         return base.Equals(obj);
    43     }
    44 
    45     public override int GetHashCode() {
    46       return this.Id.GetHashCode();
    47     }
    4834  }
    4935}
  • trunk/sources/HeuristicLab.Hive.Contracts/BusinessObjects/Resource.cs

    r995 r1175  
    2929
    3030  [DataContract]
    31   public class Resource: IHiveObject {
    32     [DataMember]
    33     public long Id { get; set; }
     31  public class Resource: HiveBaseObject {
    3432    [DataMember]
    3533    public string Name { get; set; }
    36 
    37     public override bool Equals(object obj) {
    38       if (obj is Resource)
    39         return (obj as Resource).Id.Equals(Id);
    40       else
    41         return base.Equals(obj);
    42     }
    43 
    44     public override int GetHashCode() {
    45       return Id.GetHashCode();
    46     }
    4734  }
    4835}
  • trunk/sources/HeuristicLab.Hive.Contracts/HeuristicLab.Hive.Contracts.csproj

    r1120 r1175  
    7474    <Compile Include="BusinessObjects\ClientGroup.cs" />
    7575    <Compile Include="BusinessObjects\HeartBeatData.cs" />
     76    <Compile Include="BusinessObjects\HiveBaseObject.cs" />
    7677    <Compile Include="BusinessObjects\IHiveObject.cs" />
    7778    <Compile Include="BusinessObjects\Job.cs" />
  • trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/CachedDataAdapter.cs

    r1166 r1175  
    227227    public override void Update(ObjT obj) {
    228228      if (obj != null) {
    229         RowT row =
    230           GetRowById(obj.Id);
     229        RowT row = null;
     230        long locked = default(long);
     231
     232        if (obj.Id != default(long)) {
     233          LockRow(obj.Id);
     234          locked = obj.Id;
     235
     236          row = GetRowById(obj.Id);
     237        }
    231238
    232239        if (row == null) {
     
    238245
    239246          UpdateRow(row);
    240         }
    241 
    242         obj.Id = (long)row[row.Table.PrimaryKey[0]];
    243         LockRow(obj.Id);
     247          obj.Id = (long)row[row.Table.PrimaryKey[0]];
     248        }
     249
     250        if (locked == default(long)) {
     251          LockRow(obj.Id);
     252          locked = obj.Id;
     253        }
    244254
    245255        ConvertObj(obj, row);
     
    256266        }
    257267
    258         UnlockRow(obj.Id);
     268        UnlockRow(locked);
    259269      }
    260270    }
  • trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/ClientAdapter.cs

    r1166 r1175  
    2727using HeuristicLab.Hive.Contracts.BusinessObjects;
    2828using System.Linq.Expressions;
    29 using System.Runtime.CompilerServices;
    3029
    3130namespace HeuristicLab.Hive.Server.ADODataAccess {
     
    7978
    8079    private void Preprocess(ClientInfo client) {
    81       if (client != null) {
    82         if (client.Id == default(long)) {
    83           ClientInfo found = GetById(client.ClientId);
    84           if (found != null)
    85             client.Id = found.Id;
    86         }
     80      if (client != null && client.Id == default(long)) {
     81        ClientInfo found = GetById(client.ClientId);
     82        if (found != null)
     83          client.Id = found.Id;
    8784      }
    8885    }
     
    215212
    216213    #region IClientAdapter Members
    217     [MethodImpl(MethodImplOptions.Synchronized)]
    218214    public override void Update(ClientInfo client) {
    219215      if (client != null) {
     216        Guid locked = Guid.Empty;
     217        if (client.ClientId != Guid.Empty) {
     218          LockRow(client.ClientId);
     219          locked = client.ClientId;
     220        }
     221
    220222        Preprocess(client);
    221223
     
    223225
    224226        base.Update(client);
     227
     228        if (locked != Guid.Empty) {
     229          UnlockRow(locked);
     230        }
    225231      }
    226232    }
     
    248254    }
    249255
    250     [MethodImpl(MethodImplOptions.Synchronized)]
    251     public override bool Delete(ClientInfo client) {     
     256    public override bool Delete(ClientInfo client) {
     257      bool success = false;
     258      Guid locked = Guid.Empty;
     259     
    252260      if (client != null) {
     261        if (client.ClientId != Guid.Empty) {
     262          LockRow(client.ClientId);
     263          locked = client.ClientId;
     264        }
     265
    253266        Preprocess(client);
    254267
     
    264277          }
    265278
    266           return base.Delete(client) &&
     279          success = base.Delete(client) &&
    267280            ResAdapter.Delete(client);
    268281        }
    269282      }
    270283
    271       return false;
     284      if (locked != Guid.Empty) {
     285        UnlockRow(locked);
     286      }
     287
     288      return success;
    272289    }
    273290
  • trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/ClientGroupAdapter.cs

    r1166 r1175  
    2727using HeuristicLab.Hive.Server.Core.InternalInterfaces.DataAccess;
    2828using HeuristicLab.Hive.Contracts.BusinessObjects;
    29 using System.Runtime.CompilerServices;
    3029using System.Data;
    3130
     
    233232
    234233    #region IClientGroupAdapter Members
    235     [MethodImpl(MethodImplOptions.Synchronized)]
    236234    public override void Update(ClientGroup group) {
    237235      if (group != null) {
     
    273271    }
    274272
    275     [MethodImpl(MethodImplOptions.Synchronized)]
    276273    public override bool Delete(ClientGroup group) {
    277274      if (group != null) {
  • trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/DataAdapterBase.cs

    r1134 r1175  
    3737      new Mutex();
    3838
    39     private static IDictionary<long, Mutex> lockers =
    40       new Dictionary<long, Mutex>();
    41 
    42     private static IDictionary<long, int> lockCount =
    43       new Dictionary<long, int>();
    44 
    45     protected void LockRow(long id) {
     39    private static IDictionary<object, Mutex> lockers =
     40      new Dictionary<object, Mutex>();
     41
     42    private static IDictionary<object, int> lockCount =
     43      new Dictionary<object, int>();
     44
     45    protected void LockRow(object id) {
    4646      Mutex rowLock = null;
    4747
     
    6262    }
    6363
    64     protected void UnlockRow(long id) {
     64    protected void UnlockRow(object id) {
    6565      Mutex rowLock = lockers[id];
    6666      rowLock.ReleaseMutex();
     
    163163    public virtual void Update(ObjT obj) {
    164164      if (obj != null) {
    165         RowT row =
    166           GetRowById(obj.Id);
     165        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        }         
    167174
    168175        if (row == null) {
    169176          row = InsertNewRow(obj);
    170177          UpdateRow(row);
     178
     179          obj.Id = (long)row[row.Table.PrimaryKey[0]];
    171180        }
    172181
    173         obj.Id = (long)row[row.Table.PrimaryKey[0]];
    174         LockRow(obj.Id);
     182        if (locked == default(long)) {
     183          LockRow(obj.Id);
     184          locked = obj.Id;
     185        }
    175186
    176187        ConvertObj(obj, row);
    177188        UpdateRow(row);
    178189
    179         UnlockRow(obj.Id);
     190        UnlockRow(locked);
    180191      }
    181192    }
  • trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/JobAdapter.cs

    r1169 r1175  
    2727using HeuristicLab.Hive.Contracts.BusinessObjects;
    2828using System.Linq.Expressions;
    29 using System.Runtime.CompilerServices;
    3029
    3130namespace HeuristicLab.Hive.Server.ADODataAccess {
     
    119118          job.DateCalculated = DateTime.MinValue;
    120119
    121         job.Priority = row.Priority;
     120        if (!row.IsPriorityNull())
     121          job.Priority = row.Priority;
     122        else
     123          job.Priority = default(int);
    122124
    123125        return job;
     
    332334    }
    333335
    334     [MethodImpl(MethodImplOptions.Synchronized)]
    335336    public override bool Delete(Job job) {
    336337      if (job != null) {
  • trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/PermissionOwnerAdapter.cs

    r1166 r1175  
    2727using HeuristicLab.Hive.Server.Core.InternalInterfaces.DataAccess;
    2828using HeuristicLab.Hive.Contracts.BusinessObjects;
    29 using System.Runtime.CompilerServices;
    3029
    3130namespace HeuristicLab.Hive.Server.ADODataAccess {
  • trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/ResourceAdapter.cs

    r1166 r1175  
    2626using HeuristicLab.Hive.Server.Core.InternalInterfaces.DataAccess;
    2727using HeuristicLab.Hive.Contracts.BusinessObjects;
    28 using System.Runtime.CompilerServices;
    2928
    3029namespace HeuristicLab.Hive.Server.ADODataAccess {
  • trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/UserAdapter.cs

    r1166 r1175  
    2727using HeuristicLab.Hive.Server.Core.InternalInterfaces.DataAccess;
    2828using HeuristicLab.Hive.Contracts.BusinessObjects;
    29 using System.Runtime.CompilerServices;
    3029
    3130namespace HeuristicLab.Hive.Server.ADODataAccess {
     
    136135    #region IUserAdapter Members
    137136
    138     [MethodImpl(MethodImplOptions.Synchronized)]
    139137    public override void Update(User user) {
    140138      if (user != null) {
     
    156154    }
    157155
    158     [MethodImpl(MethodImplOptions.Synchronized)]
    159156    public override bool Delete(User user) {
    160157      if (user != null) {
  • trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/UserGroupAdapter.cs

    r1166 r1175  
    2727using HeuristicLab.Hive.Server.Core.InternalInterfaces.DataAccess;
    2828using HeuristicLab.Hive.Contracts.BusinessObjects;
    29 using System.Runtime.CompilerServices;
    3029using System.Data;
    3130
     
    234233
    235234    #region IUserGroupAdapter Members
    236     [MethodImpl(MethodImplOptions.Synchronized)]
    237235    public override void Update(UserGroup group) {
    238236      if (group != null) {
     
    273271    }
    274272
    275     [MethodImpl(MethodImplOptions.Synchronized)]
    276273    public override bool Delete(UserGroup group) {
    277274      if (group != null) {
  • trunk/sources/HeuristicLab.Hive.Server.Core/InternalInterfaces/DataAccess/IDataAdapter.cs

    r1005 r1175  
    2424using System.Linq;
    2525using System.Text;
     26using HeuristicLab.Hive.Contracts.BusinessObjects;
    2627
    2728namespace HeuristicLab.Hive.Server.Core.InternalInterfaces.DataAccess {
    28   public interface IDataAdapter<ObjT> {
     29  public interface IDataAdapter<ObjT>
     30    where ObjT: IHiveObject
     31  {
    2932    /// <summary>
    3033    /// Save or update the object
Note: See TracChangeset for help on using the changeset viewer.