类:Mongo::Operation::Context Private
- 继承:
-
CsotTimeoutHolder
- 对象
- CsotTimeoutHolder
- Mongo::Operation::Context
- 定义于:
- lib/ Mongo/operation/context.rb
Overview
此类是私有 API 的一部分。 应尽可能避免使用此类,因为它将来可能会被删除或更改。
操作的上下文。
在单个容器中保存有关操作执行决策所需的各种对象,并为所包含的对象提供门面方法。
上下文包含操作的参数,因此在准备操作时,上下文中的任何内容都不应更改。 处理操作结果时,上下文返回的数据可能会更改(例如,由于事务中止),但此时该操作不应再从上下文中读取任何内容。 由于上下文数据在操作执行期间可能会发生变化,因此上下文对象不应为多个操作重复使用。
实例属性摘要折叠
- #客户端⇒ 对象 只读 private
- # options ⇒ 对象 只读 private
- # session ⇒ 对象 只读 private
- #view ⇒ Object 只读 private
从 CsotTimeoutHolder 继承的属性
#deadline 、 #operation_timeups 、 #timeout_sec
实例方法摘要折叠
- # aborting_transaction? ⇒ 布尔 private
- # any_retry_writes? ⇒ 布尔 private
- # committing_transaction? ⇒ 布尔 private
- # connection_global_id ⇒ 对象 private
- #解密 (cmd) ⇒ 对象 private
- #解密? ⇒ 布尔 private
- # encrypt (db_name, cmd) ⇒ 对象 private
- # encrypt? ⇒ 布尔 private
- # Encrypter ⇒ 对象 private
- #in_transaction? ⇒ Boolean private
-
#initialize (客户端: nil, session: nil, connection_global_id: nil, operation_timeups: {}, view: nil, options: nil) ⇒ 上下文
构造函数
private
Context 的新实例。
- # 检查 ⇒ 对象 private
- #legacy_retry_writes? ⇒ 布尔 private
- #modern_retry_writes? ⇒ 布尔 private
-
# refresh (connection_global_id: @connection_global_id, timeout_ms: nil, view: nil) ="Operation::Context"
private
返回一个新的 Operation::Context,其截止日期已刷新且相对于当前时刻。
-
#重试? ⇒ 布尔
private
该操作是重试 (true) 还是初始尝试 (false)。
- # server_api ⇒ 对象 private
- # startup_transaction? ⇒ 布尔 private
-
# with (**opts) ⇒ 对象
private
返回一个新的上下文,其中的参数根据提供的参数进行更改。
从 CsotTimeoutHolder 继承的方法
#check_timeout! ,#csot? ,#remaining_timeout_ms,#remaining_timeout_ms! ,#remaining_timeout_sec,#remaining_timeout_sec! , #timeout? , #timeout_expired?
构造函数详情
#initialize (客户端: nil, session: nil, connection_global_id: nil, operation_timeups: {}, view: nil, options: nil) ⇒ 上下文
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回 Context 的新实例。
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 |
# File 'lib/ Mongo/operation/context.rb', line 38 def 初始化( 客户端: nil, 会话: nil, connection_global_id: nil, operation_timeups: {}, 视图: nil, 选项: nil ) if if 客户端 提高 ArgumentError, '不能同时指定客户端和选项' end if 会话 提高 ArgumentError, '不能同时指定会话和选项' end end if connection_global_id && 会话&。pinned_connection_global_id 提高 ArgumentError, '当会话已固定到连接时,尝试将上下文固定到连接。 ' end @client = 客户端 @session = 会话 @view = 查看 @connection_global_id = connection_global_id @options = 超(会话: 会话, operation_timeups: operation_timeups) end |
实例属性详细信息
#客户端⇒对象(只读)
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
68 69 70 |
# File 'lib/ Mongo/operation/context.rb', line 68 def 客户端 @client end |
# options ⇒对象(只读)
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
71 72 73 |
# File 'lib/ Mongo/operation/context.rb', line 71 def @options end |
# session ⇒对象(只读)
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
69 70 71 |
# File 'lib/ Mongo/operation/context.rb', line 69 def 会话 @session end |
#视图⇒对象(只读)
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
70 71 72 |
# File 'lib/ Mongo/operation/context.rb', line 70 def 查看 @view end |
实例方法详细信息
# aborting_transaction? ⇒布尔
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
105 106 107 |
# File 'lib/ Mongo/operation/context.rb', line 105 def aborting_transaction? in_transaction? && 会话.aborting_transaction? end |
# any_retry_writes? ⇒布尔
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
117 118 119 |
# File 'lib/ Mongo/operation/context.rb', line 117 def any_retry_writes? modern_retry_writes? || legacy_retry_writes? end |
# committing_transaction? ⇒布尔
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
101 102 103 |
# File 'lib/ Mongo/operation/context.rb', line 101 def committing_transaction? in_transaction? && 会话.committing_transaction? end |
# connection_global_id ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
89 90 91 |
# File 'lib/ Mongo/operation/context.rb', line 89 def connection_global_id @connection_global_id || 会话&。pinned_connection_global_id end |
#解密 (cmd) ⇒ 对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
159 160 161 |
# File 'lib/ Mongo/operation/context.rb', line 159 def 解密(cmd) 加密器.解密(cmd, self) end |
#解密? ⇒布尔
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
155 156 157 |
# File 'lib/ Mongo/operation/context.rb', line 155 def 解密? !!客户端&。加密器 end |
# encrypt (db_name, cmd) ⇒ 对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
151 152 153 |
# File 'lib/ Mongo/operation/context.rb', line 151 def 加密(db_name, cmd) 加密器.加密(db_name, cmd, self) end |
# encrypt? ⇒布尔
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
147 148 149 |
# File 'lib/ Mongo/operation/context.rb', line 147 def 加密? 客户端&。加密器&。加密? || false end |
# Encrypter ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
163 164 165 166 167 168 169 |
# File 'lib/ Mongo/operation/context.rb', line 163 def 加密器 if 客户端&。加密器 客户端.加密器 else 提高 错误::内部驱动程序错误, '仅当要执行加密时才应访问加密器' end end |
# in_transaction? ⇒布尔
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
93 94 95 |
# File 'lib/ Mongo/operation/context.rb', line 93 def in_transaction? 会话&。in_transaction? || false end |
# 检查 ⇒ 对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
171 172 173 |
# File 'lib/ Mongo/operation/context.rb', line 171 def 检查 " #< #{ self . class } connection_global_id= #{ connection_global_id . Inspect }截止时间= #{截止日期 . Inspect } options= #{ . Inspect } operation_timeups= #{ operation_timeups . Inspect } } > " end |
#legacy_retry_writes? ⇒布尔
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
113 114 115 |
# File 'lib/ Mongo/operation/context.rb', line 113 def legacy_retry_writes? 客户端 && !客户端.[:retry_writes] && 客户端.max_write_retries > 0 end |
#modern_retry_writes? ⇒布尔
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
109 110 111 |
# File 'lib/ Mongo/operation/context.rb', line 109 def modern_retry_writes? 客户端 && 客户端.[:retry_writes] end |
# refresh (connection_global_id: @connection_global_id, timeout_ms: nil, view: nil) ="Operation::Context"
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回一个新的 Operation::Context,其截止日期已刷新且相对于当前时刻。
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/ Mongo/operation/context.rb', line 77 def 刷新(connection_global_id: @connection_global_id, timeout_ms: nil, 视图: nil) operation_timeups = @operation_timeups operation_timeups = operation_timeups.合并(merge)(operation_timeout_ms: timeout_ms) if timeout_ms self.class.new(客户端: 客户端, 会话: 会话, connection_global_id: connection_global_id, operation_timeups: operation_timeups, 视图: 查看 || self.查看, 选项: ) end |
#重试? ⇒布尔
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
该操作是重试 (true) 还是初始尝试 (false)。
130 131 132 |
# File 'lib/ Mongo/operation/context.rb', line 130 def 重试? !!@is_retry end |
# server_api ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
121 122 123 124 125 126 127 |
# File 'lib/ Mongo/operation/context.rb', line 121 def server_api if 客户端 客户端.[:server_api] elsif [:server_api] end end |
# startup_transaction? ⇒布尔
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
97 98 99 |
# File 'lib/ Mongo/operation/context.rb', line 97 def startup_transaction? 会话&。startup_transaction? || false end |
# with (**opts) ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回一个新的上下文,其中的参数根据提供的参数进行更改。
139 140 141 142 143 144 145 |
# File 'lib/ Mongo/operation/context.rb', line 139 def 通过(**opts) dup.点击 do |copy| opts.每 do |k, v| copy.instance_variable_set(" @ #{ k } ", v) end end end |