forked from mongodb/mongo-csharp-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTransactionOptions.cs
108 lines (100 loc) · 4.07 KB
/
TransactionOptions.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
/* Copyright 2018-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;
namespace MongoDB.Driver
{
/// <summary>
/// Transaction options.
/// </summary>
public class TransactionOptions
{
// private fields
private readonly TimeSpan? _maxCommitTime;
private readonly ReadConcern _readConcern;
private readonly ReadPreference _readPreference;
private readonly WriteConcern _writeConcern;
// public constructors
/// <summary>
/// Initializes a new instance of the <see cref="TransactionOptions" /> class.
/// </summary>
/// <param name="readConcern">The read concern.</param>
/// <param name="readPreference">The read preference.</param>
/// <param name="writeConcern">The write concern.</param>
/// <param name="maxCommitTime">The max commit time.</param>
public TransactionOptions(
Optional<ReadConcern> readConcern = default(Optional<ReadConcern>),
Optional<ReadPreference> readPreference = default(Optional<ReadPreference>),
Optional<WriteConcern> writeConcern = default(Optional<WriteConcern>),
Optional<TimeSpan?> maxCommitTime = default(Optional<TimeSpan?>))
{
_readConcern = readConcern.WithDefault(null);
_readPreference = readPreference.WithDefault(null);
_writeConcern = writeConcern.WithDefault(null);
_maxCommitTime = maxCommitTime.WithDefault(null);
}
// public properties
/// <summary>
/// Gets the max commit time.
/// </summary>
/// <value>
/// The max commit time.
/// </value>
public TimeSpan? MaxCommitTime => _maxCommitTime;
/// <summary>
/// Gets the read concern.
/// </summary>
/// <value>
/// The read concern.
/// </value>
public ReadConcern ReadConcern => _readConcern;
/// <summary>
/// Gets the read preference.
/// </summary>
/// <value>
/// The read preference.
/// </value>
public ReadPreference ReadPreference => _readPreference;
/// <summary>
/// Gets the write concern.
/// </summary>
/// <value>
/// The write concern.
/// </value>
public WriteConcern WriteConcern => _writeConcern;
// public methods
/// <summary>
/// Returns a new TransactionOptions with some values changed.
/// </summary>
/// <param name="readConcern">The new read concern.</param>
/// <param name="readPreference">The read preference.</param>
/// <param name="writeConcern">The new write concern.</param>
/// <param name="maxCommitTime">The max commit time.</param>
/// <returns>
/// The new TransactionOptions.
/// </returns>
public TransactionOptions With(
Optional<ReadConcern> readConcern = default(Optional<ReadConcern>),
Optional<ReadPreference> readPreference = default(Optional<ReadPreference>),
Optional<WriteConcern> writeConcern = default(Optional<WriteConcern>),
Optional<TimeSpan?> maxCommitTime = default(Optional<TimeSpan?>))
{
return new TransactionOptions(
readConcern: readConcern.WithDefault(_readConcern),
readPreference: readPreference.WithDefault(_readPreference),
writeConcern: writeConcern.WithDefault(_writeConcern),
maxCommitTime: maxCommitTime.WithDefault(_maxCommitTime));
}
}
}