| 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         "fmt" |    9         "fmt" | 
|   10  |   10  | 
|   11         "golang.org/x/net/context" |   11         "golang.org/x/net/context" | 
|   12  |   12  | 
|   13         ds "github.com/luci/gae/service/datastore" |   13         ds "github.com/luci/gae/service/datastore" | 
 |   14         "github.com/luci/gae/service/datastore/dskey" | 
|   14 ) |   15 ) | 
|   15  |   16  | 
|   16 //////////////////////////////////// public //////////////////////////////////// |   17 //////////////////////////////////// public //////////////////////////////////// | 
|   17  |   18  | 
|   18 // useRDS adds a gae.Datastore implementation to context, accessible |   19 // useRDS adds a gae.Datastore implementation to context, accessible | 
|   19 // by gae.GetDS(c) |   20 // by gae.GetDS(c) | 
|   20 func useRDS(c context.Context) context.Context { |   21 func useRDS(c context.Context) context.Context { | 
|   21         return ds.SetRawFactory(c, func(ic context.Context) ds.RawInterface { |   22         return ds.SetRawFactory(c, func(ic context.Context) ds.RawInterface { | 
|   22                 dsd := cur(ic).Get(memContextDSIdx) |   23                 dsd := cur(ic).Get(memContextDSIdx) | 
|   23  |   24  | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
|   34 // dsImpl exists solely to bind the current c to the datastore data. |   35 // dsImpl exists solely to bind the current c to the datastore data. | 
|   35 type dsImpl struct { |   36 type dsImpl struct { | 
|   36         data *dataStoreData |   37         data *dataStoreData | 
|   37         ns   string |   38         ns   string | 
|   38         c    context.Context |   39         c    context.Context | 
|   39 } |   40 } | 
|   40  |   41  | 
|   41 var _ ds.RawInterface = (*dsImpl)(nil) |   42 var _ ds.RawInterface = (*dsImpl)(nil) | 
|   42  |   43  | 
|   43 func (d *dsImpl) DecodeKey(encoded string) (ds.Key, error) { |   44 func (d *dsImpl) DecodeKey(encoded string) (ds.Key, error) { | 
|   44 »       return ds.NewKeyFromEncoded(encoded) |   45 »       return dskey.NewFromEncoded(encoded) | 
|   45 } |   46 } | 
|   46  |   47  | 
|   47 func (d *dsImpl) NewKey(kind, stringID string, intID int64, parent ds.Key) ds.Ke
     y { |   48 func (d *dsImpl) NewKey(kind, stringID string, intID int64, parent ds.Key) ds.Ke
     y { | 
|   48 »       return ds.NewKey(globalAppID, d.ns, kind, stringID, intID, parent) |   49 »       return dskey.New(globalAppID, d.ns, kind, stringID, intID, parent) | 
|   49 } |   50 } | 
|   50  |   51  | 
|   51 func (d *dsImpl) PutMulti(keys []ds.Key, vals []ds.PropertyMap, cb ds.PutMultiCB
     ) error { |   52 func (d *dsImpl) PutMulti(keys []ds.Key, vals []ds.PropertyMap, cb ds.PutMultiCB
     ) error { | 
|   52         d.data.putMulti(keys, vals, cb) |   53         d.data.putMulti(keys, vals, cb) | 
|   53         return nil |   54         return nil | 
|   54 } |   55 } | 
|   55  |   56  | 
|   56 func (d *dsImpl) GetMulti(keys []ds.Key, _meta ds.MultiMetaGetter, cb ds.GetMult
     iCB) error { |   57 func (d *dsImpl) GetMulti(keys []ds.Key, _meta ds.MultiMetaGetter, cb ds.GetMult
     iCB) error { | 
|   57         d.data.getMulti(keys, cb) |   58         d.data.getMulti(keys, cb) | 
|   58         return nil |   59         return nil | 
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  107 ////////////////////////////////// txnDsImpl /////////////////////////////////// |  108 ////////////////////////////////// txnDsImpl /////////////////////////////////// | 
|  108  |  109  | 
|  109 type txnDsImpl struct { |  110 type txnDsImpl struct { | 
|  110         data *txnDataStoreData |  111         data *txnDataStoreData | 
|  111         ns   string |  112         ns   string | 
|  112 } |  113 } | 
|  113  |  114  | 
|  114 var _ ds.RawInterface = (*txnDsImpl)(nil) |  115 var _ ds.RawInterface = (*txnDsImpl)(nil) | 
|  115  |  116  | 
|  116 func (d *txnDsImpl) DecodeKey(encoded string) (ds.Key, error) { |  117 func (d *txnDsImpl) DecodeKey(encoded string) (ds.Key, error) { | 
|  117 »       return ds.NewKeyFromEncoded(encoded) |  118 »       return dskey.NewFromEncoded(encoded) | 
|  118 } |  119 } | 
|  119  |  120  | 
|  120 func (d *txnDsImpl) NewKey(kind, stringID string, intID int64, parent ds.Key) ds
     .Key { |  121 func (d *txnDsImpl) NewKey(kind, stringID string, intID int64, parent ds.Key) ds
     .Key { | 
|  121 »       return ds.NewKey(globalAppID, d.ns, kind, stringID, intID, parent) |  122 »       return dskey.New(globalAppID, d.ns, kind, stringID, intID, parent) | 
|  122 } |  123 } | 
|  123  |  124  | 
|  124 func (d *txnDsImpl) PutMulti(keys []ds.Key, vals []ds.PropertyMap, cb ds.PutMult
     iCB) error { |  125 func (d *txnDsImpl) PutMulti(keys []ds.Key, vals []ds.PropertyMap, cb ds.PutMult
     iCB) error { | 
|  125         return d.data.run(func() error { |  126         return d.data.run(func() error { | 
|  126                 d.data.putMulti(keys, vals, cb) |  127                 d.data.putMulti(keys, vals, cb) | 
|  127                 return nil |  128                 return nil | 
|  128         }) |  129         }) | 
|  129 } |  130 } | 
|  130  |  131  | 
|  131 func (d *txnDsImpl) GetMulti(keys []ds.Key, _meta ds.MultiMetaGetter, cb ds.GetM
     ultiCB) error { |  132 func (d *txnDsImpl) GetMulti(keys []ds.Key, _meta ds.MultiMetaGetter, cb ds.GetM
     ultiCB) error { | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
|  158         return errors.New("datastore: nested transactions are not supported") |  159         return errors.New("datastore: nested transactions are not supported") | 
|  159 } |  160 } | 
|  160  |  161  | 
|  161 func (d *txnDsImpl) NewQuery(kind string) ds.Query { |  162 func (d *txnDsImpl) NewQuery(kind string) ds.Query { | 
|  162         return &queryImpl{ns: d.ns, kind: kind} |  163         return &queryImpl{ns: d.ns, kind: kind} | 
|  163 } |  164 } | 
|  164  |  165  | 
|  165 func (*txnDsImpl) Testable() ds.Testable { |  166 func (*txnDsImpl) Testable() ds.Testable { | 
|  166         return nil |  167         return nil | 
|  167 } |  168 } | 
| OLD | NEW |