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 "infra/gae/libs/wrapper" | 9 "infra/gae/libs/wrapper" |
10 goon_internal "infra/gae/libs/wrapper/memory/internal/goon" | 10 goon_internal "infra/gae/libs/wrapper/memory/internal/goon" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 return nil, nil, err | 145 return nil, nil, err |
146 } | 146 } |
147 key = newKey(key.Namespace(), key.Kind(), "", id, key.Parent()) | 147 key = newKey(key.Namespace(), key.Kind(), "", id, key.Parent()) |
148 } | 148 } |
149 | 149 |
150 return ents, key, nil | 150 return ents, key, nil |
151 } | 151 } |
152 | 152 |
153 func putPrelim(ns string, knr goon.KindNameResolver, src interface{}) (*datastor
e.Key, *propertyList, error) { | 153 func putPrelim(ns string, knr goon.KindNameResolver, src interface{}) (*datastor
e.Key, *propertyList, error) { |
154 key := newKeyObj(ns, knr, src) | 154 key := newKeyObj(ns, knr, src) |
155 » if !KeyCouldBeValid(ns, key, UserKeyOnly) { | 155 » if !keyCouldBeValid(ns, key, userKeyOnly) { |
156 // TODO(riannucci): different error for Put-ing to reserved Keys
? | 156 // TODO(riannucci): different error for Put-ing to reserved Keys
? |
157 return nil, nil, datastore.ErrInvalidKey | 157 return nil, nil, datastore.ErrInvalidKey |
158 } | 158 } |
159 | 159 |
160 data, err := toPL(src) | 160 data, err := toPL(src) |
161 return key, data, err | 161 return key, data, err |
162 } | 162 } |
163 | 163 |
164 func (d *dataStoreData) put(ns string, src interface{}) (*datastore.Key, error)
{ | 164 func (d *dataStoreData) put(ns string, src interface{}) (*datastore.Key, error)
{ |
165 key, plData, err := putPrelim(ns, d.KindNameResolver(), src) | 165 key, plData, err := putPrelim(ns, d.KindNameResolver(), src) |
(...skipping 23 matching lines...) Expand all Loading... |
189 return nil, err | 189 return nil, err |
190 } | 190 } |
191 | 191 |
192 ents.Set(keyBytes(noNS, key), dataBytes) | 192 ents.Set(keyBytes(noNS, key), dataBytes) |
193 | 193 |
194 return key, nil | 194 return key, nil |
195 } | 195 } |
196 | 196 |
197 func getInner(ns string, knr goon.KindNameResolver, dst interface{}, getColl fun
c(*datastore.Key) (*memCollection, error)) error { | 197 func getInner(ns string, knr goon.KindNameResolver, dst interface{}, getColl fun
c(*datastore.Key) (*memCollection, error)) error { |
198 key := newKeyObj(ns, knr, dst) | 198 key := newKeyObj(ns, knr, dst) |
199 » if !KeyValid(ns, key, AllowSpecialKeys) { | 199 » if !keyValid(ns, key, allowSpecialKeys) { |
200 return datastore.ErrInvalidKey | 200 return datastore.ErrInvalidKey |
201 } | 201 } |
202 | 202 |
203 ents, err := getColl(key) | 203 ents, err := getColl(key) |
204 if err != nil { | 204 if err != nil { |
205 return err | 205 return err |
206 } | 206 } |
207 if ents == nil { | 207 if ents == nil { |
208 return datastore.ErrNoSuchEntity | 208 return datastore.ErrNoSuchEntity |
209 } | 209 } |
(...skipping 12 matching lines...) Expand all Loading... |
222 return getInner(ns, d.KindNameResolver(), dst, func(*datastore.Key) (*me
mCollection, error) { | 222 return getInner(ns, d.KindNameResolver(), dst, func(*datastore.Key) (*me
mCollection, error) { |
223 d.rwlock.RLock() | 223 d.rwlock.RLock() |
224 s := d.store.Snapshot() | 224 s := d.store.Snapshot() |
225 d.rwlock.RUnlock() | 225 d.rwlock.RUnlock() |
226 | 226 |
227 return s.GetCollection("ents:" + ns), nil | 227 return s.GetCollection("ents:" + ns), nil |
228 }) | 228 }) |
229 } | 229 } |
230 | 230 |
231 func (d *dataStoreData) del(ns string, key *datastore.Key) error { | 231 func (d *dataStoreData) del(ns string, key *datastore.Key) error { |
232 » if !KeyValid(ns, key, UserKeyOnly) { | 232 » if !keyValid(ns, key, userKeyOnly) { |
233 return datastore.ErrInvalidKey | 233 return datastore.ErrInvalidKey |
234 } | 234 } |
235 | 235 |
236 keyBuf := keyBytes(noNS, key) | 236 keyBuf := keyBytes(noNS, key) |
237 | 237 |
238 d.rwlock.Lock() | 238 d.rwlock.Lock() |
239 defer d.rwlock.Unlock() | 239 defer d.rwlock.Unlock() |
240 | 240 |
241 ents := d.store.GetCollection("ents:" + ns) | 241 ents := d.store.GetCollection("ents:" + ns) |
242 if ents == nil { | 242 if ents == nil { |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 func (td *txnDataStoreData) get(ns string, dst interface{}) error { | 437 func (td *txnDataStoreData) get(ns string, dst interface{}) error { |
438 return getInner(ns, td.KindNameResolver(), dst, func(key *datastore.Key)
(*memCollection, error) { | 438 return getInner(ns, td.KindNameResolver(), dst, func(key *datastore.Key)
(*memCollection, error) { |
439 if err := td.writeMutation(true, key, nil); err != nil { | 439 if err := td.writeMutation(true, key, nil); err != nil { |
440 return nil, err | 440 return nil, err |
441 } | 441 } |
442 return td.snap.GetCollection("ents:" + ns), nil | 442 return td.snap.GetCollection("ents:" + ns), nil |
443 }) | 443 }) |
444 } | 444 } |
445 | 445 |
446 func (td *txnDataStoreData) del(ns string, key *datastore.Key) error { | 446 func (td *txnDataStoreData) del(ns string, key *datastore.Key) error { |
447 » if !KeyValid(ns, key, UserKeyOnly) { | 447 » if !keyValid(ns, key, userKeyOnly) { |
448 return datastore.ErrInvalidKey | 448 return datastore.ErrInvalidKey |
449 } | 449 } |
450 return td.writeMutation(false, key, nil) | 450 return td.writeMutation(false, key, nil) |
451 } | 451 } |
OLD | NEW |