[4424] | 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 |
|
---|
[3578] | 22 | using System.Data.Linq;
|
---|
[4710] | 23 | using HeuristicLab.Hive.Tracing;
|
---|
[2904] | 24 |
|
---|
| 25 | namespace HeuristicLab.Hive.Server.LINQDataAccess {
|
---|
[3011] | 26 | public abstract class BaseDao<TBusiness, TDatabaseEntity> {
|
---|
[4092] | 27 | private static ContextFactory contextFactory = new ContextFactory();
|
---|
| 28 |
|
---|
[2904] | 29 | public static HiveDataContext Context {
|
---|
| 30 | get {
|
---|
[4092] | 31 | return contextFactory.CurrentContext as HiveDataContext;
|
---|
[2904] | 32 | }
|
---|
| 33 | }
|
---|
[3011] | 34 |
|
---|
[4050] | 35 | protected void CommitChanges() {
|
---|
[3578] | 36 | try {
|
---|
| 37 | Context.SubmitChanges(ConflictMode.ContinueOnConflict);
|
---|
[4092] | 38 | } catch (ChangeConflictException e) {
|
---|
[3578] | 39 | Logger.Warn("Concurrency Exception! " + e.Message);
|
---|
[3931] | 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 | }
|
---|
[3578] | 48 | conflict.Resolve(RefreshMode.KeepChanges);
|
---|
| 49 | }
|
---|
[4423] | 50 | try {
|
---|
| 51 | Context.SubmitChanges();
|
---|
| 52 | }
|
---|
| 53 | catch {
|
---|
| 54 | Logger.Error("Could not resolve conflict!");
|
---|
| 55 | }
|
---|
[3578] | 56 | }
|
---|
| 57 | }
|
---|
| 58 |
|
---|
[3011] | 59 | public abstract TDatabaseEntity DtoToEntity(TBusiness source, TDatabaseEntity target);
|
---|
| 60 | public abstract TBusiness EntityToDto(TDatabaseEntity source, TBusiness target);
|
---|
| 61 |
|
---|
[2904] | 62 | }
|
---|
| 63 | }
|
---|