2010-06-21 Marek Habersack <mhabersack@novell.com>
[mcs.git] / class / System.Data.OracleClient / System.Data.OracleClient.Oci / OciTransactionHandle.cs
blob4308a38988308f5fe41e3eef78cfa3e65e83f8c0
1 //
2 // OciTransactionHandle.cs
3 //
4 // Part of managed C#/.NET library System.Data.OracleClient.dll
5 //
6 // Part of the Mono class libraries at
7 // mcs/class/System.Data.OracleClient/System.Data.OracleClient.Oci
8 //
9 // Assembly: System.Data.OracleClient.dll
10 // Namespace: System.Data.OracleClient.Oci
11 //
12 // Author:
13 // Tim Coleman <tim@timcoleman.com>
14 //
15 // Copyright (C) Tim Coleman, 2003
16 //
18 using System;
19 using System.Runtime.InteropServices;
21 namespace System.Data.OracleClient.Oci {
22 internal sealed class OciTransactionHandle : OciHandle, IDisposable
24 #region Fields
26 bool disposed = false;
27 OciErrorHandle errorHandle;
28 OciServiceHandle serviceHandle;
30 #endregion // Fields
32 #region Constructors
34 public OciTransactionHandle (OciHandle parent, IntPtr handle)
35 : base (OciHandleType.Transaction, parent, handle)
39 #endregion // Constructors
41 #region Properties
43 public OciErrorHandle ErrorHandle {
44 get { return errorHandle; }
45 set { errorHandle = value; }
48 public OciServiceHandle Service {
49 get { return serviceHandle; }
50 set { serviceHandle = value; }
53 #endregion // Properties
55 #region Methods
57 public void AttachToServiceContext ()
59 int status = 0;
60 status = OciCalls.OCIAttrSet (Service,
61 OciHandleType.Service,
62 this,
64 OciAttributeType.Transaction,
65 ErrorHandle);
66 if (status != 0) {
67 OciErrorInfo info = ErrorHandle.HandleError ();
68 throw new OracleException (info.ErrorCode, info.ErrorMessage);
72 public void DetachFromServiceContext ()
74 int status = 0;
75 status = OciCalls.OCIAttrSet (Service,
76 OciHandleType.Service,
77 IntPtr.Zero,
79 OciAttributeType.Transaction,
80 ErrorHandle);
81 if (status != 0)
83 OciErrorInfo info = ErrorHandle.HandleError ();
84 throw new OracleException (info.ErrorCode, info.ErrorMessage);
88 public void Begin ()
90 int status = 0;
92 AttachToServiceContext ();
94 status = OciCalls.OCITransStart (Service,
95 ErrorHandle,
96 60,
97 OciTransactionFlags.New);
99 if (status != 0) {
100 OciErrorInfo info = ErrorHandle.HandleError ();
101 throw new OracleException (info.ErrorCode, info.ErrorMessage);
105 public void Commit ()
107 int status = 0;
108 AttachToServiceContext ();
109 try {
110 status = OciCalls.OCITransCommit (Service, ErrorHandle, 0);
112 if (status != 0)
114 OciErrorInfo info = ErrorHandle.HandleError ();
115 throw new OracleException (info.ErrorCode, info.ErrorMessage);
118 finally {
119 DetachFromServiceContext ();
123 protected override void Dispose (bool disposing)
125 if (!disposed) {
126 disposed = true;
127 base.Dispose (disposing);
131 public void Rollback ()
133 try {
134 int status = 0;
135 AttachToServiceContext ();
136 status = OciCalls.OCITransRollback (Service, ErrorHandle, 0);
138 if (status != 0) {
139 OciErrorInfo info = ErrorHandle.HandleError ();
140 throw new OracleException (info.ErrorCode, info.ErrorMessage);
143 finally {
144 DetachFromServiceContext ();
148 #endregion // Methods