| 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 memory | 5 package memory |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "errors" | 8 "errors" |
| 9 | 9 |
| 10 "golang.org/x/net/context" | 10 "golang.org/x/net/context" |
| 11 | 11 |
| 12 » rds "github.com/luci/gae/service/rawdatastore" | 12 » ds "github.com/luci/gae/service/datastore" |
| 13 ) | 13 ) |
| 14 | 14 |
| 15 //////////////////////////////////// public //////////////////////////////////// | 15 //////////////////////////////////// public //////////////////////////////////// |
| 16 | 16 |
| 17 // useRDS adds a gae.Datastore implementation to context, accessible | 17 // useRDS adds a gae.Datastore implementation to context, accessible |
| 18 // by gae.GetDS(c) | 18 // by gae.GetDS(c) |
| 19 func useRDS(c context.Context) context.Context { | 19 func useRDS(c context.Context) context.Context { |
| 20 » return rds.SetFactory(c, func(ic context.Context) rds.Interface { | 20 » return ds.SetRawFactory(c, func(ic context.Context) ds.RawInterface { |
| 21 dsd := cur(ic).Get(memContextDSIdx) | 21 dsd := cur(ic).Get(memContextDSIdx) |
| 22 | 22 |
| 23 ns := curGID(ic).namespace | 23 ns := curGID(ic).namespace |
| 24 if x, ok := dsd.(*dataStoreData); ok { | 24 if x, ok := dsd.(*dataStoreData); ok { |
| 25 return &dsImpl{x, ns, ic} | 25 return &dsImpl{x, ns, ic} |
| 26 } | 26 } |
| 27 return &txnDsImpl{dsd.(*txnDataStoreData), ns} | 27 return &txnDsImpl{dsd.(*txnDataStoreData), ns} |
| 28 }) | 28 }) |
| 29 } | 29 } |
| 30 | 30 |
| 31 //////////////////////////////////// dsImpl //////////////////////////////////// | 31 //////////////////////////////////// dsImpl //////////////////////////////////// |
| 32 | 32 |
| 33 // dsImpl exists solely to bind the current c to the datastore data. | 33 // dsImpl exists solely to bind the current c to the datastore data. |
| 34 type dsImpl struct { | 34 type dsImpl struct { |
| 35 data *dataStoreData | 35 data *dataStoreData |
| 36 ns string | 36 ns string |
| 37 c context.Context | 37 c context.Context |
| 38 } | 38 } |
| 39 | 39 |
| 40 var _ rds.Interface = (*dsImpl)(nil) | 40 var _ ds.RawInterface = (*dsImpl)(nil) |
| 41 | 41 |
| 42 func (d *dsImpl) DecodeKey(encoded string) (rds.Key, error) { | 42 func (d *dsImpl) DecodeKey(encoded string) (ds.Key, error) { |
| 43 » return rds.NewKeyFromEncoded(encoded) | 43 » return ds.NewKeyFromEncoded(encoded) |
| 44 } | 44 } |
| 45 | 45 |
| 46 func (d *dsImpl) NewKey(kind, stringID string, intID int64, parent rds.Key) rds.
Key { | 46 func (d *dsImpl) NewKey(kind, stringID string, intID int64, parent ds.Key) ds.Ke
y { |
| 47 » return rds.NewKey(globalAppID, d.ns, kind, stringID, intID, parent) | 47 » return ds.NewKey(globalAppID, d.ns, kind, stringID, intID, parent) |
| 48 } | 48 } |
| 49 | 49 |
| 50 func (d *dsImpl) PutMulti(keys []rds.Key, vals []rds.PropertyLoadSaver, cb rds.P
utMultiCB) error { | 50 func (d *dsImpl) PutMulti(keys []ds.Key, vals []ds.PropertyMap, cb ds.PutMultiCB
) error { |
| 51 d.data.putMulti(keys, vals, cb) | 51 d.data.putMulti(keys, vals, cb) |
| 52 return nil | 52 return nil |
| 53 } | 53 } |
| 54 | 54 |
| 55 func (d *dsImpl) GetMulti(keys []rds.Key, cb rds.GetMultiCB) error { | 55 func (d *dsImpl) GetMulti(keys []ds.Key, cb ds.GetMultiCB) error { |
| 56 d.data.getMulti(keys, cb) | 56 d.data.getMulti(keys, cb) |
| 57 return nil | 57 return nil |
| 58 } | 58 } |
| 59 | 59 |
| 60 func (d *dsImpl) DeleteMulti(keys []rds.Key, cb rds.DeleteMultiCB) error { | 60 func (d *dsImpl) DeleteMulti(keys []ds.Key, cb ds.DeleteMultiCB) error { |
| 61 d.data.delMulti(keys, cb) | 61 d.data.delMulti(keys, cb) |
| 62 return nil | 62 return nil |
| 63 } | 63 } |
| 64 | 64 |
| 65 func (d *dsImpl) NewQuery(kind string) rds.Query { | 65 func (d *dsImpl) NewQuery(kind string) ds.Query { |
| 66 return &queryImpl{ns: d.ns, kind: kind} | 66 return &queryImpl{ns: d.ns, kind: kind} |
| 67 } | 67 } |
| 68 | 68 |
| 69 func (d *dsImpl) Run(q rds.Query, cb rds.RunCB) error { | 69 func (d *dsImpl) Run(q ds.Query, cb ds.RawRunCB) error { |
| 70 return nil | 70 return nil |
| 71 /* | 71 /* |
| 72 rq := q.(*queryImpl) | 72 rq := q.(*queryImpl) |
| 73 rq = rq.normalize().checkCorrectness(d.ns, false) | 73 rq = rq.normalize().checkCorrectness(d.ns, false) |
| 74 return &queryIterImpl{rq} | 74 return &queryIterImpl{rq} |
| 75 */ | 75 */ |
| 76 } | 76 } |
| 77 | 77 |
| 78 ////////////////////////////////// txnDsImpl /////////////////////////////////// | 78 ////////////////////////////////// txnDsImpl /////////////////////////////////// |
| 79 | 79 |
| 80 type txnDsImpl struct { | 80 type txnDsImpl struct { |
| 81 data *txnDataStoreData | 81 data *txnDataStoreData |
| 82 ns string | 82 ns string |
| 83 } | 83 } |
| 84 | 84 |
| 85 var _ rds.Interface = (*txnDsImpl)(nil) | 85 var _ ds.RawInterface = (*txnDsImpl)(nil) |
| 86 | 86 |
| 87 func (d *txnDsImpl) DecodeKey(encoded string) (rds.Key, error) { | 87 func (d *txnDsImpl) DecodeKey(encoded string) (ds.Key, error) { |
| 88 » return rds.NewKeyFromEncoded(encoded) | 88 » return ds.NewKeyFromEncoded(encoded) |
| 89 } | 89 } |
| 90 | 90 |
| 91 func (d *txnDsImpl) NewKey(kind, stringID string, intID int64, parent rds.Key) r
ds.Key { | 91 func (d *txnDsImpl) NewKey(kind, stringID string, intID int64, parent ds.Key) ds
.Key { |
| 92 » return rds.NewKey(globalAppID, d.ns, kind, stringID, intID, parent) | 92 » return ds.NewKey(globalAppID, d.ns, kind, stringID, intID, parent) |
| 93 } | 93 } |
| 94 | 94 |
| 95 func (d *txnDsImpl) PutMulti(keys []rds.Key, vals []rds.PropertyLoadSaver, cb rd
s.PutMultiCB) error { | 95 func (d *txnDsImpl) PutMulti(keys []ds.Key, vals []ds.PropertyMap, cb ds.PutMult
iCB) error { |
| 96 return d.data.run(func() error { | 96 return d.data.run(func() error { |
| 97 d.data.putMulti(keys, vals, cb) | 97 d.data.putMulti(keys, vals, cb) |
| 98 return nil | 98 return nil |
| 99 }) | 99 }) |
| 100 } | 100 } |
| 101 | 101 |
| 102 func (d *txnDsImpl) GetMulti(keys []rds.Key, cb rds.GetMultiCB) error { | 102 func (d *txnDsImpl) GetMulti(keys []ds.Key, cb ds.GetMultiCB) error { |
| 103 return d.data.run(func() error { | 103 return d.data.run(func() error { |
| 104 return d.data.getMulti(keys, cb) | 104 return d.data.getMulti(keys, cb) |
| 105 }) | 105 }) |
| 106 } | 106 } |
| 107 | 107 |
| 108 func (d *txnDsImpl) DeleteMulti(keys []rds.Key, cb rds.DeleteMultiCB) error { | 108 func (d *txnDsImpl) DeleteMulti(keys []ds.Key, cb ds.DeleteMultiCB) error { |
| 109 return d.data.run(func() error { | 109 return d.data.run(func() error { |
| 110 return d.data.delMulti(keys, cb) | 110 return d.data.delMulti(keys, cb) |
| 111 }) | 111 }) |
| 112 } | 112 } |
| 113 | 113 |
| 114 func (d *txnDsImpl) Run(q rds.Query, cb rds.RunCB) error { | 114 func (d *txnDsImpl) Run(q ds.Query, cb ds.RawRunCB) error { |
| 115 rq := q.(*queryImpl) | 115 rq := q.(*queryImpl) |
| 116 if rq.ancestor == nil { | 116 if rq.ancestor == nil { |
| 117 return errors.New("memory: queries in transactions only support
ancestor queries") | 117 return errors.New("memory: queries in transactions only support
ancestor queries") |
| 118 } | 118 } |
| 119 panic("NOT IMPLEMENTED") | 119 panic("NOT IMPLEMENTED") |
| 120 } | 120 } |
| 121 | 121 |
| 122 func (*txnDsImpl) RunInTransaction(func(c context.Context) error, *rds.Transacti
onOptions) error { | 122 func (*txnDsImpl) RunInTransaction(func(c context.Context) error, *ds.Transactio
nOptions) error { |
| 123 return errors.New("datastore: nested transactions are not supported") | 123 return errors.New("datastore: nested transactions are not supported") |
| 124 } | 124 } |
| 125 | 125 |
| 126 func (d *txnDsImpl) NewQuery(kind string) rds.Query { | 126 func (d *txnDsImpl) NewQuery(kind string) ds.Query { |
| 127 return &queryImpl{ns: d.ns, kind: kind} | 127 return &queryImpl{ns: d.ns, kind: kind} |
| 128 } | 128 } |
| OLD | NEW |