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

Side by Side Diff: impl/prod/raw_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: fix doc and naming 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
« no previous file with comments | « impl/prod/everything_test.go ('k') | impl/prod/taskqueue.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 prod 5 package prod
6 6
7 import ( 7 import (
8 ds "github.com/luci/gae/service/datastore" 8 ds "github.com/luci/gae/service/datastore"
9 "github.com/luci/gae/service/info" 9 "github.com/luci/gae/service/info"
10 "github.com/luci/luci-go/common/errors" 10 "github.com/luci/luci-go/common/errors"
11 "golang.org/x/net/context" 11 "golang.org/x/net/context"
12 "google.golang.org/appengine/datastore" 12 "google.golang.org/appengine/datastore"
13 ) 13 )
14 14
15 // useRDS adds a gae.RawDatastore implementation to context, accessible 15 // useRDS adds a gae.RawDatastore implementation to context, accessible
16 // by gae.GetDS(c) 16 // by gae.GetDS(c)
17 func useRDS(c context.Context) context.Context { 17 func useRDS(c context.Context) context.Context {
18 » return ds.SetRawFactory(c, func(ci context.Context) ds.RawInterface { 18 » return ds.SetRawFactory(c, func(ci context.Context, wantTxn bool) ds.Raw Interface {
19 » » return rdsImpl{ci, AEContext(ci), info.Get(ci).GetNamespace()} 19 » » ns := info.Get(ci).GetNamespace()
20 » » maybeTxnCtx := AEContext(ci)
21
22 » » if wantTxn {
23 » » » return rdsImpl{ci, maybeTxnCtx, ns}
24 » » }
25 » » aeCtx := AEContextNoTxn(ci)
26 » » if maybeTxnCtx != aeCtx {
27 » » » ci = context.WithValue(ci, prodContextKey, aeCtx)
28 » » }
29 » » return rdsImpl{ci, aeCtx, ns}
20 }) 30 })
21 } 31 }
22 32
23 ////////// Datastore 33 ////////// Datastore
24 34
25 type rdsImpl struct { 35 type rdsImpl struct {
26 // userCtx is the context that has the luci/gae services and user object s in 36 // userCtx is the context that has the luci/gae services and user object s in
27 // it. 37 // it.
28 userCtx context.Context 38 userCtx context.Context
29 39
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 q, err := d.fixQuery(fq) 226 q, err := d.fixQuery(fq)
217 if err != nil { 227 if err != nil {
218 return 0, err 228 return 0, err
219 } 229 }
220 ret, err := q.Count(d.aeCtx) 230 ret, err := q.Count(d.aeCtx)
221 return int64(ret), err 231 return int64(ret), err
222 } 232 }
223 233
224 func (d rdsImpl) RunInTransaction(f func(c context.Context) error, opts *ds.Tran sactionOptions) error { 234 func (d rdsImpl) RunInTransaction(f func(c context.Context) error, opts *ds.Tran sactionOptions) error {
225 ropts := (*datastore.TransactionOptions)(opts) 235 ropts := (*datastore.TransactionOptions)(opts)
226 » return datastore.RunInTransaction(d.aeCtx, func(aeCtx context.Context) e rror { 236 » return datastore.RunInTransaction(d.aeCtx, func(c context.Context) error {
227 » » return f(context.WithValue(d.userCtx, prodContextKey, aeCtx)) 237 » » return f(context.WithValue(d.userCtx, prodContextKey, c))
228 }, ropts) 238 }, ropts)
229 } 239 }
230 240
231 func (d rdsImpl) Testable() ds.Testable { 241 func (d rdsImpl) Testable() ds.Testable {
232 return nil 242 return nil
233 } 243 }
OLDNEW
« no previous file with comments | « impl/prod/everything_test.go ('k') | impl/prod/taskqueue.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698