OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 package meta | |
6 | |
7 import ( | |
8 "appengine/datastore" | |
9 | |
10 "infra/gae/libs/context" | |
11 "infra/libs/errors" | |
12 ) | |
13 | |
14 var mark = errors.MakeMarkFn("eg") | |
15 | |
16 // EntityGroupMeta is the model corresponding to the __entity_group__ model in | |
17 // appengine. You shouldn't need to use this struct directly, but instead should | |
18 // use GetEntityGroupVersion. | |
19 type EntityGroupMeta struct { | |
20 _kind string `datastore:"-" goon:"kind,__entity_group__"` | |
21 | |
22 ID int64 `datastore:"-" goon:"id"` | |
23 Parent *datastore.Key `datastore:"-" goon:"parent"` | |
24 | |
25 Version int64 `datastore:"__version__"` | |
26 } | |
27 | |
28 // GetEntityGroupVersion returns the entity group version for the entity group | |
29 // containing root. If the entity group doesn't exist, this function will return | |
30 // zero and a nil error. | |
31 func GetEntityGroupVersion(c context.SingleReadWriter, root *datastore.Key) (int 64, error) { | |
32 for root.Parent() != nil { | |
33 root = root.Parent() | |
34 } | |
35 egm := &EntityGroupMeta{ID: 1, Parent: root} | |
36 err := c.Get(egm) | |
37 if err != datastore.ErrNoSuchEntity { | |
38 err = mark(err) | |
Vadim Sh.
2015/03/06 03:01:48
nit: 'mark' is too general. It is ok in such small
| |
39 } else { | |
40 // this is OK for callers. The version of the entity group is ef fectively 0 | |
41 // in this case. | |
42 err = nil | |
43 } | |
44 return egm.Version, err | |
45 } | |
OLD | NEW |