Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Side by Side Diff: impl/memory/raw_datastore.go

Issue 1281173002: Refactor: Rename some files. (Closed) Base URL: https://github.com/luci/gae.git@tweak_testable
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « impl/memory/plist_test.go ('k') | impl/memory/raw_datastore_data.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 package memory
6
7 import (
8 "errors"
9
10 "golang.org/x/net/context"
11
12 ds "github.com/luci/gae/service/datastore"
13 )
14
15 //////////////////////////////////// public ////////////////////////////////////
16
17 // useRDS adds a gae.Datastore implementation to context, accessible
18 // by gae.GetDS(c)
19 func useRDS(c context.Context) context.Context {
20 return ds.SetRawFactory(c, func(ic context.Context) ds.RawInterface {
21 dsd := cur(ic).Get(memContextDSIdx)
22
23 ns := curGID(ic).namespace
24 if x, ok := dsd.(*dataStoreData); ok {
25 return &dsImpl{x, ns, ic}
26 }
27 return &txnDsImpl{dsd.(*txnDataStoreData), ns}
28 })
29 }
30
31 //////////////////////////////////// dsImpl ////////////////////////////////////
32
33 // dsImpl exists solely to bind the current c to the datastore data.
34 type dsImpl struct {
35 data *dataStoreData
36 ns string
37 c context.Context
38 }
39
40 var _ ds.RawInterface = (*dsImpl)(nil)
41
42 func (d *dsImpl) DecodeKey(encoded string) (ds.Key, error) {
43 return ds.NewKeyFromEncoded(encoded)
44 }
45
46 func (d *dsImpl) NewKey(kind, stringID string, intID int64, parent ds.Key) ds.Ke y {
47 return ds.NewKey(globalAppID, d.ns, kind, stringID, intID, parent)
48 }
49
50 func (d *dsImpl) PutMulti(keys []ds.Key, vals []ds.PropertyMap, cb ds.PutMultiCB ) error {
51 d.data.putMulti(keys, vals, cb)
52 return nil
53 }
54
55 func (d *dsImpl) GetMulti(keys []ds.Key, _meta ds.MultiMetaGetter, cb ds.GetMult iCB) error {
56 d.data.getMulti(keys, cb)
57 return nil
58 }
59
60 func (d *dsImpl) DeleteMulti(keys []ds.Key, cb ds.DeleteMultiCB) error {
61 d.data.delMulti(keys, cb)
62 return nil
63 }
64
65 func (d *dsImpl) NewQuery(kind string) ds.Query {
66 return &queryImpl{ns: d.ns, kind: kind}
67 }
68
69 func (d *dsImpl) Run(q ds.Query, cb ds.RawRunCB) error {
70 return nil
71 /*
72 rq := q.(*queryImpl)
73 rq = rq.normalize().checkCorrectness(d.ns, false)
74 return &queryIterImpl{rq}
75 */
76 }
77
78 ////////////////////////////////// txnDsImpl ///////////////////////////////////
79
80 type txnDsImpl struct {
81 data *txnDataStoreData
82 ns string
83 }
84
85 var _ ds.RawInterface = (*txnDsImpl)(nil)
86
87 func (d *txnDsImpl) DecodeKey(encoded string) (ds.Key, error) {
88 return ds.NewKeyFromEncoded(encoded)
89 }
90
91 func (d *txnDsImpl) NewKey(kind, stringID string, intID int64, parent ds.Key) ds .Key {
92 return ds.NewKey(globalAppID, d.ns, kind, stringID, intID, parent)
93 }
94
95 func (d *txnDsImpl) PutMulti(keys []ds.Key, vals []ds.PropertyMap, cb ds.PutMult iCB) error {
96 return d.data.run(func() error {
97 d.data.putMulti(keys, vals, cb)
98 return nil
99 })
100 }
101
102 func (d *txnDsImpl) GetMulti(keys []ds.Key, _meta ds.MultiMetaGetter, cb ds.GetM ultiCB) error {
103 return d.data.run(func() error {
104 return d.data.getMulti(keys, cb)
105 })
106 }
107
108 func (d *txnDsImpl) DeleteMulti(keys []ds.Key, cb ds.DeleteMultiCB) error {
109 return d.data.run(func() error {
110 return d.data.delMulti(keys, cb)
111 })
112 }
113
114 func (d *txnDsImpl) Run(q ds.Query, cb ds.RawRunCB) error {
115 rq := q.(*queryImpl)
116 if rq.ancestor == nil {
117 return errors.New("memory: queries in transactions only support ancestor queries")
118 }
119 panic("NOT IMPLEMENTED")
120 }
121
122 func (*txnDsImpl) RunInTransaction(func(c context.Context) error, *ds.Transactio nOptions) error {
123 return errors.New("datastore: nested transactions are not supported")
124 }
125
126 func (d *txnDsImpl) NewQuery(kind string) ds.Query {
127 return &queryImpl{ns: d.ns, kind: kind}
128 }
OLDNEW
« no previous file with comments | « impl/memory/plist_test.go ('k') | impl/memory/raw_datastore_data.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698