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, 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. [DllImport ("oci")]
  45. public static extern int OCITransCommit (IntPtr svchp,
  46. IntPtr errhp,
  47. uint flags);
  48. [DllImport ("oci")]
  49. public static extern int OCITransRollback (IntPtr svchp,
  50. IntPtr errhp,
  51. uint flags);
  52. [DllImport ("oci")]
  53. public static extern int OCITransStart (IntPtr svchp,
  54. IntPtr errhp,
  55. uint timeout,
  56. [MarshalAs (UnmanagedType.U4)] OciTransactionFlags flags);
  57. public void AttachToServiceContext ()
  58. {
  59. int status = 0;
  60. status = OciGlue.OCIAttrSet (Service,
  61. OciHandleType.Service,
  62. this,
  63. 0,
  64. OciAttributeType.Transaction,
  65. ErrorHandle);
  66. if (status != 0) {
  67. OciErrorInfo info = ErrorHandle.HandleError ();
  68. throw new OracleException (info.ErrorCode, info.ErrorMessage);
  69. }
  70. }
  71. public void Begin ()
  72. {
  73. int status = 0;
  74. AttachToServiceContext ();
  75. status = OCITransStart (Service,
  76. ErrorHandle,
  77. 60,
  78. OciTransactionFlags.New);
  79. if (status != 0) {
  80. OciErrorInfo info = ErrorHandle.HandleError ();
  81. throw new OracleException (info.ErrorCode, info.ErrorMessage);
  82. }
  83. }
  84. public void Commit ()
  85. {
  86. int status = 0;
  87. AttachToServiceContext ();
  88. status = OCITransCommit (Service, ErrorHandle, 0);
  89. if (status != 0) {
  90. OciErrorInfo info = ErrorHandle.HandleError ();
  91. throw new OracleException (info.ErrorCode, info.ErrorMessage);
  92. }
  93. }
  94. protected override void Dispose (bool disposing)
  95. {
  96. if (!disposed) {
  97. disposed = true;
  98. base.Dispose (disposing);
  99. }
  100. }
  101. public void Rollback ()
  102. {
  103. int status = 0;
  104. AttachToServiceContext ();
  105. status = OCITransRollback (Service, ErrorHandle, 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. }