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

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

Issue 1494223002: Add API to allow you to get the non-transactional datastore or taskqueue. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: Created 5 years 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
OLDNEW
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/info" 14 "github.com/luci/gae/service/info"
15 ) 15 )
16 16
17 //////////////////////////////////// public //////////////////////////////////// 17 //////////////////////////////////// public ////////////////////////////////////
18 18
19 // useRDS adds a gae.Datastore implementation to context, accessible 19 // useRDS adds a gae.Datastore implementation to context, accessible
20 // by gae.GetDS(c) 20 // by gae.GetDS(c)
21 func useRDS(c context.Context) context.Context { 21 func useRDS(c context.Context) context.Context {
22 » return ds.SetRawFactory(c, func(ic context.Context) ds.RawInterface { 22 » return ds.SetRawFactory(c, func(ic context.Context, wantTxn bool) ds.Raw Interface {
23 » » dsd := cur(ic).Get(memContextDSIdx) 23 » » ns := curGID(ic).namespace
24 » » maybeTxnCtx := cur(ic)
24 25
25 » » ns := curGID(ic).namespace 26 » » needResetCtx := false
27 » » if !wantTxn {
28 » » » rootctx := curNoTxn(ic)
29 » » » if rootctx != maybeTxnCtx {
30 » » » » needResetCtx = true
31 » » » » maybeTxnCtx = rootctx
32 » » » }
33 » » }
34
35 » » dsd := maybeTxnCtx.Get(memContextDSIdx)
26 if x, ok := dsd.(*dataStoreData); ok { 36 if x, ok := dsd.(*dataStoreData); ok {
37 if needResetCtx {
38 ic = context.WithValue(ic, memContextKey, maybeT xnCtx)
iannucci 2015/12/04 03:35:10 this is necessary so that .RunInTransaction will f
39 }
27 return &dsImpl{x, ns, ic} 40 return &dsImpl{x, ns, ic}
28 } 41 }
29 return &txnDsImpl{dsd.(*txnDataStoreData), ns} 42 return &txnDsImpl{dsd.(*txnDataStoreData), ns}
30 }) 43 })
31 } 44 }
32 45
33 // NewDatastore creates a new standalone memory implementation of the datastore, 46 // NewDatastore creates a new standalone memory implementation of the datastore,
34 // suitable for embedding for doing in-memory data organization. 47 // suitable for embedding for doing in-memory data organization.
35 // 48 //
36 // It's configured by default with the following settings: 49 // It's configured by default with the following settings:
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 return countQuery(fq, d.data.parent.aid, d.ns, true, d.data.snap, d.data .snap) 218 return countQuery(fq, d.data.parent.aid, d.ns, true, d.data.snap, d.data .snap)
206 } 219 }
207 220
208 func (*txnDsImpl) RunInTransaction(func(c context.Context) error, *ds.Transactio nOptions) error { 221 func (*txnDsImpl) RunInTransaction(func(c context.Context) error, *ds.Transactio nOptions) error {
209 return errors.New("datastore: nested transactions are not supported") 222 return errors.New("datastore: nested transactions are not supported")
210 } 223 }
211 224
212 func (*txnDsImpl) Testable() ds.Testable { 225 func (*txnDsImpl) Testable() ds.Testable {
213 return nil 226 return nil
214 } 227 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698