1919from ravendb .http .server_node import ServerNode
2020from ravendb .http .topology import RaftCommand
2121from ravendb .json .metadata_as_dictionary import MetadataAsDictionary
22- from ravendb .documents .session .entity_to_json import EntityToJson
22+ from ravendb .documents .session .entity_to_json import EntityToJsonStatic
2323from ravendb .tools .utils import Utils
2424from ravendb .util .util import RaftIdGenerator
2525
@@ -65,14 +65,14 @@ def parse_from_string(
6565
6666class PutCompareExchangeValueOperation (IOperation [CompareExchangeResult ], Generic [_T ]):
6767 def __init__ (self , key : str , value : _T , index : int , metadata : MetadataAsDictionary = None ):
68- self .__key = key
69- self .__value = value
70- self .__index = index
71- self .__metadata = metadata
68+ self ._key = key
69+ self ._value = value
70+ self ._index = index
71+ self ._metadata = metadata
7272
7373 def get_command (self , store : DocumentStore , conventions : DocumentConventions , cache : HttpCache ) -> RavenCommand [_T ]:
7474 return self .__PutCompareExchangeValueCommand (
75- self .__key , self .__value , self .__index , self .__metadata , conventions
75+ self ._key , self ._value , self ._index , self ._metadata , conventions
7676 )
7777
7878 class __PutCompareExchangeValueCommand (RavenCommand [_T ], RaftCommand , Generic [_T ]):
@@ -87,43 +87,43 @@ def __init__(
8787
8888 super ().__init__ (CompareExchangeResult [_T ])
8989
90- self .__key = key
91- self .__value = value
92- self .__index = index
93- self .__metadata = metadata
94- self .__conventions = conventions or DocumentConventions ()
90+ self ._key = key
91+ self ._value = value
92+ self ._index = index
93+ self ._metadata = metadata
94+ self ._conventions = conventions or DocumentConventions ()
9595
9696 def is_read_request (self ) -> bool :
9797 return False
9898
9999 def create_request (self , node : ServerNode ) -> requests .Request :
100- url = f"{ node .url } /databases/{ node .database } /cmpxchg?key={ Utils .quote_key (self .__key )} &index={ self .__index } "
101- tuple = {constants .CompareExchange .OBJECT_FIELD_NAME : self .__value }
102- json_dict = EntityToJson . convert_entity_to_json_internal_static ( tuple , self .__conventions , None , False )
103- if self .__metadata :
100+ url = f"{ node .url } /databases/{ node .database } /cmpxchg?key={ Utils .quote_key (self ._key )} &index={ self ._index } "
101+ object_and_value = {constants .CompareExchange .OBJECT_FIELD_NAME : self ._value }
102+ json_dict = EntityToJsonStatic . convert_entity_to_json ( object_and_value , self ._conventions , None , False )
103+ if self ._metadata :
104104 metadata = CompareExchangeSessionValue .prepare_metadata_for_put (
105- self .__key , self .__metadata , self .__conventions
105+ self ._key , self ._metadata , self ._conventions
106106 )
107107 json_dict [constants .Documents .Metadata .KEY ] = metadata
108108
109109 return requests .Request ("PUT" , url , data = json_dict )
110110
111111 def set_response (self , response : str , from_cache : bool ) -> None :
112- self .result = CompareExchangeResult .parse_from_string (type (self .__value ), response , self .__conventions )
112+ self .result = CompareExchangeResult .parse_from_string (type (self ._value ), response , self ._conventions )
113113
114114 def get_raft_unique_request_id (self ) -> str :
115115 return RaftIdGenerator .new_id ()
116116
117117
118118class GetCompareExchangeValueOperation (IOperation [CompareExchangeValue [_T ]], Generic [_T ]):
119119 def __init__ (self , key : str , object_type : Type [_T ], materialize_metadata : bool = True ):
120- self .__key = key
121- self .__object_type = object_type
122- self .__materialize_metadata = materialize_metadata
120+ self ._key = key
121+ self ._object_type = object_type
122+ self ._materialize_metadata = materialize_metadata
123123
124124 def get_command (self , store : DocumentStore , conventions : DocumentConventions , cache : HttpCache ) -> RavenCommand [_T ]:
125125 return self .GetCompareExchangeValueCommand (
126- self .__key , self .__object_type , self .__materialize_metadata , conventions
126+ self ._key , self ._object_type , self ._materialize_metadata , conventions
127127 )
128128
129129 class GetCompareExchangeValueCommand (RavenCommand [CompareExchangeValue [_T ]]):
@@ -133,55 +133,55 @@ def __init__(
133133 if not key :
134134 raise ValueError ("The key argument must have value" )
135135 super ().__init__ (CompareExchangeValue [_T ])
136- self .__key = key
137- self .__object_type = object_type
138- self .__materialize_metadata = materialize_metadata
139- self .__conventions = conventions
136+ self ._key = key
137+ self ._object_type = object_type
138+ self ._materialize_metadata = materialize_metadata
139+ self ._conventions = conventions
140140
141141 def is_read_request (self ) -> bool :
142142 return True
143143
144144 def create_request (self , node : ServerNode ) -> requests .Request :
145- url = f"{ node .url } /databases/{ node .database } /cmpxchg?key={ Utils .quote_key (self .__key )} "
145+ url = f"{ node .url } /databases/{ node .database } /cmpxchg?key={ Utils .quote_key (self ._key )} "
146146 return requests .Request ("GET" , url )
147147
148148 def set_response (self , response : str , from_cache : bool ) -> None :
149149 self .result = CompareExchangeValueResultParser .get_value (
150- self .__object_type , response , self .__materialize_metadata , self .__conventions
150+ self ._object_type , response , self ._materialize_metadata , self ._conventions
151151 )
152152
153153
154154class DeleteCompareExchangeValueOperation (IOperation [CompareExchangeResult [_T ]], Generic [_T ]):
155155 def __init__ (self , object_type : type , key : str , index : int ):
156- self .__key = key
157- self .__object_type = object_type
158- self .__index = index
156+ self ._key = key
157+ self ._object_type = object_type
158+ self ._index = index
159159
160160 def get_command (self , store : DocumentStore , conventions : DocumentConventions , cache : HttpCache ) -> RavenCommand [_T ]:
161- return self .RemoveCompareExchangeCommand [_T ](self .__object_type , self .__key , self .__index , conventions )
161+ return self .RemoveCompareExchangeCommand [_T ](self ._object_type , self ._key , self ._index , conventions )
162162
163163 class RemoveCompareExchangeCommand (RavenCommand [CompareExchangeResult [_T ]], RaftCommand , Generic [_T ]):
164164 def __init__ (self , object_type : type , key : str , index : int , conventions : DocumentConventions ):
165165 if not key :
166166 raise ValueError ("The key must have value" )
167167
168168 super ().__init__ (CompareExchangeResult [_T ])
169- self .__object_type = object_type
170- self .__key = key
171- self .__index = index
172- self .__conventions = conventions
169+ self ._object_type = object_type
170+ self ._key = key
171+ self ._index = index
172+ self ._conventions = conventions
173173
174174 def is_read_request (self ) -> bool :
175175 return True
176176
177177 def create_request (self , node : ServerNode ) -> requests .Request :
178178 return requests .Request (
179179 "DELETE" ,
180- f"{ node .url } /databases/{ node .database } /cmpxchg?key={ Utils .quote_key (self .__key )} &index={ self .__index } " ,
180+ f"{ node .url } /databases/{ node .database } /cmpxchg?key={ Utils .quote_key (self ._key )} &index={ self ._index } " ,
181181 )
182182
183183 def set_response (self , response : str , from_cache : bool ) -> None :
184- self .result = CompareExchangeResult .parse_from_string (self .__object_type , response , self .__conventions )
184+ self .result = CompareExchangeResult .parse_from_string (self ._object_type , response , self ._conventions )
185185
186186 def get_raft_unique_request_id (self ) -> str :
187187 return RaftIdGenerator .new_id ()
@@ -226,34 +226,34 @@ def __init__(
226226 conventions : DocumentConventions ,
227227 ):
228228 super ().__init__ (dict )
229- self .__operation = operation
230- self .__materialize_metadata = materialize_metadata
231- self .__conventions = conventions
229+ self ._operation = operation
230+ self ._materialize_metadata = materialize_metadata
231+ self ._conventions = conventions
232232
233233 def is_read_request (self ) -> bool :
234234 return True
235235
236236 def create_request (self , node : ServerNode ) -> requests .Request :
237237 path_builder = [node .url , "/databases/" , node .database , "/cmpxchg?" ]
238238
239- if self .__operation ._keys :
240- for key in self .__operation ._keys :
239+ if self ._operation ._keys :
240+ for key in self ._operation ._keys :
241241 path_builder .append ("&key=" )
242242 path_builder .append (Utils .quote_key (key ))
243243 else :
244- if self .__operation ._start_with :
244+ if self ._operation ._start_with :
245245 path_builder .append ("&startsWith=" )
246- path_builder .append (Utils .quote_key (self .__operation ._start_with ))
247- if self .__operation ._start :
246+ path_builder .append (Utils .quote_key (self ._operation ._start_with ))
247+ if self ._operation ._start :
248248 path_builder .append ("&start=" )
249- path_builder .append (Utils .quote_key (self .__operation ._start ))
250- if self .__operation ._page_size :
249+ path_builder .append (Utils .quote_key (self ._operation ._start ))
250+ if self ._operation ._page_size :
251251 path_builder .append ("&pageSize=" )
252- path_builder .append (Utils .quote_key (self .__operation ._page_size ))
252+ path_builder .append (Utils .quote_key (self ._operation ._page_size ))
253253
254254 return requests .Request ("GET" , "" .join (path_builder ))
255255
256256 def set_response (self , response : str , from_cache : bool ) -> None :
257257 self .result = CompareExchangeValueResultParser .get_values (
258- self .__operation ._object_type , response , self .__materialize_metadata , self .__conventions
258+ self ._operation ._object_type , response , self ._materialize_metadata , self ._conventions
259259 )
0 commit comments