Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.DataAccess.ADOHelper/3.2/Transaction.cs @ 2036

Last change on this file since 2036 was 1529, checked in by gkronber, 16 years ago

Moved source files of plugins AdvancedOptimizationFrontEnd ... Grid into version-specific sub-folders. #576

File size: 2.6 KB
RevLine 
[1468]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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.Collections.Generic;
24using System.Linq;
25using System.Text;
26using HeuristicLab.DataAccess.Interfaces;
27using System.Data;
28using System.Data.Common;
29
30namespace HeuristicLab.DataAccess.ADOHelper {
31  class Transaction: ITransaction {
32    private DbTransaction transaction;
33
[1488]34    private Session session;
[1468]35
[1488]36    public Transaction(Session session) {
37      this.session = session;
[1468]38    }
39
40    public DbConnection Connection {
41      set {
42        if (value != null &&
43          (transaction == null ||
[1496]44           !(transaction.Connection != null &&
[1468]45             transaction.Connection.Equals(value)))) {
[1496]46          if (value.State != System.Data.ConnectionState.Open)
47            value.Open();
[1468]48
[1516]49          transaction = value.BeginTransaction(IsolationLevel.ReadCommitted);
[1468]50        }
51      }
52    }
53
[1496]54    #region ITransaction Members
[1468]55    public void Commit() {
[1496]56      this.session.CheckThread();
57
[1468]58      if (transaction != null) {
59        DbConnection conn =
60          transaction.Connection;
61
62        transaction.Commit();
63
[1488]64        transaction = null;
65        session.DetachTrasaction();
66
[1468]67        if (conn != null &&
68            conn.State == System.Data.ConnectionState.Open)
69          conn.Close();
70      }
71    }
72
73    public void Rollback() {
[1496]74      this.session.CheckThread();
75
[1488]76      if (transaction != null) {
77        DbConnection conn =
78            transaction.Connection;
[1468]79
[1488]80        transaction.Rollback();
[1468]81
[1488]82        transaction = null;
83        session.DetachTrasaction();
84
85        if (conn != null &&
86            conn.State == System.Data.ConnectionState.Open)
87          conn.Close();
88      }
[1468]89    }
90
91    public object InnerTransaction {
92      get {
[1496]93        this.session.CheckThread();
94
[1468]95        return transaction;
96      }
97    }
98
99    #endregion
100  }
101}
Note: See TracBrowser for help on using the repository browser.