forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlazy_aggregation_query_operation.go
75 lines (64 loc) · 2.27 KB
/
lazy_aggregation_query_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
package ravendb
var _ ILazyOperation = &LazyAggregationQueryOperation{}
// LazyAggregationQueryOperation represents lazy aggregation query operation
type LazyAggregationQueryOperation struct {
conventions *DocumentConventions
indexQuery *IndexQuery
invokeAfterQueryExecuted func(*QueryResult)
processResults func(*QueryResult, *DocumentConventions) (map[string]*FacetResult, error)
result map[string]*FacetResult
queryResult *QueryResult
requiresRetry bool
}
func newLazyAggregationQueryOperation(conventions *DocumentConventions, indexQuery *IndexQuery, invokeAfterQueryExecuted func(*QueryResult),
processResults func(*QueryResult, *DocumentConventions) (map[string]*FacetResult, error)) *LazyAggregationQueryOperation {
return &LazyAggregationQueryOperation{
conventions: conventions,
indexQuery: indexQuery,
invokeAfterQueryExecuted: invokeAfterQueryExecuted,
processResults: processResults,
}
}
// needed for ILazyOperation
func (o *LazyAggregationQueryOperation) createRequest() *getRequest {
request := &getRequest{
url: "/queries",
method: "POST",
query: "?queryHash=" + o.indexQuery.GetQueryHash(),
content: NewIndexQueryContent(o.conventions, o.indexQuery),
}
return request
}
// needed for ILazyOperation
func (o *LazyAggregationQueryOperation) getResult(results interface{}) error {
return setInterfaceToValue(results, o.result)
}
// needed for ILazyOperation
func (o *LazyAggregationQueryOperation) getQueryResult() *QueryResult {
return o.queryResult
}
// needed for ILazyOperation
func (o *LazyAggregationQueryOperation) isRequiresRetry() bool {
return o.requiresRetry
}
// needed for ILazyOperation
func (o *LazyAggregationQueryOperation) handleResponse(response *GetResponse) error {
if response.IsForceRetry {
o.result = nil
o.requiresRetry = true
return nil
}
var queryResult *QueryResult
err := jsonUnmarshal(response.Result, &queryResult)
if err != nil {
return err
}
return o.handleResponse2(queryResult)
}
func (o *LazyAggregationQueryOperation) handleResponse2(queryResult *QueryResult) error {
var err error
o.invokeAfterQueryExecuted(queryResult)
o.result, err = o.processResults(queryResult, o.conventions)
o.queryResult = queryResult
return err
}