19
19
from ravendb .http .server_node import ServerNode
20
20
from ravendb .http .topology import RaftCommand
21
21
from 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
23
23
from ravendb .tools .utils import Utils
24
24
from ravendb .util .util import RaftIdGenerator
25
25
@@ -65,14 +65,14 @@ def parse_from_string(
65
65
66
66
class PutCompareExchangeValueOperation (IOperation [CompareExchangeResult ], Generic [_T ]):
67
67
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
72
72
73
73
def get_command (self , store : DocumentStore , conventions : DocumentConventions , cache : HttpCache ) -> RavenCommand [_T ]:
74
74
return self .__PutCompareExchangeValueCommand (
75
- self .__key , self .__value , self .__index , self .__metadata , conventions
75
+ self ._key , self ._value , self ._index , self ._metadata , conventions
76
76
)
77
77
78
78
class __PutCompareExchangeValueCommand (RavenCommand [_T ], RaftCommand , Generic [_T ]):
@@ -87,43 +87,43 @@ def __init__(
87
87
88
88
super ().__init__ (CompareExchangeResult [_T ])
89
89
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 ()
95
95
96
96
def is_read_request (self ) -> bool :
97
97
return False
98
98
99
99
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 :
104
104
metadata = CompareExchangeSessionValue .prepare_metadata_for_put (
105
- self .__key , self .__metadata , self .__conventions
105
+ self ._key , self ._metadata , self ._conventions
106
106
)
107
107
json_dict [constants .Documents .Metadata .KEY ] = metadata
108
108
109
109
return requests .Request ("PUT" , url , data = json_dict )
110
110
111
111
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 )
113
113
114
114
def get_raft_unique_request_id (self ) -> str :
115
115
return RaftIdGenerator .new_id ()
116
116
117
117
118
118
class GetCompareExchangeValueOperation (IOperation [CompareExchangeValue [_T ]], Generic [_T ]):
119
119
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
123
123
124
124
def get_command (self , store : DocumentStore , conventions : DocumentConventions , cache : HttpCache ) -> RavenCommand [_T ]:
125
125
return self .GetCompareExchangeValueCommand (
126
- self .__key , self .__object_type , self .__materialize_metadata , conventions
126
+ self ._key , self ._object_type , self ._materialize_metadata , conventions
127
127
)
128
128
129
129
class GetCompareExchangeValueCommand (RavenCommand [CompareExchangeValue [_T ]]):
@@ -133,55 +133,55 @@ def __init__(
133
133
if not key :
134
134
raise ValueError ("The key argument must have value" )
135
135
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
140
140
141
141
def is_read_request (self ) -> bool :
142
142
return True
143
143
144
144
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 )} "
146
146
return requests .Request ("GET" , url )
147
147
148
148
def set_response (self , response : str , from_cache : bool ) -> None :
149
149
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
151
151
)
152
152
153
153
154
154
class DeleteCompareExchangeValueOperation (IOperation [CompareExchangeResult [_T ]], Generic [_T ]):
155
155
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
159
159
160
160
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 )
162
162
163
163
class RemoveCompareExchangeCommand (RavenCommand [CompareExchangeResult [_T ]], RaftCommand , Generic [_T ]):
164
164
def __init__ (self , object_type : type , key : str , index : int , conventions : DocumentConventions ):
165
165
if not key :
166
166
raise ValueError ("The key must have value" )
167
167
168
168
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
173
173
174
174
def is_read_request (self ) -> bool :
175
175
return True
176
176
177
177
def create_request (self , node : ServerNode ) -> requests .Request :
178
178
return requests .Request (
179
179
"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 } " ,
181
181
)
182
182
183
183
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 )
185
185
186
186
def get_raft_unique_request_id (self ) -> str :
187
187
return RaftIdGenerator .new_id ()
@@ -226,34 +226,34 @@ def __init__(
226
226
conventions : DocumentConventions ,
227
227
):
228
228
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
232
232
233
233
def is_read_request (self ) -> bool :
234
234
return True
235
235
236
236
def create_request (self , node : ServerNode ) -> requests .Request :
237
237
path_builder = [node .url , "/databases/" , node .database , "/cmpxchg?" ]
238
238
239
- if self .__operation ._keys :
240
- for key in self .__operation ._keys :
239
+ if self ._operation ._keys :
240
+ for key in self ._operation ._keys :
241
241
path_builder .append ("&key=" )
242
242
path_builder .append (Utils .quote_key (key ))
243
243
else :
244
- if self .__operation ._start_with :
244
+ if self ._operation ._start_with :
245
245
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 :
248
248
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 :
251
251
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 ))
253
253
254
254
return requests .Request ("GET" , "" .join (path_builder ))
255
255
256
256
def set_response (self , response : str , from_cache : bool ) -> None :
257
257
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
259
259
)
0 commit comments