Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Manager/PersistenceManager.cs @ 12691

Last change on this file since 12691 was 12691, checked in by dglaser, 9 years ago

#2388:

HeuristicLab.Services.Access:
HeuristicLab.Services.Access.DataAccess:

  • Changed connection strings and certificates for local usage

HeuristicLab.Services.Hive.DataAccess:

  • Added compiled queries for frequently used queries
  • Integrated string queries from OptimizedHiveDao

HeuristicLab.Services.Hive:

  • Added NewHeartbeatManager.cs
  • Added NewRoundRobinTaskScheduler.cs
  • Added PerformanceLogger
  • Updated AuthoriziationManager
  • Updated NewHiveService
    • Added Regions
    • Implemented missing methods
    • Improved performance of several queries

HeuristicLab.Services.WebApp.Status:

  • Fixed a bug which caused an error when calculating the average waiting time.
File size: 7.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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;
23using System.Data.Linq;
24using System.Transactions;
25using HeuristicLab.Services.Hive.DataAccess.Daos;
26using HeuristicLab.Services.Hive.DataAccess.Daos.HiveStatistics;
27using HeuristicLab.Services.Hive.DataAccess.Interfaces;
28
29namespace HeuristicLab.Services.Hive.DataAccess.Manager {
30  public class PersistenceManager : IPersistenceManager {
31    private readonly DataContext dataContext;
32    public DataContext DataContext {
33      get { return dataContext; }
34    }
35
36    #region Hive daos
37
38    private AssignedResourceDao assignedResourceDao;
39    public AssignedResourceDao AssignedResourceDao {
40      get { return assignedResourceDao ?? (assignedResourceDao = new AssignedResourceDao(dataContext)); }
41    }
42
43    private DowntimeDao downtimeDao;
44    public DowntimeDao DowntimeDao {
45      get { return downtimeDao ?? (downtimeDao = new DowntimeDao(dataContext)); }
46    }
47
48    private JobDao jobDao;
49    public JobDao JobDao {
50      get { return jobDao ?? (jobDao = new JobDao(dataContext)); }
51    }
52
53    private JobPermissionDao jobPermissionDao;
54    public JobPermissionDao JobPermissionDao {
55      get { return jobPermissionDao ?? (jobPermissionDao = new JobPermissionDao(dataContext)); }
56    }
57
58    private LifecycleDao lifecycleDao;
59    public LifecycleDao LifecycleDao {
60      get { return lifecycleDao ?? (lifecycleDao = new LifecycleDao(dataContext)); }
61    }
62
63    private PluginDao pluginDao;
64    public PluginDao PluginDao {
65      get { return pluginDao ?? (pluginDao = new PluginDao(dataContext)); }
66    }
67
68    private PluginDataDao pluginDataDao;
69    public PluginDataDao PluginDataDao {
70      get { return pluginDataDao ?? (pluginDataDao = new PluginDataDao(dataContext)); }
71    }
72
73    private RequiredPluginDao requiredPluginDao;
74    public RequiredPluginDao RequiredPluginDao {
75      get { return requiredPluginDao ?? (requiredPluginDao = new RequiredPluginDao(dataContext)); }
76    }
77
78    private ResourceDao resourceDao;
79    public ResourceDao ResourceDao {
80      get { return resourceDao ?? (resourceDao = new ResourceDao(dataContext)); }
81    }
82
83    private ResourcePermissionDao resourcePermissionDao;
84    public ResourcePermissionDao ResourcePermissionDao {
85      get { return resourcePermissionDao ?? (resourcePermissionDao = new ResourcePermissionDao(dataContext)); }
86    }
87
88    private SlaveDao slaveDao;
89    public SlaveDao SlaveDao {
90      get { return slaveDao ?? (slaveDao = new SlaveDao(dataContext)); }
91    }
92
93    private SlaveGroupDao slaveGroupDao;
94    public SlaveGroupDao SlaveGroupDao {
95      get { return slaveGroupDao ?? (slaveGroupDao = new SlaveGroupDao(dataContext)); }
96    }
97
98    private StateLogDao stateLogDao;
99    public StateLogDao StateLogDao {
100      get { return stateLogDao ?? (stateLogDao = new StateLogDao(dataContext)); }
101    }
102
103    private TaskDao taskDao;
104    public TaskDao TaskDao {
105      get { return taskDao ?? (taskDao = new TaskDao(dataContext)); }
106    }
107
108    private TaskDataDao taskDataDao;
109    public TaskDataDao TaskDataDao {
110      get { return taskDataDao ?? (taskDataDao = new TaskDataDao(dataContext)); }
111    }
112
113    private UserPriorityDao userPriorityDao;
114    public UserPriorityDao UserPriorityDao {
115      get { return userPriorityDao ?? (userPriorityDao = new UserPriorityDao(dataContext)); }
116    }
117    #endregion
118
119    #region HiveStatistics daos
120
121    private DimClientDao dimClientDao;
122    public DimClientDao DimClientDao {
123      get { return dimClientDao ?? (dimClientDao = new DimClientDao(dataContext)); }
124    }
125
126    private DimJobDao dimJobDao;
127    public DimJobDao DimJobDao {
128      get { return dimJobDao ?? (dimJobDao = new DimJobDao(dataContext)); }
129    }
130
131    private DimTimeDao dimTimeDao;
132    public DimTimeDao DimTimeDao {
133      get { return dimTimeDao ?? (dimTimeDao = new DimTimeDao(dataContext)); }
134    }
135
136    private DimUserDao dimUserDao;
137    public DimUserDao DimUserDao {
138      get { return dimUserDao ?? (dimUserDao = new DimUserDao(dataContext)); }
139    }
140
141    private FactClientInfoDao factClientInfoDao;
142    public FactClientInfoDao FactClientInfoDao {
143      get { return factClientInfoDao ?? (factClientInfoDao = new FactClientInfoDao(dataContext)); }
144    }
145
146    private FactTaskDao factTaskDao;
147    public FactTaskDao FactTaskDao {
148      get { return factTaskDao ?? (factTaskDao = new FactTaskDao(dataContext)); }
149    }
150    #endregion
151
152    public PersistenceManager(bool longRunning = false) {
153      var context = new HiveDataContext(Settings.Default.HeuristicLab_Hive_LinqConnectionString);
154      if (longRunning) context.CommandTimeout = (int)Settings.Default.LongRunningDatabaseCommandTimeout.TotalSeconds;
155      dataContext = context;
156    }
157
158    public PersistenceManager(DataContext dataContext) {
159      this.dataContext = dataContext;
160    }
161
162    #region Transaction management
163    public void UseTransaction(Action call, bool repeatableRead = false, bool longRunning = false) {
164      UseTransaction<object>(() => {
165        call();
166        return null;
167      });
168    }
169
170    public T UseTransaction<T>(Func<T> call, bool repeatableRead = false, bool longRunning = false) {
171      int n = 10;
172      while (n > 0) {
173        TransactionScope transaction = CreateTransaction(repeatableRead, longRunning);
174        try {
175          T result = call();
176          transaction.Complete();
177          return result;
178        }
179        catch (System.Data.SqlClient.SqlException e) {
180          n--; // probably deadlock situation, let it roll back and repeat the transaction n times
181          LogFactory.GetLogger(typeof(TransactionManager).Namespace).Log(string.Format("Exception occured, repeating transaction {0} more times. Details: {1}", n, e.ToString()));
182          if (n <= 0) throw;
183        }
184        finally {
185          transaction.Dispose();
186        }
187      }
188      throw new Exception("Transaction couldn't be completed.");
189    }
190
191    private static TransactionScope CreateTransaction(bool repeatableRead, bool longRunning) {
192      var options = new TransactionOptions {
193        IsolationLevel = repeatableRead ? IsolationLevel.RepeatableRead : IsolationLevel.ReadUncommitted
194      };
195      if (longRunning) {
196        options.Timeout = Settings.Default.LongRunningDatabaseCommandTimeout;
197      }
198      return new TransactionScope(TransactionScopeOption.Required, options);
199    }
200    #endregion
201
202    public void SubmitChanges() {
203      if (dataContext != null) {
204        dataContext.SubmitChanges();
205      }
206    }
207
208    public void Dispose() {
209      //if (dataContext != null) {
210      //  dataContext.Dispose();
211      //}
212    }
213  }
214}
Note: See TracBrowser for help on using the repository browser.