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