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

Side by Side Diff: service/datastore/context.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 | « service/datastore/checkfilter.go ('k') | service/datastore/context_test.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 datastore 5 package datastore
6 6
7 import ( 7 import (
8 "github.com/luci/gae/service/info" 8 "github.com/luci/gae/service/info"
9 "golang.org/x/net/context" 9 "golang.org/x/net/context"
10 ) 10 )
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // GetRawNoTxn gets the RawInterface implementation from context. If there's a 57 // GetRawNoTxn gets the RawInterface implementation from context. If there's a
58 // currently active transaction, this will return a non-transactional connection 58 // currently active transaction, this will return a non-transactional connection
59 // to the datastore, otherwise this is the same as GetRaw. 59 // to the datastore, otherwise this is the same as GetRaw.
60 func GetRawNoTxn(c context.Context) RawInterface { 60 func GetRawNoTxn(c context.Context) RawInterface {
61 return getFiltered(c, false) 61 return getFiltered(c, false)
62 } 62 }
63 63
64 // Get gets the Interface implementation from context. 64 // Get gets the Interface implementation from context.
65 func Get(c context.Context) Interface { 65 func Get(c context.Context) Interface {
66 inf := info.Get(c) 66 inf := info.Get(c)
67 ns, _ := inf.GetNamespace()
67 return &datastoreImpl{ 68 return &datastoreImpl{
68 GetRaw(c), 69 GetRaw(c),
69 inf.FullyQualifiedAppID(), 70 inf.FullyQualifiedAppID(),
70 » » inf.GetNamespace(), 71 » » ns,
71 } 72 }
72 } 73 }
73 74
74 // GetNoTxn gets the Interface implementation from context. If there's a 75 // GetNoTxn gets the Interface implementation from context. If there's a
75 // currently active transaction, this will return a non-transactional connection 76 // currently active transaction, this will return a non-transactional connection
76 // to the datastore, otherwise this is the same as GetRaw. 77 // to the datastore, otherwise this is the same as GetRaw.
77 // Get gets the Interface implementation from context. 78 // Get gets the Interface implementation from context.
78 func GetNoTxn(c context.Context) Interface { 79 func GetNoTxn(c context.Context) Interface {
79 inf := info.Get(c) 80 inf := info.Get(c)
81 ns, _ := inf.GetNamespace()
80 return &datastoreImpl{ 82 return &datastoreImpl{
81 GetRawNoTxn(c), 83 GetRawNoTxn(c),
82 inf.FullyQualifiedAppID(), 84 inf.FullyQualifiedAppID(),
83 » » inf.GetNamespace(), 85 » » ns,
84 } 86 }
85 } 87 }
86 88
87 // SetRawFactory sets the function to produce Datastore instances, as returned b y 89 // SetRawFactory sets the function to produce Datastore instances, as returned b y
88 // the GetRaw method. 90 // the GetRaw method.
89 func SetRawFactory(c context.Context, rdsf RawFactory) context.Context { 91 func SetRawFactory(c context.Context, rdsf RawFactory) context.Context {
90 return context.WithValue(c, rawDatastoreKey, rdsf) 92 return context.WithValue(c, rawDatastoreKey, rdsf)
91 } 93 }
92 94
93 // SetRaw sets the current Datastore object in the context. Useful for testing 95 // SetRaw sets the current Datastore object in the context. Useful for testing
(...skipping 15 matching lines...) Expand all
109 func AddRawFilters(c context.Context, filts ...RawFilter) context.Context { 111 func AddRawFilters(c context.Context, filts ...RawFilter) context.Context {
110 if len(filts) == 0 { 112 if len(filts) == 0 {
111 return c 113 return c
112 } 114 }
113 cur := getCurFilters(c) 115 cur := getCurFilters(c)
114 newFilts := make([]RawFilter, 0, len(cur)+len(filts)) 116 newFilts := make([]RawFilter, 0, len(cur)+len(filts))
115 newFilts = append(newFilts, getCurFilters(c)...) 117 newFilts = append(newFilts, getCurFilters(c)...)
116 newFilts = append(newFilts, filts...) 118 newFilts = append(newFilts, filts...)
117 return context.WithValue(c, rawDatastoreFilterKey, newFilts) 119 return context.WithValue(c, rawDatastoreFilterKey, newFilts)
118 } 120 }
OLDNEW
« no previous file with comments | « service/datastore/checkfilter.go ('k') | service/datastore/context_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698