OleDbTransaction.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. public sealed class OleDbTransaction : MarshalByRefObject, IDbTransaction, IDisposable
  35. {
  36. #region Fields
  37. OleDbConnection connection;
  38. IntPtr gdaTransaction;
  39. int depth;
  40. #endregion // Fields
  41. #region Constructors
  42. internal OleDbTransaction (OleDbConnection connection, int depth)
  43. : this (connection, depth, IsolationLevel.ReadCommitted)
  44. {
  45. }
  46. internal OleDbTransaction (OleDbConnection connection)
  47. : this (connection, 1)
  48. {
  49. }
  50. internal OleDbTransaction (OleDbConnection connection, int depth, IsolationLevel isolevel)
  51. {
  52. this.connection = connection;
  53. gdaTransaction = libgda.gda_transaction_new (depth.ToString ());
  54. switch (isolevel) {
  55. case IsolationLevel.ReadCommitted :
  56. libgda.gda_transaction_set_isolation_level (gdaTransaction,
  57. GdaTransactionIsolation.ReadCommitted);
  58. break;
  59. case IsolationLevel.ReadUncommitted :
  60. libgda.gda_transaction_set_isolation_level (gdaTransaction,
  61. GdaTransactionIsolation.ReadUncommitted);
  62. break;
  63. case IsolationLevel.RepeatableRead :
  64. libgda.gda_transaction_set_isolation_level (gdaTransaction,
  65. GdaTransactionIsolation.RepeatableRead);
  66. break;
  67. case IsolationLevel.Serializable :
  68. libgda.gda_transaction_set_isolation_level (gdaTransaction,
  69. GdaTransactionIsolation.Serializable);
  70. break;
  71. }
  72. libgda.gda_connection_begin_transaction (connection.GdaConnection, gdaTransaction);
  73. }
  74. internal OleDbTransaction (OleDbConnection connection, IsolationLevel isolevel)
  75. : this (connection, 1, isolevel)
  76. {
  77. }
  78. #endregion // Constructors
  79. #region Properties
  80. public OleDbConnection Connection {
  81. get {
  82. return connection;
  83. }
  84. }
  85. IDbConnection IDbTransaction.Connection {
  86. get {
  87. return connection;
  88. }
  89. }
  90. public IsolationLevel IsolationLevel {
  91. get {
  92. switch (libgda.gda_transaction_get_isolation_level (gdaTransaction)) {
  93. case GdaTransactionIsolation.ReadCommitted :
  94. return IsolationLevel.ReadCommitted;
  95. case GdaTransactionIsolation.ReadUncommitted :
  96. return IsolationLevel.ReadUncommitted;
  97. case GdaTransactionIsolation.RepeatableRead :
  98. return IsolationLevel.RepeatableRead;
  99. case GdaTransactionIsolation.Serializable :
  100. return IsolationLevel.Serializable;
  101. }
  102. return IsolationLevel.Unspecified;
  103. }
  104. }
  105. #endregion // Properties
  106. #region Methods
  107. public OleDbTransaction Begin ()
  108. {
  109. return new OleDbTransaction (connection, depth + 1);
  110. }
  111. public OleDbTransaction Begin (IsolationLevel isolevel)
  112. {
  113. return new OleDbTransaction (connection, depth + 1, isolevel);
  114. }
  115. public void Commit ()
  116. {
  117. if (!libgda.gda_connection_commit_transaction (connection.GdaConnection,
  118. gdaTransaction))
  119. throw new InvalidOperationException ();
  120. }
  121. [MonoTODO]
  122. ~OleDbTransaction ()
  123. {
  124. libgda.FreeObject (gdaTransaction);
  125. gdaTransaction = IntPtr.Zero;
  126. }
  127. [MonoTODO]
  128. void IDisposable.Dispose ()
  129. {
  130. GC.SuppressFinalize (this);
  131. throw new NotImplementedException ();
  132. }
  133. public void Rollback ()
  134. {
  135. if (!libgda.gda_connection_rollback_transaction (connection.GdaConnection,
  136. gdaTransaction))
  137. throw new InvalidOperationException ();
  138. }
  139. #endregion // Methods
  140. }
  141. }