OciTransactionHandle.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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, IDisposable
  21. {
  22. #region Fields
  23. bool disposed = false;
  24. OciErrorHandle errorHandle;
  25. OciServiceHandle serviceHandle;
  26. #endregion // Fields
  27. #region Constructors
  28. public OciTransactionHandle (OciHandle parent, IntPtr handle)
  29. : base (OciHandleType.Transaction, parent, handle)
  30. {
  31. }
  32. #endregion // Constructors
  33. #region Properties
  34. public OciErrorHandle ErrorHandle {
  35. get { return errorHandle; }
  36. set { errorHandle = value; }
  37. }
  38. public OciServiceHandle Service {
  39. get { return serviceHandle; }
  40. set { serviceHandle = value; }
  41. }
  42. #endregion // Properties
  43. #region Methods
  44. public void AttachToServiceContext ()
  45. {
  46. int status = 0;
  47. status = OciCalls.OCIAttrSet (Service,
  48. OciHandleType.Service,
  49. this,
  50. 0,
  51. OciAttributeType.Transaction,
  52. ErrorHandle);
  53. if (status != 0) {
  54. OciErrorInfo info = ErrorHandle.HandleError ();
  55. throw new OracleException (info.ErrorCode, info.ErrorMessage);
  56. }
  57. }
  58. public void DetachFromServiceContext ()
  59. {
  60. int status = 0;
  61. status = OciCalls.OCIAttrSet (Service,
  62. OciHandleType.Service,
  63. IntPtr.Zero,
  64. 0,
  65. OciAttributeType.Transaction,
  66. ErrorHandle);
  67. if (status != 0)
  68. {
  69. OciErrorInfo info = ErrorHandle.HandleError ();
  70. throw new OracleException (info.ErrorCode, info.ErrorMessage);
  71. }
  72. }
  73. public void Begin ()
  74. {
  75. int status = 0;
  76. AttachToServiceContext ();
  77. status = OciCalls.OCITransStart (Service,
  78. ErrorHandle,
  79. 60,
  80. OciTransactionFlags.New);
  81. if (status != 0) {
  82. OciErrorInfo info = ErrorHandle.HandleError ();
  83. throw new OracleException (info.ErrorCode, info.ErrorMessage);
  84. }
  85. }
  86. public void Commit ()
  87. {
  88. int status = 0;
  89. AttachToServiceContext ();
  90. try {
  91. status = OciCalls.OCITransCommit (Service, ErrorHandle, 0);
  92. if (status != 0)
  93. {
  94. OciErrorInfo info = ErrorHandle.HandleError ();
  95. throw new OracleException (info.ErrorCode, info.ErrorMessage);
  96. }
  97. }
  98. finally {
  99. DetachFromServiceContext ();
  100. }
  101. }
  102. protected override void Dispose (bool disposing)
  103. {
  104. if (!disposed) {
  105. disposed = true;
  106. base.Dispose (disposing);
  107. }
  108. }
  109. public void Rollback ()
  110. {
  111. try {
  112. int status = 0;
  113. AttachToServiceContext ();
  114. status = OciCalls.OCITransRollback (Service, ErrorHandle, 0);
  115. if (status != 0) {
  116. OciErrorInfo info = ErrorHandle.HandleError ();
  117. throw new OracleException (info.ErrorCode, info.ErrorMessage);
  118. }
  119. }
  120. finally {
  121. DetachFromServiceContext ();
  122. }
  123. }
  124. #endregion // Methods
  125. }
  126. }