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 | 10 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 // NewDatastore creates a new standalone memory implementation of the datastore, | 46 // NewDatastore creates a new standalone memory implementation of the datastore, |
47 // suitable for embedding for doing in-memory data organization. | 47 // suitable for embedding for doing in-memory data organization. |
48 // | 48 // |
49 // It's configured by default with the following settings: | 49 // It's configured by default with the following settings: |
50 // * AutoIndex(true) | 50 // * AutoIndex(true) |
51 // * Consistent(true) | 51 // * Consistent(true) |
52 // * DisableSpecialEntities(true) | 52 // * DisableSpecialEntities(true) |
53 // | 53 // |
54 // These settings can of course be changed by using the Testable() interface. | 54 // These settings can of course be changed by using the Testable() interface. |
55 func NewDatastore(aid, ns string) (ds.Interface, error) { | 55 func NewDatastore(inf info.Interface) ds.Interface { |
56 » ctx := UseWithAppID(context.Background(), aid) | 56 » fqAppID := inf.FullyQualifiedAppID() |
| 57 » ns, hasNS := inf.GetNamespace() |
57 | 58 |
58 » if ns != "" { | 59 » memctx := newMemContext(fqAppID) |
59 » » var err error | |
60 » » ctx, err = info.Get(ctx).Namespace(ns) | |
61 » » if err != nil { | |
62 » » » return nil, err | |
63 » » } | |
64 » } | |
65 | 60 |
66 » ret := ds.Get(ctx) | 61 » dsCtx := info.Set(context.Background(), inf) |
| 62 » rds := &dsImpl{memctx.Get(memContextDSIdx).(*dataStoreData), ns, hasNS,
dsCtx} |
| 63 |
| 64 » ret := ds.Get(ds.SetRaw(dsCtx, rds)) |
67 t := ret.Testable() | 65 t := ret.Testable() |
68 t.AutoIndex(true) | 66 t.AutoIndex(true) |
69 t.Consistent(true) | 67 t.Consistent(true) |
70 t.DisableSpecialEntities(true) | 68 t.DisableSpecialEntities(true) |
71 » return ret, nil | 69 |
| 70 » return ret |
72 } | 71 } |
73 | 72 |
74 //////////////////////////////////// dsImpl //////////////////////////////////// | 73 //////////////////////////////////// dsImpl //////////////////////////////////// |
75 | 74 |
76 // dsImpl exists solely to bind the current c to the datastore data. | 75 // dsImpl exists solely to bind the current c to the datastore data. |
77 type dsImpl struct { | 76 type dsImpl struct { |
78 data *dataStoreData | 77 data *dataStoreData |
79 ns string | 78 ns string |
80 hasNS bool | 79 hasNS bool |
81 c context.Context | 80 c context.Context |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 if ns == "" && hasNS { | 252 if ns == "" && hasNS { |
254 // The user has set an empty namespace. Datastore does not suppo
rt this | 253 // The user has set an empty namespace. Datastore does not suppo
rt this |
255 // for queries. | 254 // for queries. |
256 // | 255 // |
257 // Bug on file is: | 256 // Bug on file is: |
258 // https://code.google.com/p/googleappengine/issues/detail?id=12
914 | 257 // https://code.google.com/p/googleappengine/issues/detail?id=12
914 |
259 return errors.New("namespace may not be present and empty") | 258 return errors.New("namespace may not be present and empty") |
260 } | 259 } |
261 return nil | 260 return nil |
262 } | 261 } |
OLD | NEW |