Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/BaseDao.cs @ 4092

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

replaced transaction- and context management from Spring-advice by custom context management (see ContextFactory) (#1098)

File size: 1.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Data.Linq;
6using HeuristicLab.Tracing;
7
8namespace HeuristicLab.Hive.Server.LINQDataAccess {
9  public abstract class BaseDao<TBusiness, TDatabaseEntity> {
10    private static ContextFactory contextFactory = new ContextFactory();
11
12    public static HiveDataContext Context {
13      get {
14        return contextFactory.CurrentContext as HiveDataContext;
15      }
16    }
17
18    protected void CommitChanges() {     
19      try {
20        Context.SubmitChanges(ConflictMode.ContinueOnConflict);
21      } catch (ChangeConflictException e) {
22        Logger.Warn("Concurrency Exception! " + e.Message);
23        foreach (ObjectChangeConflict conflict in Context.ChangeConflicts) {
24          Logger.Info("Conflicted: ");
25          foreach (MemberChangeConflict memberChangeConflict in conflict.MemberConflicts) {
26            Logger.Info("    Member in Conflict: " + memberChangeConflict.Member.Name);
27            Logger.Info("    Database Value: " + memberChangeConflict.DatabaseValue);
28            Logger.Info("    Original value: " + memberChangeConflict.OriginalValue);
29            Logger.Info("    Current value: " + memberChangeConflict.CurrentValue);             
30          }
31          conflict.Resolve(RefreshMode.KeepChanges);
32        }
33        //next round!
34        CommitChanges();
35        //Context.SubmitChanges(ConflictMode.FailOnFirstConflict);
36      }
37    }
38
39    public abstract TDatabaseEntity DtoToEntity(TBusiness source, TDatabaseEntity target);
40    public abstract TBusiness EntityToDto(TDatabaseEntity source, TBusiness target);
41
42  }
43}
Note: See TracBrowser for help on using the repository browser.