| 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 memory | 5 package memory |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "errors" | 8 "errors" |
| 9 "fmt" | 9 "fmt" |
| 10 "infra/gae/libs/wrapper" | 10 "infra/gae/libs/wrapper" |
| 11 "strings" | 11 "strings" |
| 12 | 12 |
| 13 "github.com/mjibson/goon" | 13 "github.com/mjibson/goon" |
| 14 "golang.org/x/net/context" | 14 "golang.org/x/net/context" |
| 15 | 15 |
| 16 "appengine/datastore" | 16 "appengine/datastore" |
| 17 "appengine_internal" | 17 "appengine_internal" |
| 18 pb "appengine_internal/datastore" | 18 pb "appengine_internal/datastore" |
| 19 ) | 19 ) |
| 20 | 20 |
| 21 //////////////////////////////////// public //////////////////////////////////// | 21 //////////////////////////////////// public //////////////////////////////////// |
| 22 | 22 |
| 23 // UseDS adds a wrapper.Datastore implementation to context, accessible | 23 // useDS adds a wrapper.Datastore implementation to context, accessible |
| 24 // by wrapper.GetDS(c) | 24 // by wrapper.GetDS(c) |
| 25 func UseDS(c context.Context) context.Context { | 25 func useDS(c context.Context) context.Context { |
| 26 return wrapper.SetDSFactory(c, func(ic context.Context) wrapper.Datastor
e { | 26 return wrapper.SetDSFactory(c, func(ic context.Context) wrapper.Datastor
e { |
| 27 dsd := cur(ic).Get(memContextDSIdx) | 27 dsd := cur(ic).Get(memContextDSIdx) |
| 28 | 28 |
| 29 switch x := dsd.(type) { | 29 switch x := dsd.(type) { |
| 30 case *dataStoreData: | 30 case *dataStoreData: |
| 31 return &dsImpl{wrapper.DummyDS(), x, curGID(ic).namespac
e, ic} | 31 return &dsImpl{wrapper.DummyDS(), x, curGID(ic).namespac
e, ic} |
| 32 case *txnDataStoreData: | 32 case *txnDataStoreData: |
| 33 return &txnDsImpl{wrapper.DummyDS(), x, curGID(ic).names
pace} | 33 return &txnDsImpl{wrapper.DummyDS(), x, curGID(ic).names
pace} |
| 34 default: | 34 default: |
| 35 panic(fmt.Errorf("DS: bad type: %v in context %v", dsd,
ic)) | 35 panic(fmt.Errorf("DS: bad type: %v in context %v", dsd,
ic)) |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 | 171 |
| 172 ////////////////////////////// private functions /////////////////////////////// | 172 ////////////////////////////// private functions /////////////////////////////// |
| 173 | 173 |
| 174 func newDSError(code pb.Error_ErrorCode, message ...string) *appengine_internal.
APIError { | 174 func newDSError(code pb.Error_ErrorCode, message ...string) *appengine_internal.
APIError { |
| 175 return &appengine_internal.APIError{ | 175 return &appengine_internal.APIError{ |
| 176 Detail: strings.Join(message, ""), | 176 Detail: strings.Join(message, ""), |
| 177 Service: "datastore_v3", | 177 Service: "datastore_v3", |
| 178 Code: int32(code), | 178 Code: int32(code), |
| 179 } | 179 } |
| 180 } | 180 } |
| OLD | NEW |