OciTransactionHandle.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 <[email protected]>
  14. //
  15. // Copyright (C) Tim Coleman, 2003
  16. //
  17. using System;
  18. using System.Runtime.InteropServices;
  19. namespace System.Data.OracleClient.Oci {
  20. internal sealed class OciTransactionHandle : OciHandle, IOciHandle, IDisposable
  21. {
  22. #region Fields
  23. OciErrorHandle errorHandle;
  24. OciServiceHandle serviceHandle;
  25. #endregion // Fields
  26. #region Constructors
  27. public OciTransactionHandle (OciEnvironmentHandle environment, IntPtr handle)
  28. : base (OciHandleType.Transaction, environment, handle)
  29. {
  30. }
  31. #endregion // Constructors
  32. #region Properties
  33. public OciErrorHandle ErrorHandle {
  34. get { return errorHandle; }
  35. set { errorHandle = value; }
  36. }
  37. public OciServiceHandle Service {
  38. get { return serviceHandle; }
  39. set { serviceHandle = value; }
  40. }
  41. #endregion // Properties
  42. #region Methods
  43. [DllImport ("oci")]
  44. public static extern int OCITransCommit (IntPtr svchp,
  45. IntPtr errhp,
  46. uint flags);
  47. [DllImport ("oci")]
  48. public static extern int OCITransRollback (IntPtr svchp,
  49. IntPtr errhp,
  50. uint flags);
  51. [DllImport ("oci")]
  52. public static extern int OCITransStart (IntPtr svchp,
  53. IntPtr errhp,
  54. uint timeout,
  55. [MarshalAs (UnmanagedType.U4)] OciTransactionFlags flags);
  56. public void AttachToServiceContext ()
  57. {
  58. int status = 0;
  59. status = OciGlue.OCIAttrSet (Service.Handle,
  60. OciHandleType.Service,
  61. Handle,
  62. 0,
  63. OciAttributeType.Transaction,
  64. ErrorHandle.Handle);
  65. if (status != 0) {
  66. OciErrorInfo info = ErrorHandle.HandleError ();
  67. throw new OracleException (info.ErrorCode, info.ErrorMessage);
  68. }
  69. }
  70. public void Begin ()
  71. {
  72. int status = 0;
  73. AttachToServiceContext ();
  74. status = OCITransStart (Service.Handle,
  75. ErrorHandle.Handle,
  76. 60,
  77. OciTransactionFlags.New);
  78. if (status != 0) {
  79. OciErrorInfo info = ErrorHandle.HandleError ();
  80. throw new OracleException (info.ErrorCode, info.ErrorMessage);
  81. }
  82. }
  83. public void Commit ()
  84. {
  85. int status = 0;
  86. AttachToServiceContext ();
  87. status = OCITransCommit (Service.Handle,
  88. ErrorHandle.Handle,
  89. 0);
  90. if (status != 0) {
  91. OciErrorInfo info = ErrorHandle.HandleError ();
  92. throw new OracleException (info.ErrorCode, info.ErrorMessage);
  93. }
  94. }
  95. public void Dispose ()
  96. {
  97. Environment.FreeHandle (this);
  98. }
  99. public void Rollback ()
  100. {
  101. int status = 0;
  102. AttachToServiceContext ();
  103. status = OCITransRollback (Service.Handle,
  104. ErrorHandle.Handle,
  105. 0);
  106. if (status != 0) {
  107. OciErrorInfo info = ErrorHandle.HandleError ();
  108. throw new OracleException (info.ErrorCode, info.ErrorMessage);
  109. }
  110. }
  111. #endregion // Methods
  112. }
  113. }