forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_compare_exchange_value_operation.go
77 lines (60 loc) · 1.93 KB
/
get_compare_exchange_value_operation.go
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
package ravendb
import (
"net/http"
"reflect"
)
var (
_ IOperation = &GetCompareExchangeValueOperation{}
)
type GetCompareExchangeValueOperation struct {
Command *GetCompareExchangeValueCommand
_key string
_clazz reflect.Type
}
func NewGetCompareExchangeValueOperation(clazz reflect.Type, key string) (*GetCompareExchangeValueOperation, error) {
if stringIsEmpty(key) {
return nil, newIllegalArgumentError("The key argument must have value")
}
return &GetCompareExchangeValueOperation{
_clazz: clazz,
_key: key,
}, nil
}
func (o *GetCompareExchangeValueOperation) GetCommand(store *DocumentStore, conventions *DocumentConventions, cache *httpCache) (RavenCommand, error) {
var err error
o.Command, err = NewGetCompareExchangeValueCommand(o._clazz, o._key, conventions)
return o.Command, err
}
var _ RavenCommand = &GetCompareExchangeValueCommand{}
type GetCompareExchangeValueCommand struct {
RavenCommandBase
_key string
_clazz reflect.Type
_conventions *DocumentConventions
Result *CompareExchangeValue
}
func NewGetCompareExchangeValueCommand(clazz reflect.Type, key string, conventions *DocumentConventions) (*GetCompareExchangeValueCommand, error) {
if stringIsEmpty(key) {
return nil, newIllegalArgumentError("The key argument must have value")
}
cmd := &GetCompareExchangeValueCommand{
RavenCommandBase: NewRavenCommandBase(),
_clazz: clazz,
_key: key,
_conventions: conventions,
}
cmd.IsReadRequest = true
return cmd, nil
}
func (c *GetCompareExchangeValueCommand) CreateRequest(node *ServerNode) (*http.Request, error) {
url := node.URL + "/databases/" + node.Database + "/cmpxchg?key=" + urlEncode(c._key)
return newHttpGet(url)
}
func (c *GetCompareExchangeValueCommand) SetResponse(response []byte, fromCache bool) error {
res, err := compareExchangeValueResultParserGetValue(c._clazz, response, c._conventions)
if err != nil {
return err
}
c.Result = res
return nil
}