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

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

Issue 1916463004: impl/memory: Disallow empty namespace. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/gae@master
Patch Set: Rbase. Created 4 years, 8 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/prod/info.go ('k') | service/datastore/checkfilter.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"
10 "github.com/luci/luci-go/common/errors" 9 "github.com/luci/luci-go/common/errors"
11 "golang.org/x/net/context" 10 "golang.org/x/net/context"
12 "google.golang.org/appengine/datastore" 11 "google.golang.org/appengine/datastore"
13 ) 12 )
14 13
15 // useRDS adds a gae.RawDatastore implementation to context, accessible 14 // useRDS adds a gae.RawDatastore implementation to context, accessible
16 // by gae.GetDS(c) 15 // by gae.GetDS(c)
17 func useRDS(c context.Context) context.Context { 16 func useRDS(c context.Context) context.Context {
18 return ds.SetRawFactory(c, func(ci context.Context, wantTxn bool) ds.Raw Interface { 17 return ds.SetRawFactory(c, func(ci context.Context, wantTxn bool) ds.Raw Interface {
19 ns := info.Get(ci).GetNamespace()
20 maybeTxnCtx := AEContext(ci) 18 maybeTxnCtx := AEContext(ci)
21 19
22 if wantTxn { 20 if wantTxn {
23 » » » return rdsImpl{ci, maybeTxnCtx, ns} 21 » » » return rdsImpl{ci, maybeTxnCtx}
24 } 22 }
25 aeCtx := AEContextNoTxn(ci) 23 aeCtx := AEContextNoTxn(ci)
26 if maybeTxnCtx != aeCtx { 24 if maybeTxnCtx != aeCtx {
27 ci = context.WithValue(ci, prodContextKey, aeCtx) 25 ci = context.WithValue(ci, prodContextKey, aeCtx)
28 } 26 }
29 » » return rdsImpl{ci, aeCtx, ns} 27 » » return rdsImpl{ci, aeCtx}
30 }) 28 })
31 } 29 }
32 30
33 ////////// Datastore 31 ////////// Datastore
34 32
35 type rdsImpl struct { 33 type rdsImpl struct {
36 // userCtx is the context that has the luci/gae services and user object s in 34 // userCtx is the context that has the luci/gae services and user object s in
37 // it. 35 // it.
38 userCtx context.Context 36 userCtx context.Context
39 37
40 // aeCtx is the context with the appengine connection information in it. 38 // aeCtx is the context with the appengine connection information in it.
41 aeCtx context.Context 39 aeCtx context.Context
42
43 ns string
44 } 40 }
45 41
46 func idxCallbacker(err error, amt int, cb func(idx int, err error)) error { 42 func idxCallbacker(err error, amt int, cb func(idx int, err error)) error {
47 if err == nil { 43 if err == nil {
48 for i := 0; i < amt; i++ { 44 for i := 0; i < amt; i++ {
49 cb(i, nil) 45 cb(i, nil)
50 } 46 }
51 return nil 47 return nil
52 } 48 }
53 err = errors.Fix(err) 49 err = errors.Fix(err)
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 func (d rdsImpl) RunInTransaction(f func(c context.Context) error, opts *ds.Tran sactionOptions) error { 230 func (d rdsImpl) RunInTransaction(f func(c context.Context) error, opts *ds.Tran sactionOptions) error {
235 ropts := (*datastore.TransactionOptions)(opts) 231 ropts := (*datastore.TransactionOptions)(opts)
236 return datastore.RunInTransaction(d.aeCtx, func(c context.Context) error { 232 return datastore.RunInTransaction(d.aeCtx, func(c context.Context) error {
237 return f(context.WithValue(d.userCtx, prodContextKey, c)) 233 return f(context.WithValue(d.userCtx, prodContextKey, c))
238 }, ropts) 234 }, ropts)
239 } 235 }
240 236
241 func (d rdsImpl) Testable() ds.Testable { 237 func (d rdsImpl) Testable() ds.Testable {
242 return nil 238 return nil
243 } 239 }
OLDNEW
« no previous file with comments | « impl/prod/info.go ('k') | service/datastore/checkfilter.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698