2002-10-31 Tim Coleman (tim@timcoleman.com)
[mono.git] / mcs / class / Mono.Data.TdsClient / Mono.Data.TdsClient / TdsTransaction.cs
1 //
2 // Mono.Data.TdsClient.TdsTransaction.cs
3 //
4 // Author:
5 //   Tim Coleman (tim@timcoleman.com)
6 //
7 // Copyright (C) 2002 Tim Coleman
8 //
9
10 using Mono.Data.TdsClient.Internal;
11 using System;
12 using System.ComponentModel;
13 using System.Data;
14
15 namespace Mono.Data.TdsClient {
16         public class TdsTransaction : Component, ICloneable, IDbTransaction
17         {
18                 #region Fields
19
20                 TdsConnection connection;
21                 IsolationLevel isolationLevel;
22                 bool open;
23
24                 #endregion // Fields
25
26                 #region Constructors
27
28                 internal TdsTransaction (TdsConnection connection, IsolationLevel isolevel)
29                 {
30                         this.connection = connection;
31                         this.isolationLevel = isolevel;
32
33                         connection.Tds.ExecuteNonQuery ("BEGIN TRAN");
34                         open = true;
35                 }
36
37                 #endregion // Constructors
38
39                 #region Properties
40
41                 TdsConnection Connection {
42                         get { return connection; }
43                 }
44
45                 IDbConnection IDbTransaction.Connection {
46                         get { return Connection; }
47                 }
48
49                 IsolationLevel IDbTransaction.IsolationLevel {
50                         get { return isolationLevel; }
51                 }
52
53                 public bool Open {      
54                         get { return open; }
55                 }
56
57                 #endregion // Properties
58
59                 #region Methods
60
61                 public void Commit ()
62                 {
63                         if (!open)
64                                 throw new InvalidOperationException ("This TdsTransaction has completed; it is no longer usable.");
65                         connection.Tds.ExecuteNonQuery ("IF @@TRANCOUNT>0 COMMIT TRAN");
66                         open = false;
67                 }
68
69                 object ICloneable.Clone()
70                 {
71                         throw new NotImplementedException ();
72                 }
73
74                 public void Rollback ()
75                 {
76                         if (!open)
77                                 throw new InvalidOperationException ("This TdsTransaction has completed; it is no longer usable.");
78                         connection.Tds.ExecuteNonQuery ("IF @@TRANCOUNT>0 ROLLBACK TRAN");
79                         open = false;
80                 }
81
82                 public void Save (string savePointName)
83                 {
84                         if (!open)
85                                 throw new InvalidOperationException ("This TdsTransaction has completed; it is no longer usable.");
86                         connection.Tds.ExecuteNonQuery (String.Format ("SAVE TRAN {0}", savePointName));
87                 }
88
89                 #endregion // Methods
90         }
91 }