New test.
[mono.git] / mcs / class / System.Data.OracleClient / System.Data.OracleClient.Oci / OciServerHandle.cs
1 // 
2 // OciServerHandle.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 // 
17
18 using System;
19 using System.Runtime.InteropServices;
20
21 namespace System.Data.OracleClient.Oci {
22         internal sealed class OciServerHandle : OciHandle, IDisposable
23         {
24                 #region Fields
25
26                 bool disposed = false;
27                 bool attached = false;
28                 OciErrorHandle errorHandle;
29
30                 #endregion // Fields
31
32                 #region Constructors
33
34                 public OciServerHandle (OciHandle parent, IntPtr newHandle)
35                         : base (OciHandleType.Server, parent, newHandle)
36                 {
37                 }
38
39                 #endregion // Constructors
40
41                 #region Methods
42
43                 public bool Attach (string tnsname, OciErrorHandle error)
44                 {
45                         errorHandle = error;
46
47                         int status = OciCalls.OCIServerAttach (this, error, tnsname, tnsname.Length, 0);
48
49                         if (status != 0) {
50                                 OciErrorInfo info = errorHandle.HandleError ();
51                                 throw new OracleException (info.ErrorCode, info.ErrorMessage);
52                         }
53
54                         attached = true;
55                         return attached;
56                 }
57
58                 public void Detach (OciErrorHandle error)
59                 {
60                         if (!attached) 
61                                 return;
62
63                         int status = OciCalls.OCIServerDetach (this, error, 0);
64
65                         if (status != 0) {
66                                 OciErrorInfo info = errorHandle.HandleError ();
67                                 throw new OracleException (info.ErrorCode, info.ErrorMessage);
68                         }
69
70                         attached = false;
71                 }
72
73                 protected override void Dispose (bool disposing)
74                 {
75                         if (!disposed) {
76                                 try {
77                                         //Detach (errorHandle);
78                                         disposed = true;
79                                 } finally {
80                                         base.Dispose (disposing);
81                                 }
82                         }
83                 }
84
85                 #endregion // Methods
86         }
87 }