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 | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Data.Linq;
|
---|
6 | using HeuristicLab.Tracing;
|
---|
7 |
|
---|
8 | namespace 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.