| 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 » ds "github.com/luci/gae/service/datastore" |
| 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 RunInTransaction Entry | 18 RunInTransaction Entry |
| 19 Run Entry | 19 Run Entry |
| 20 DeleteMulti Entry | 20 DeleteMulti Entry |
| 21 GetMulti Entry | 21 GetMulti Entry |
| 22 PutMulti Entry | 22 PutMulti Entry |
| 23 } | 23 } |
| 24 | 24 |
| 25 type rdsCounter struct { | 25 type rdsCounter struct { |
| 26 c *RDSCounter | 26 c *RDSCounter |
| 27 | 27 |
| 28 » rds rds.Interface | 28 » ds ds.RawInterface |
| 29 } | 29 } |
| 30 | 30 |
| 31 var _ rds.Interface = (*rdsCounter)(nil) | 31 var _ ds.RawInterface = (*rdsCounter)(nil) |
| 32 | 32 |
| 33 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 ds.Key) d
s.Key { |
| 34 r.c.NewKey.up() | 34 r.c.NewKey.up() |
| 35 » return r.rds.NewKey(kind, stringID, intID, parent) | 35 » return r.ds.NewKey(kind, stringID, intID, parent) |
| 36 } | 36 } |
| 37 | 37 |
| 38 func (r *rdsCounter) DecodeKey(encoded string) (rds.Key, error) { | 38 func (r *rdsCounter) DecodeKey(encoded string) (ds.Key, error) { |
| 39 » ret, err := r.rds.DecodeKey(encoded) | 39 » ret, err := r.ds.DecodeKey(encoded) |
| 40 return ret, r.c.DecodeKey.up(err) | 40 return ret, r.c.DecodeKey.up(err) |
| 41 } | 41 } |
| 42 | 42 |
| 43 func (r *rdsCounter) NewQuery(kind string) rds.Query { | 43 func (r *rdsCounter) NewQuery(kind string) ds.Query { |
| 44 r.c.NewQuery.up() | 44 r.c.NewQuery.up() |
| 45 » return r.rds.NewQuery(kind) | 45 » return r.ds.NewQuery(kind) |
| 46 } | 46 } |
| 47 | 47 |
| 48 func (r *rdsCounter) Run(q rds.Query, cb rds.RunCB) error { | 48 func (r *rdsCounter) Run(q ds.Query, cb ds.RawRunCB) error { |
| 49 » return r.c.Run.up(r.rds.Run(q, cb)) | 49 » return r.c.Run.up(r.ds.Run(q, cb)) |
| 50 } | 50 } |
| 51 | 51 |
| 52 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 *ds.Tr
ansactionOptions) error { |
| 53 » return r.c.RunInTransaction.up(r.rds.RunInTransaction(f, opts)) | 53 » return r.c.RunInTransaction.up(r.ds.RunInTransaction(f, opts)) |
| 54 } | 54 } |
| 55 | 55 |
| 56 func (r *rdsCounter) DeleteMulti(keys []rds.Key, cb rds.DeleteMultiCB) error { | 56 func (r *rdsCounter) DeleteMulti(keys []ds.Key, cb ds.DeleteMultiCB) error { |
| 57 » return r.c.DeleteMulti.up(r.rds.DeleteMulti(keys, cb)) | 57 » return r.c.DeleteMulti.up(r.ds.DeleteMulti(keys, cb)) |
| 58 } | 58 } |
| 59 | 59 |
| 60 func (r *rdsCounter) GetMulti(keys []rds.Key, cb rds.GetMultiCB) error { | 60 func (r *rdsCounter) GetMulti(keys []ds.Key, cb ds.GetMultiCB) error { |
| 61 » return r.c.GetMulti.up(r.rds.GetMulti(keys, cb)) | 61 » return r.c.GetMulti.up(r.ds.GetMulti(keys, cb)) |
| 62 } | 62 } |
| 63 | 63 |
| 64 func (r *rdsCounter) PutMulti(keys []rds.Key, vals []rds.PropertyLoadSaver, cb r
ds.PutMultiCB) error { | 64 func (r *rdsCounter) PutMulti(keys []ds.Key, vals []ds.PropertyMap, cb ds.PutMul
tiCB) error { |
| 65 » return r.c.PutMulti.up(r.rds.PutMulti(keys, vals, cb)) | 65 » return r.c.PutMulti.up(r.ds.PutMulti(keys, vals, cb)) |
| 66 } | 66 } |
| 67 | 67 |
| 68 // FilterRDS installs a counter RawDatastore filter in the context. | 68 // FilterRDS installs a counter RawDatastore filter in the context. |
| 69 func FilterRDS(c context.Context) (context.Context, *RDSCounter) { | 69 func FilterRDS(c context.Context) (context.Context, *RDSCounter) { |
| 70 state := &RDSCounter{} | 70 state := &RDSCounter{} |
| 71 » return rds.AddFilters(c, func(ic context.Context, rds rds.Interface) rds
.Interface { | 71 » return ds.AddRawFilters(c, func(ic context.Context, ds ds.RawInterface)
ds.RawInterface { |
| 72 » » return &rdsCounter{state, rds} | 72 » » return &rdsCounter{state, ds} |
| 73 }), state | 73 }), state |
| 74 } | 74 } |
| OLD | NEW |