IClientSession.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /* Copyright 2017-present MongoDB Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. using System;
  16. using System.Threading;
  17. using System.Threading.Tasks;
  18. using MongoDB.Bson;
  19. using MongoDB.Driver.Core.Bindings;
  20. namespace MongoDB.Driver
  21. {
  22. /// <summary>
  23. /// The interface for a client session.
  24. /// </summary>
  25. public interface IClientSession : IDisposable
  26. {
  27. // properties
  28. /// <summary>
  29. /// Gets the client.
  30. /// </summary>
  31. /// <value>
  32. /// The client.
  33. /// </value>
  34. IMongoClient Client { get; }
  35. /// <summary>
  36. /// Gets the cluster time.
  37. /// </summary>
  38. /// <value>
  39. /// The cluster time.
  40. /// </value>
  41. BsonDocument ClusterTime { get; }
  42. /// <summary>
  43. /// Gets a value indicating whether this session is an implicit session.
  44. /// </summary>
  45. /// <value>
  46. /// <c>true</c> if this session is an implicit session; otherwise, <c>false</c>.
  47. /// </value>
  48. bool IsImplicit { get; }
  49. /// <summary>
  50. /// Gets a value indicating whether this instance is in a transaction.
  51. /// </summary>
  52. /// <value>
  53. /// <c>true</c> if this instance is in a transaction; otherwise, <c>false</c>.
  54. /// </value>
  55. bool IsInTransaction { get; }
  56. /// <summary>
  57. /// Gets the operation time.
  58. /// </summary>
  59. /// <value>
  60. /// The operation time.
  61. /// </value>
  62. BsonTimestamp OperationTime { get; }
  63. /// <summary>
  64. /// Gets the options.
  65. /// </summary>
  66. /// <value>
  67. /// The options.
  68. /// </value>
  69. ClientSessionOptions Options { get; }
  70. /// <summary>
  71. /// Gets the server session.
  72. /// </summary>
  73. /// <value>
  74. /// The server session.
  75. /// </value>
  76. IServerSession ServerSession { get; }
  77. /// <summary>
  78. /// Gets the wrapped core session (intended for internal use only).
  79. /// </summary>
  80. /// <value>
  81. /// The wrapped core session.
  82. /// </value>
  83. ICoreSessionHandle WrappedCoreSession { get; }
  84. // methods
  85. /// <summary>
  86. /// Aborts the transaction.
  87. /// </summary>
  88. /// <param name="cancellationToken">The cancellation token.</param>
  89. void AbortTransaction(CancellationToken cancellationToken = default(CancellationToken));
  90. /// <summary>
  91. /// Aborts the transaction.
  92. /// </summary>
  93. /// <param name="cancellationToken">The cancellation token.</param>
  94. /// <returns>A Task.</returns>
  95. Task AbortTransactionAsync(CancellationToken cancellationToken = default(CancellationToken));
  96. /// <summary>
  97. /// Advances the cluster time.
  98. /// </summary>
  99. /// <param name="newClusterTime">The new cluster time.</param>
  100. void AdvanceClusterTime(BsonDocument newClusterTime);
  101. /// <summary>
  102. /// Advances the operation time.
  103. /// </summary>
  104. /// <param name="newOperationTime">The new operation time.</param>
  105. void AdvanceOperationTime(BsonTimestamp newOperationTime);
  106. /// <summary>
  107. /// Commits the transaction.
  108. /// </summary>
  109. /// <param name="cancellationToken">The cancellation token.</param>
  110. void CommitTransaction(CancellationToken cancellationToken = default(CancellationToken));
  111. /// <summary>
  112. /// Commits the transaction.
  113. /// </summary>
  114. /// <param name="cancellationToken">The cancellation token.</param>
  115. /// <returns>A Task.</returns>
  116. Task CommitTransactionAsync(CancellationToken cancellationToken = default(CancellationToken));
  117. /// <summary>
  118. /// Starts a transaction.
  119. /// </summary>
  120. /// <param name="transactionOptions">The transaction options.</param>
  121. void StartTransaction(TransactionOptions transactionOptions = null);
  122. }
  123. /// <summary>
  124. /// A handle to an underlying reference counted IClientSession.
  125. /// </summary>
  126. /// <seealso cref="MongoDB.Driver.IClientSession" />
  127. public interface IClientSessionHandle : IClientSession
  128. {
  129. /// <summary>
  130. /// Forks this instance.
  131. /// </summary>
  132. /// <returns>A session.</returns>
  133. IClientSessionHandle Fork();
  134. }
  135. }