OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package count | 5 package count |
6 | 6 |
7 import ( | 7 import ( |
8 "golang.org/x/net/context" | 8 "golang.org/x/net/context" |
9 | 9 |
10 rds "github.com/luci/gae/service/rawdatastore" | 10 rds "github.com/luci/gae/service/rawdatastore" |
11 ) | 11 ) |
12 | 12 |
13 // RDSCounter is the counter object for the RawDatastore service. | 13 // RDSCounter is the counter object for the RawDatastore service. |
14 type RDSCounter struct { | 14 type RDSCounter struct { |
15 NewKey Entry | 15 NewKey Entry |
16 DecodeKey Entry | 16 DecodeKey Entry |
17 NewQuery Entry | 17 NewQuery Entry |
18 Count Entry | |
19 RunInTransaction Entry | 18 RunInTransaction Entry |
20 Run Entry | 19 Run Entry |
21 GetAll Entry | |
22 Put Entry | |
23 Get Entry | |
24 Delete Entry | |
25 DeleteMulti Entry | 20 DeleteMulti Entry |
26 GetMulti Entry | 21 GetMulti Entry |
27 PutMulti Entry | 22 PutMulti Entry |
28 } | 23 } |
29 | 24 |
30 type rdsCounter struct { | 25 type rdsCounter struct { |
31 c *RDSCounter | 26 c *RDSCounter |
32 | 27 |
33 rds rds.Interface | 28 rds rds.Interface |
34 } | 29 } |
35 | 30 |
36 var _ rds.Interface = (*rdsCounter)(nil) | 31 var _ rds.Interface = (*rdsCounter)(nil) |
37 | 32 |
38 func (r *rdsCounter) NewKey(kind, stringID string, intID int64, parent rds.Key)
rds.Key { | 33 func (r *rdsCounter) NewKey(kind, stringID string, intID int64, parent rds.Key)
rds.Key { |
39 r.c.NewKey.up() | 34 r.c.NewKey.up() |
40 return r.rds.NewKey(kind, stringID, intID, parent) | 35 return r.rds.NewKey(kind, stringID, intID, parent) |
41 } | 36 } |
42 | 37 |
43 func (r *rdsCounter) DecodeKey(encoded string) (rds.Key, error) { | 38 func (r *rdsCounter) DecodeKey(encoded string) (rds.Key, error) { |
44 ret, err := r.rds.DecodeKey(encoded) | 39 ret, err := r.rds.DecodeKey(encoded) |
45 return ret, r.c.DecodeKey.up(err) | 40 return ret, r.c.DecodeKey.up(err) |
46 } | 41 } |
47 | 42 |
48 func (r *rdsCounter) NewQuery(kind string) rds.Query { | 43 func (r *rdsCounter) NewQuery(kind string) rds.Query { |
49 r.c.NewQuery.up() | 44 r.c.NewQuery.up() |
50 return r.rds.NewQuery(kind) | 45 return r.rds.NewQuery(kind) |
51 } | 46 } |
52 | 47 |
53 func (r *rdsCounter) Run(q rds.Query) rds.Iterator { | 48 func (r *rdsCounter) Run(q rds.Query, cb rds.RunCB) error { |
54 » r.c.Run.up() | 49 » return r.c.Run.up(r.rds.Run(q, cb)) |
55 » return r.rds.Run(q) | |
56 } | |
57 | |
58 func (r *rdsCounter) GetAll(q rds.Query, dst *[]rds.PropertyMap) ([]rds.Key, err
or) { | |
59 » ret, err := r.rds.GetAll(q, dst) | |
60 » return ret, r.c.GetAll.up(err) | |
61 } | |
62 | |
63 func (r *rdsCounter) Count(q rds.Query) (int, error) { | |
64 » ret, err := r.rds.Count(q) | |
65 » return ret, r.c.Count.up(err) | |
66 } | 50 } |
67 | 51 |
68 func (r *rdsCounter) RunInTransaction(f func(context.Context) error, opts *rds.T
ransactionOptions) error { | 52 func (r *rdsCounter) RunInTransaction(f func(context.Context) error, opts *rds.T
ransactionOptions) error { |
69 return r.c.RunInTransaction.up(r.rds.RunInTransaction(f, opts)) | 53 return r.c.RunInTransaction.up(r.rds.RunInTransaction(f, opts)) |
70 } | 54 } |
71 | 55 |
72 func (r *rdsCounter) Put(key rds.Key, src rds.PropertyLoadSaver) (rds.Key, error
) { | 56 func (r *rdsCounter) DeleteMulti(keys []rds.Key, cb rds.DeleteMultiCB) error { |
73 » ret, err := r.rds.Put(key, src) | 57 » return r.c.DeleteMulti.up(r.rds.DeleteMulti(keys, cb)) |
74 » return ret, r.c.Put.up(err) | |
75 } | 58 } |
76 | 59 |
77 func (r *rdsCounter) Get(key rds.Key, dst rds.PropertyLoadSaver) error { | 60 func (r *rdsCounter) GetMulti(keys []rds.Key, cb rds.GetMultiCB) error { |
78 » return r.c.Get.up(r.rds.Get(key, dst)) | 61 » return r.c.GetMulti.up(r.rds.GetMulti(keys, cb)) |
79 } | 62 } |
80 | 63 |
81 func (r *rdsCounter) Delete(key rds.Key) error { | 64 func (r *rdsCounter) PutMulti(keys []rds.Key, vals []rds.PropertyLoadSaver, cb r
ds.PutMultiCB) error { |
82 » return r.c.Delete.up(r.rds.Delete(key)) | 65 » return r.c.PutMulti.up(r.rds.PutMulti(keys, vals, cb)) |
83 } | |
84 | |
85 func (r *rdsCounter) DeleteMulti(keys []rds.Key) error { | |
86 » return r.c.DeleteMulti.up(r.rds.DeleteMulti(keys)) | |
87 } | |
88 | |
89 func (r *rdsCounter) GetMulti(keys []rds.Key, dst []rds.PropertyLoadSaver) error
{ | |
90 » return r.c.GetMulti.up(r.rds.GetMulti(keys, dst)) | |
91 } | |
92 | |
93 func (r *rdsCounter) PutMulti(keys []rds.Key, src []rds.PropertyLoadSaver) ([]rd
s.Key, error) { | |
94 » ret, err := r.rds.PutMulti(keys, src) | |
95 » return ret, r.c.PutMulti.up(err) | |
96 } | 66 } |
97 | 67 |
98 // FilterRDS installs a counter RawDatastore filter in the context. | 68 // FilterRDS installs a counter RawDatastore filter in the context. |
99 func FilterRDS(c context.Context) (context.Context, *RDSCounter) { | 69 func FilterRDS(c context.Context) (context.Context, *RDSCounter) { |
100 state := &RDSCounter{} | 70 state := &RDSCounter{} |
101 return rds.AddFilters(c, func(ic context.Context, rds rds.Interface) rds
.Interface { | 71 return rds.AddFilters(c, func(ic context.Context, rds rds.Interface) rds
.Interface { |
102 return &rdsCounter{state, rds} | 72 return &rdsCounter{state, rds} |
103 }), state | 73 }), state |
104 } | 74 } |
OLD | NEW |