| 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 "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 Loading... |
| 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 Loading... |
| 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 } |
| OLD | NEW |