Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive.ExperimentManager/HeuristicLab.Hive.Server.LINQDataAccess/3.3/BaseDao.cs @ 4792

Last change on this file since 4792 was 4710, checked in by cneumuel, 14 years ago

#1254

  • enabled full IIS7 compatibility
  • removed dependency to HeuristicLab.Tracing
  • changed server-side logging to wcf-tracing (needs to be enhanced to trace job-lifecycle)
File size: 2.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Data.Linq;
23using HeuristicLab.Hive.Tracing;
24
25namespace HeuristicLab.Hive.Server.LINQDataAccess {
26  public abstract class BaseDao<TBusiness, TDatabaseEntity> {
27    private static ContextFactory contextFactory = new ContextFactory();
28
29    public static HiveDataContext Context {
30      get {
31        return contextFactory.CurrentContext as HiveDataContext;
32      }
33    }
34
35    protected void CommitChanges() {     
36      try {
37        Context.SubmitChanges(ConflictMode.ContinueOnConflict);
38      } catch (ChangeConflictException e) {
39        Logger.Warn("Concurrency Exception! " + e.Message);
40        foreach (ObjectChangeConflict conflict in Context.ChangeConflicts) {
41          Logger.Info("Conflicted: ");
42          foreach (MemberChangeConflict memberChangeConflict in conflict.MemberConflicts) {
43            Logger.Info("    Member in Conflict: " + memberChangeConflict.Member.Name);
44            Logger.Info("    Database Value: " + memberChangeConflict.DatabaseValue);
45            Logger.Info("    Original value: " + memberChangeConflict.OriginalValue);
46            Logger.Info("    Current value: " + memberChangeConflict.CurrentValue);             
47          }
48          conflict.Resolve(RefreshMode.KeepChanges);
49        }
50        try {
51          Context.SubmitChanges();
52        }
53        catch {
54          Logger.Error("Could not resolve conflict!");
55        }
56      }
57    }
58
59    public abstract TDatabaseEntity DtoToEntity(TBusiness source, TDatabaseEntity target);
60    public abstract TBusiness EntityToDto(TDatabaseEntity source, TBusiness target);
61
62  }
63}
Note: See TracBrowser for help on using the repository browser.