763955ff4a1852b368ad83e39018d9c2c83cbdf9
[mono.git] / mcs / class / System.Data / System.Data.OleDb / OleDbTransaction.cs
1 //
2 // System.Data.OleDb.OleDbTransaction
3 //
4 // Authors:
5 //   Rodrigo Moya (rodrigo@ximian.com)
6 //   Tim Coleman (tim@timcoleman.com)
7 //
8 // Copyright (C) Rodrigo Moya, 2002
9 // Copyright (C) Tim Coleman, 2002
10 //
11
12 using System.Data;
13 using System.Data.Common;
14
15 namespace System.Data.OleDb
16 {
17         public sealed class OleDbTransaction : MarshalByRefObject, IDbTransaction, IDisposable
18         {
19                 #region Fields
20
21                 OleDbConnection connection;
22                 IsolationLevel isolationLevel;
23                 IntPtr gdaTransaction;
24                 int depth;
25
26                 #endregion // Fields
27
28                 #region Constructors
29
30                 internal OleDbTransaction (OleDbConnection connection, int depth)
31                 {
32                         this.connection = connection;
33                         isolationLevel = IsolationLevel.ReadCommitted;
34
35                         gdaTransaction = libgda.gda_transaction_new (depth.ToString ());
36                         libgda.gda_connection_begin_transaction (connection.GdaConnection, gdaTransaction);
37                 }
38
39                 internal OleDbTransaction (OleDbConnection connection)
40                         : this (connection, 1)
41                 {
42                 }
43
44                 internal OleDbTransaction (OleDbConnection connection, int depth, IsolationLevel isolevel) 
45                         : this (connection, depth)
46                 {
47                         isolationLevel = isolevel;
48                 }
49
50                 internal OleDbTransaction (OleDbConnection connection, IsolationLevel isolevel) 
51                         : this (connection, 1, isolevel)
52                 {
53                 }
54
55
56                 #endregion // Constructors
57
58                 #region Properties
59
60                 public OleDbConnection Connection {
61                         get { return connection; }
62                 }
63
64                 public IsolationLevel IsolationLevel {
65                         get { return isolationLevel; }
66                 }
67
68                 IDbConnection IDbTransaction.Connection {
69                         get { return connection; }
70                 }
71
72                 #endregion // Properties
73
74                 #region Methods
75
76                 public OleDbTransaction Begin () 
77                 {
78                         return new OleDbTransaction (connection, depth + 1);
79                 }
80
81                 public OleDbTransaction Begin (IsolationLevel isolevel) 
82                 {
83                         return new OleDbTransaction (connection, depth + 1, isolevel);
84                 }
85
86                 public void Commit ()
87                 {
88                         if (!libgda.gda_connection_commit_transaction (connection.GdaConnection, gdaTransaction))
89                                 throw new InvalidOperationException ();
90                 }
91
92                 [MonoTODO]
93                 ~OleDbTransaction ()
94                 {
95                 }
96
97                 [MonoTODO]
98                 void IDisposable.Dispose ()
99                 {
100                         throw new NotImplementedException ();
101                 }
102
103                 public void Rollback ()
104                 {
105                         if (!libgda.gda_connection_rollback_transaction (connection.GdaConnection, gdaTransaction))
106                                 throw new InvalidOperationException ();
107                 }
108
109                 #endregion // Methods
110         }
111 }