Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: service/datastore/interface.go

Issue 2007123002: datastore: Update AllocateIDs to take keys. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/gae@master
Patch Set: Add empty arg/key short-circuits for other varidic methods. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "golang.org/x/net/context" 8 "golang.org/x/net/context"
9 ) 9 )
10 10
11 // Interface is the 'user-friendly' interface to access the current filtered 11 // Interface is the 'user-friendly' interface to access the current filtered
12 // datastore service implementation. 12 // datastore service implementation.
13 // 13 //
14 // Note that in exchange for userfriendliness, this interface ends up doing 14 // Note that in exchange for userfriendliness, this interface ends up doing
15 // a lot of reflection. 15 // a lot of reflection.
16 // 16 //
17 // Methods taking 'interface{}' objects describe what a valid type for that 17 // Methods taking 'interface{}' objects describe what a valid type for that
18 // interface are in the comments. 18 // interface are in the comments.
19 // 19 //
20 // Struct objects passed in will be converted to PropertyLoadSaver interfaces 20 // Struct objects passed in will be converted to PropertyLoadSaver interfaces
21 // using this package's GetPLS function. 21 // using this package's GetPLS function.
22 type Interface interface { 22 type Interface interface {
23 // AllocateIDs allows you to allocate IDs from the datastore without put ting 23 // AllocateIDs allows you to allocate IDs from the datastore without put ting
24 » // any data. `incomplete` must be a PartialValid Key. If there's no erro r, 24 » // any data.
25 » // a contiguous block of IDs of n length starting at `start` will be res erved 25 » //
26 » // indefinitely for the user application code for use in new keys. The 26 » // A partial valid key will be constructed from each entity's kind and p arent,
27 » // appengine automatic ID generator will never automatically assign thes e IDs 27 » // if present. An allocation will then be performed against the datastor e for
28 » // for Keys of this type. 28 » // each key, and the partial key will be populated with a unique integer ID.
29 » AllocateIDs(incomplete *Key, n int) (start int64, err error) 29 » // The resulting keys will be applied to their objects using PopulateKey . If
30 » // successful, any existing ID will be destroyed.
31 » //
32 » // If the object is supplied that cannot accept an integer key, this met hod
33 » // will panic.
34 » //
35 » // ent must be one of:
36 » //» - *S where S is a struct
37 » //» - *P where *P is a concrete type implementing PropertyLoadSaver
38 » //» - []S or []*S where S is a struct
39 » //» - []P or []*P where *P is a concrete type implementing PropertyL oadSaver
40 » //» - []I where i is some interface type. Each element of the slice must
41 » //» be non-nil, and its underlying type must be either *S or *P.
42 » //» - *Key to populate a partial-valid key.
iannucci 2016/06/14 01:46:04 how can this work? Does it modify the Key in place
dnj (Google) 2016/06/14 04:24:18 Oh good point. Crap, okay, I'll remove this option
43 » //» - []*Key, to populate a slice of partial-valid keys.
44 » //
45 » // If an error is encountered, the returned error value will depend on t he
46 » // input arguments. If one argument is supplied, the result will be the
47 » // encountered error type. If multiple arguments are supplied, the resul t will
48 » // be a MultiError whose error index corresponds to the argument in whic h the
49 » // error was encountered.
50 » //
51 » // If an ent argument is a slice, its error type will be a MultiError. N ote
52 » // that in the scenario where multiple slices are provided, this will re turn a
53 » // MultiError containing a nested MultiError for each slice argument.
54 » AllocateIDs(ent ...interface{}) error
30 55
31 // KeyForObj extracts a key from src. 56 // KeyForObj extracts a key from src.
32 // 57 //
33 // It is the same as KeyForObjErr, except that if KeyForObjErr would hav e 58 // It is the same as KeyForObjErr, except that if KeyForObjErr would hav e
34 // returned an error, this method panics. It's safe to use if you know t hat 59 // returned an error, this method panics. It's safe to use if you know t hat
35 // src statically meets the metadata constraints described by KeyForObjE rr. 60 // src statically meets the metadata constraints described by KeyForObjE rr.
36 KeyForObj(src interface{}) *Key 61 KeyForObj(src interface{}) *Key
37 62
38 // MakeKey is a convenience method for manufacturing a *Key. It should o nly be 63 // MakeKey is a convenience method for manufacturing a *Key. It should o nly be
39 // used when elems... is known statically (e.g. in the code) to be corre ct. 64 // used when elems... is known statically (e.g. in the code) to be corre ct.
40 // 65 //
41 // elems is pairs of (string, string|int|int32|int64) pairs, which corre spond 66 // elems is pairs of (string, string|int|int32|int64) pairs, which corre spond
42 // to Kind/id pairs. Example: 67 // to Kind/id pairs. Example:
43 // dstore.MakeKey("Parent", 1, "Child", "id") 68 // dstore.MakeKey("Parent", 1, "Child", "id")
44 // 69 //
45 // Would create the key: 70 // Would create the key:
46 // <current appID>:<current Namespace>:/Parent,1/Child,id 71 // <current appID>:<current Namespace>:/Parent,1/Child,id
47 // 72 //
48 // If elems is not parsable (e.g. wrong length, wrong types, etc.) this method 73 // If elems is not parsable (e.g. wrong length, wrong types, etc.) this method
49 // will panic. 74 // will panic.
50 MakeKey(elems ...interface{}) *Key 75 MakeKey(elems ...interface{}) *Key
51 76
52 // NewKey constructs a new key in the current appID/Namespace, using the 77 // NewKey constructs a new key in the current appID/Namespace, using the
53 // specified parameters. 78 // specified parameters.
54 NewKey(kind, stringID string, intID int64, parent *Key) *Key 79 NewKey(kind, stringID string, intID int64, parent *Key) *Key
55 80
81 // NewIncompleteKeys allocates count incomplete keys sharing the same ki nd and
82 // parent. It is useful as input to AllocateIDs.
83 NewIncompleteKeys(count int, kind string, parent *Key) []*Key
84
56 // NewKeyToks constructs a new key in the current appID/Namespace, using the 85 // NewKeyToks constructs a new key in the current appID/Namespace, using the
57 // specified key tokens. 86 // specified key tokens.
58 NewKeyToks([]KeyTok) *Key 87 NewKeyToks([]KeyTok) *Key
59 88
60 // KeyForObjErr extracts a key from src. 89 // KeyForObjErr extracts a key from src.
61 // 90 //
62 // src must be one of: 91 // src must be one of:
63 // - *S where S is a struct 92 // - *S where S is a struct
64 // - a PropertyLoadSaver 93 // - a PropertyLoadSaver
65 // 94 //
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 // - []S or []*S where S is a struct 226 // - []S or []*S where S is a struct
198 // - []P or []*P where *P is a concrete type implementing PropertyLoad Saver 227 // - []P or []*P where *P is a concrete type implementing PropertyLoad Saver
199 // - []I where I is some interface type. Each element of the slice mus t 228 // - []I where I is some interface type. Each element of the slice mus t
200 // be non-nil, and its underlying type must be either *S or *P. 229 // be non-nil, and its underlying type must be either *S or *P.
201 // 230 //
202 // NOTE: GetMulti is obsolete. The vararg-accepting Get should be used 231 // NOTE: GetMulti is obsolete. The vararg-accepting Get should be used
203 // instead. This is left for backwards compatibility, but will be remove d from 232 // instead. This is left for backwards compatibility, but will be remove d from
204 // this interface at some point in the future. 233 // this interface at some point in the future.
205 GetMulti(dst interface{}) error 234 GetMulti(dst interface{}) error
206 235
207 » // Put inserts a single object into the datastore 236 » // Put writes objects into the datastore.
208 // 237 //
209 // src must be one of: 238 // src must be one of:
210 // - *S where S is a struct 239 // - *S where S is a struct
211 // - *P where *P is a concrete type implementing PropertyLoadSaver 240 // - *P where *P is a concrete type implementing PropertyLoadSaver
212 // - []S or []*S where S is a struct 241 // - []S or []*S where S is a struct
213 // - []P or []*P where *P is a concrete type implementing PropertyL oadSaver 242 // - []P or []*P where *P is a concrete type implementing PropertyL oadSaver
214 // - []I where i is some interface type. Each element of the slice must 243 // - []I where i is some interface type. Each element of the slice must
215 // be non-nil, and its underlying type must be either *S or *P. 244 // be non-nil, and its underlying type must be either *S or *P.
216 // 245 //
217 // A *Key will be extracted from src via KeyForObj. If 246 // A *Key will be extracted from src via KeyForObj. If
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 309
281 // Testable returns the Testable interface for the implementation, or ni l if 310 // Testable returns the Testable interface for the implementation, or ni l if
282 // there is none. 311 // there is none.
283 Testable() Testable 312 Testable() Testable
284 313
285 // Raw returns the underlying RawInterface. The Interface and RawInterfa ce may 314 // Raw returns the underlying RawInterface. The Interface and RawInterfa ce may
286 // be used interchangably; there's no danger of interleaving access to t he 315 // be used interchangably; there's no danger of interleaving access to t he
287 // datastore via the two. 316 // datastore via the two.
288 Raw() RawInterface 317 Raw() RawInterface
289 } 318 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698