| OLD | NEW |
| 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 "golang.org/x/net/context" | 9 "golang.org/x/net/context" |
| 9 ) | 10 ) |
| 10 | 11 |
| 11 type key int | 12 type key int |
| 12 | 13 |
| 13 var ( | 14 var ( |
| 14 rawDatastoreKey key | 15 rawDatastoreKey key |
| 15 rawDatastoreFilterKey key = 1 | 16 rawDatastoreFilterKey key = 1 |
| 16 ) | 17 ) |
| 17 | 18 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 40 return nil | 41 return nil |
| 41 } | 42 } |
| 42 for _, f := range getCurFilters(c) { | 43 for _, f := range getCurFilters(c) { |
| 43 ret = f(c, ret) | 44 ret = f(c, ret) |
| 44 } | 45 } |
| 45 return applyCheckFilter(c, ret) | 46 return applyCheckFilter(c, ret) |
| 46 } | 47 } |
| 47 | 48 |
| 48 // Get gets the Interface implementation from context. | 49 // Get gets the Interface implementation from context. |
| 49 func Get(c context.Context) Interface { | 50 func Get(c context.Context) Interface { |
| 50 » return &datastoreImpl{GetRaw(c)} | 51 » inf := info.Get(c) |
| 52 » return &datastoreImpl{ |
| 53 » » GetRaw(c), |
| 54 » » inf.FullyQualifiedAppID(), |
| 55 » » inf.GetNamespace(), |
| 56 » } |
| 51 } | 57 } |
| 52 | 58 |
| 53 // SetRawFactory sets the function to produce Datastore instances, as returned b
y | 59 // SetRawFactory sets the function to produce Datastore instances, as returned b
y |
| 54 // the GetRaw method. | 60 // the GetRaw method. |
| 55 func SetRawFactory(c context.Context, rdsf RawFactory) context.Context { | 61 func SetRawFactory(c context.Context, rdsf RawFactory) context.Context { |
| 56 return context.WithValue(c, rawDatastoreKey, rdsf) | 62 return context.WithValue(c, rawDatastoreKey, rdsf) |
| 57 } | 63 } |
| 58 | 64 |
| 59 // SetRaw sets the current Datastore object in the context. Useful for testing | 65 // SetRaw sets the current Datastore object in the context. Useful for testing |
| 60 // with a quick mock. This is just a shorthand SetRawFactory invocation to set | 66 // with a quick mock. This is just a shorthand SetRawFactory invocation to set |
| (...skipping 14 matching lines...) Expand all Loading... |
| 75 func AddRawFilters(c context.Context, filts ...RawFilter) context.Context { | 81 func AddRawFilters(c context.Context, filts ...RawFilter) context.Context { |
| 76 if len(filts) == 0 { | 82 if len(filts) == 0 { |
| 77 return c | 83 return c |
| 78 } | 84 } |
| 79 cur := getCurFilters(c) | 85 cur := getCurFilters(c) |
| 80 newFilts := make([]RawFilter, 0, len(cur)+len(filts)) | 86 newFilts := make([]RawFilter, 0, len(cur)+len(filts)) |
| 81 newFilts = append(newFilts, getCurFilters(c)...) | 87 newFilts = append(newFilts, getCurFilters(c)...) |
| 82 newFilts = append(newFilts, filts...) | 88 newFilts = append(newFilts, filts...) |
| 83 return context.WithValue(c, rawDatastoreFilterKey, newFilts) | 89 return context.WithValue(c, rawDatastoreFilterKey, newFilts) |
| 84 } | 90 } |
| OLD | NEW |