| 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 featureBreaker | 5 package featureBreaker |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "golang.org/x/net/context" | 8 "golang.org/x/net/context" |
| 9 | 9 |
| 10 » "github.com/luci/gae" | 10 » rds "github.com/luci/gae/service/rawdatastore" |
| 11 ) | 11 ) |
| 12 | 12 |
| 13 type rdsState struct { | 13 type rdsState struct { |
| 14 *state | 14 *state |
| 15 | 15 |
| 16 » gae.RawDatastore | 16 » rds.Interface |
| 17 } | 17 } |
| 18 | 18 |
| 19 func (r *rdsState) DecodeKey(encoded string) (ret gae.DSKey, err error) { | 19 func (r *rdsState) DecodeKey(encoded string) (ret rds.Key, err error) { |
| 20 err = r.run(func() (err error) { | 20 err = r.run(func() (err error) { |
| 21 » » ret, err = r.RawDatastore.DecodeKey(encoded) | 21 » » ret, err = r.Interface.DecodeKey(encoded) |
| 22 return | 22 return |
| 23 }) | 23 }) |
| 24 return | 24 return |
| 25 } | 25 } |
| 26 | 26 |
| 27 func (r *rdsState) GetAll(q gae.DSQuery, dst *[]gae.DSPropertyMap) (ret []gae.DS
Key, err error) { | 27 func (r *rdsState) GetAll(q rds.Query, dst *[]rds.PropertyMap) (ret []rds.Key, e
rr error) { |
| 28 err = r.run(func() (err error) { | 28 err = r.run(func() (err error) { |
| 29 » » ret, err = r.RawDatastore.GetAll(q, dst) | 29 » » ret, err = r.Interface.GetAll(q, dst) |
| 30 return | 30 return |
| 31 }) | 31 }) |
| 32 return | 32 return |
| 33 } | 33 } |
| 34 | 34 |
| 35 func (r *rdsState) Count(q gae.DSQuery) (ret int, err error) { | 35 func (r *rdsState) Count(q rds.Query) (ret int, err error) { |
| 36 err = r.run(func() (err error) { | 36 err = r.run(func() (err error) { |
| 37 » » ret, err = r.RawDatastore.Count(q) | 37 » » ret, err = r.Interface.Count(q) |
| 38 return | 38 return |
| 39 }) | 39 }) |
| 40 return | 40 return |
| 41 } | 41 } |
| 42 | 42 |
| 43 func (r *rdsState) RunInTransaction(f func(c context.Context) error, opts *gae.D
STransactionOptions) error { | 43 func (r *rdsState) RunInTransaction(f func(c context.Context) error, opts *rds.T
ransactionOptions) error { |
| 44 return r.run(func() error { | 44 return r.run(func() error { |
| 45 » » return r.RawDatastore.RunInTransaction(f, opts) | 45 » » return r.Interface.RunInTransaction(f, opts) |
| 46 }) | 46 }) |
| 47 } | 47 } |
| 48 | 48 |
| 49 func (r *rdsState) Put(key gae.DSKey, src gae.DSPropertyLoadSaver) (ret gae.DSKe
y, err error) { | 49 func (r *rdsState) Put(key rds.Key, src rds.PropertyLoadSaver) (ret rds.Key, err
error) { |
| 50 err = r.run(func() (err error) { | 50 err = r.run(func() (err error) { |
| 51 » » ret, err = r.RawDatastore.Put(key, src) | 51 » » ret, err = r.Interface.Put(key, src) |
| 52 return | 52 return |
| 53 }) | 53 }) |
| 54 return | 54 return |
| 55 } | 55 } |
| 56 | 56 |
| 57 func (r *rdsState) Get(key gae.DSKey, dst gae.DSPropertyLoadSaver) error { | 57 func (r *rdsState) Get(key rds.Key, dst rds.PropertyLoadSaver) error { |
| 58 return r.run(func() error { | 58 return r.run(func() error { |
| 59 » » return r.RawDatastore.Get(key, dst) | 59 » » return r.Interface.Get(key, dst) |
| 60 }) | 60 }) |
| 61 } | 61 } |
| 62 | 62 |
| 63 func (r *rdsState) Delete(key gae.DSKey) error { | 63 func (r *rdsState) Delete(key rds.Key) error { |
| 64 return r.run(func() error { | 64 return r.run(func() error { |
| 65 » » return r.RawDatastore.Delete(key) | 65 » » return r.Interface.Delete(key) |
| 66 }) | 66 }) |
| 67 } | 67 } |
| 68 | 68 |
| 69 func (r *rdsState) DeleteMulti(keys []gae.DSKey) error { | 69 func (r *rdsState) DeleteMulti(keys []rds.Key) error { |
| 70 return r.run(func() error { | 70 return r.run(func() error { |
| 71 » » return r.RawDatastore.DeleteMulti(keys) | 71 » » return r.Interface.DeleteMulti(keys) |
| 72 }) | 72 }) |
| 73 } | 73 } |
| 74 | 74 |
| 75 func (r *rdsState) GetMulti(keys []gae.DSKey, dst []gae.DSPropertyLoadSaver) err
or { | 75 func (r *rdsState) GetMulti(keys []rds.Key, dst []rds.PropertyLoadSaver) error { |
| 76 return r.run(func() error { | 76 return r.run(func() error { |
| 77 » » return r.RawDatastore.GetMulti(keys, dst) | 77 » » return r.Interface.GetMulti(keys, dst) |
| 78 }) | 78 }) |
| 79 } | 79 } |
| 80 | 80 |
| 81 func (r *rdsState) PutMulti(keys []gae.DSKey, src []gae.DSPropertyLoadSaver) (re
t []gae.DSKey, err error) { | 81 func (r *rdsState) PutMulti(keys []rds.Key, src []rds.PropertyLoadSaver) (ret []
rds.Key, err error) { |
| 82 err = r.run(func() (err error) { | 82 err = r.run(func() (err error) { |
| 83 » » ret, err = r.RawDatastore.PutMulti(keys, src) | 83 » » ret, err = r.Interface.PutMulti(keys, src) |
| 84 return | 84 return |
| 85 }) | 85 }) |
| 86 return | 86 return |
| 87 } | 87 } |
| 88 | 88 |
| 89 // FilterRDS installs a counter RawDatastore filter in the context. | 89 // FilterRDS installs a counter RawDatastore filter in the context. |
| 90 func FilterRDS(c context.Context, defaultError error) (context.Context, FeatureB
reaker) { | 90 func FilterRDS(c context.Context, defaultError error) (context.Context, FeatureB
reaker) { |
| 91 state := newState(defaultError) | 91 state := newState(defaultError) |
| 92 » return gae.AddRDSFilters(c, func(ic context.Context, RawDatastore gae.Ra
wDatastore) gae.RawDatastore { | 92 » return rds.AddFilters(c, func(ic context.Context, RawDatastore rds.Inter
face) rds.Interface { |
| 93 return &rdsState{state, RawDatastore} | 93 return &rdsState{state, RawDatastore} |
| 94 }), state | 94 }), state |
| 95 } | 95 } |
| OLD | NEW |