OleDbTransaction.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. //
  2. // System.Data.OleDb.OleDbTransaction
  3. //
  4. // Authors:
  5. // Rodrigo Moya ([email protected])
  6. // Tim Coleman ([email protected])
  7. //
  8. // Copyright (C) Rodrigo Moya, 2002
  9. // Copyright (C) Tim Coleman, 2002
  10. // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining
  13. // a copy of this software and associated documentation files (the
  14. // "Software"), to deal in the Software without restriction, including
  15. // without limitation the rights to use, copy, modify, merge, publish,
  16. // distribute, sublicense, and/or sell copies of the Software, and to
  17. // permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be
  21. // included in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. //
  31. using System.Data.Common;
  32. namespace System.Data.OleDb
  33. {
  34. #if NET_2_0
  35. public sealed class OleDbTransaction : DbTransaction, IDbTransaction
  36. #else
  37. public sealed class OleDbTransaction : MarshalByRefObject, IDbTransaction, IDisposable
  38. #endif
  39. {
  40. #region Fields
  41. OleDbConnection connection;
  42. IntPtr gdaTransaction;
  43. int depth;
  44. #endregion // Fields
  45. #region Constructors
  46. internal OleDbTransaction (OleDbConnection connection, int depth)
  47. : this (connection, depth, IsolationLevel.ReadCommitted)
  48. {
  49. }
  50. internal OleDbTransaction (OleDbConnection connection)
  51. : this (connection, 1)
  52. {
  53. }
  54. internal OleDbTransaction (OleDbConnection connection, int depth, IsolationLevel isolevel)
  55. {
  56. this.connection = connection;
  57. gdaTransaction = libgda.gda_transaction_new (depth.ToString ());
  58. switch (isolevel) {
  59. case IsolationLevel.ReadCommitted :
  60. libgda.gda_transaction_set_isolation_level (gdaTransaction,
  61. GdaTransactionIsolation.ReadCommitted);
  62. break;
  63. case IsolationLevel.ReadUncommitted :
  64. libgda.gda_transaction_set_isolation_level (gdaTransaction,
  65. GdaTransactionIsolation.ReadUncommitted);
  66. break;
  67. case IsolationLevel.RepeatableRead :
  68. libgda.gda_transaction_set_isolation_level (gdaTransaction,
  69. GdaTransactionIsolation.RepeatableRead);
  70. break;
  71. case IsolationLevel.Serializable :
  72. libgda.gda_transaction_set_isolation_level (gdaTransaction,
  73. GdaTransactionIsolation.Serializable);
  74. break;
  75. }
  76. libgda.gda_connection_begin_transaction (connection.GdaConnection, gdaTransaction);
  77. }
  78. internal OleDbTransaction (OleDbConnection connection, IsolationLevel isolevel)
  79. : this (connection, 1, isolevel)
  80. {
  81. }
  82. #endregion // Constructors
  83. #region Properties
  84. public new OleDbConnection Connection {
  85. get {
  86. return connection;
  87. }
  88. }
  89. #if NET_2_0
  90. protected override DbConnection DbConnection {
  91. get { return connection; }
  92. }
  93. #endif
  94. IDbConnection IDbTransaction.Connection {
  95. get {
  96. return connection;
  97. }
  98. }
  99. public
  100. #if NET_2_0
  101. override
  102. #endif
  103. IsolationLevel IsolationLevel {
  104. get {
  105. switch (libgda.gda_transaction_get_isolation_level (gdaTransaction)) {
  106. case GdaTransactionIsolation.ReadCommitted :
  107. return IsolationLevel.ReadCommitted;
  108. case GdaTransactionIsolation.ReadUncommitted :
  109. return IsolationLevel.ReadUncommitted;
  110. case GdaTransactionIsolation.RepeatableRead :
  111. return IsolationLevel.RepeatableRead;
  112. case GdaTransactionIsolation.Serializable :
  113. return IsolationLevel.Serializable;
  114. }
  115. return IsolationLevel.Unspecified;
  116. }
  117. }
  118. #endregion // Properties
  119. #region Methods
  120. public OleDbTransaction Begin ()
  121. {
  122. return new OleDbTransaction (connection, depth + 1);
  123. }
  124. public OleDbTransaction Begin (IsolationLevel isolevel)
  125. {
  126. return new OleDbTransaction (connection, depth + 1, isolevel);
  127. }
  128. public
  129. #if NET_2_0
  130. override
  131. #endif
  132. void Commit ()
  133. {
  134. if (!libgda.gda_connection_commit_transaction (connection.GdaConnection,
  135. gdaTransaction))
  136. throw new InvalidOperationException ();
  137. }
  138. [MonoTODO]
  139. ~OleDbTransaction ()
  140. {
  141. libgda.FreeObject (gdaTransaction);
  142. gdaTransaction = IntPtr.Zero;
  143. }
  144. [MonoTODO]
  145. #if NET_2_0
  146. protected override void Dispose (bool disposing)
  147. {
  148. base.Dispose (disposing);
  149. }
  150. #else
  151. void IDisposable.Dispose ()
  152. {
  153. GC.SuppressFinalize (this);
  154. }
  155. #endif
  156. public
  157. #if NET_2_0
  158. override
  159. #endif
  160. void Rollback ()
  161. {
  162. if (!libgda.gda_connection_rollback_transaction (connection.GdaConnection,
  163. gdaTransaction))
  164. throw new InvalidOperationException ();
  165. }
  166. #endregion // Methods
  167. }
  168. }