forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_compare_exchange_values_operation.go
106 lines (85 loc) · 2.72 KB
/
get_compare_exchange_values_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
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
package ravendb
import (
"net/http"
"reflect"
"strconv"
)
var (
_ IOperation = &GetCompareExchangeValuesOperation{}
)
type GetCompareExchangeValuesOperation struct {
Command *GetCompareExchangeValuesCommand
_clazz reflect.Type
_keys []string
_startWith string
_start int // -1 for unset
_pageSize int
}
func NewGetCompareExchangeValuesOperationWithKeys(clazz reflect.Type, keys []string) (*GetCompareExchangeValuesOperation, error) {
if len(keys) == 0 {
return nil, newIllegalArgumentError("Keys cannot be null or empty array")
}
return &GetCompareExchangeValuesOperation{
_keys: keys,
_clazz: clazz,
_start: -1,
_pageSize: 0,
_startWith: "",
}, nil
}
func NewGetCompareExchangeValuesOperation(clazz reflect.Type, startWith string, start int, pageSize int) (*GetCompareExchangeValuesOperation, error) {
return &GetCompareExchangeValuesOperation{
_clazz: clazz,
_start: start,
_pageSize: pageSize,
_startWith: startWith,
}, nil
}
var _ RavenCommand = &GetCompareExchangeValuesCommand{}
func (o *GetCompareExchangeValuesOperation) GetCommand(store *DocumentStore, conventions *DocumentConventions, cache *httpCache) (RavenCommand, error) {
var err error
o.Command, err = NewGetCompareExchangeValuesCommand(o, conventions)
return o.Command, err
}
type GetCompareExchangeValuesCommand struct {
RavenCommandBase
_operation *GetCompareExchangeValuesOperation
_conventions *DocumentConventions
Result map[string]*CompareExchangeValue
}
func NewGetCompareExchangeValuesCommand(operation *GetCompareExchangeValuesOperation, conventions *DocumentConventions) (*GetCompareExchangeValuesCommand, error) {
cmd := &GetCompareExchangeValuesCommand{
RavenCommandBase: NewRavenCommandBase(),
_operation: operation,
_conventions: conventions,
}
cmd.IsReadRequest = true
return cmd, nil
}
func (c *GetCompareExchangeValuesCommand) CreateRequest(node *ServerNode) (*http.Request, error) {
url := node.URL + "/databases/" + node.Database + "/cmpxchg?"
if c._operation._keys != nil {
for _, key := range c._operation._keys {
url += "&key=" + urlUtilsEscapeDataString(key)
}
} else {
if !stringIsEmpty(c._operation._startWith) {
url += "&startsWith=" + urlUtilsEscapeDataString(c._operation._startWith)
}
if c._operation._start >= 0 {
url += "&start=" + strconv.Itoa(c._operation._start)
}
if c._operation._pageSize > 0 {
url += "&pageSize=" + strconv.Itoa(c._operation._pageSize)
}
}
return newHttpGet(url)
}
func (c *GetCompareExchangeValuesCommand) SetResponse(response []byte, fromCache bool) error {
res, err := compareExchangeValueResultParserGetValues(c._operation._clazz, response, c._conventions)
if err != nil {
return err
}
c.Result = res
return nil
}