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 // +build appengine | |
6 | |
7 package meta | 5 package meta |
8 | 6 |
9 import ( | 7 import ( |
8 "golang.org/x/net/context" | |
M-A Ruel
2015/05/25 17:14:50
Why golang.org and github.com not be grouped toget
iannucci
2015/05/26 18:25:05
Ok, I was unsure of this. I was trying to do somet
M-A Ruel
2015/05/27 00:27:10
I prefer the result of the following:
pack everyt
| |
9 | |
10 "appengine/datastore" | 10 "appengine/datastore" |
11 | 11 |
12 "github.com/luci/luci-go/common/errors" | 12 "github.com/luci/luci-go/common/errors" |
13 | 13 |
14 » "infra/gae/libs/context" | 14 » "infra/gae/libs/wrapper" |
15 ) | 15 ) |
16 | 16 |
17 var mark = errors.MakeMarkFn("eg") | 17 var mark = errors.MakeMarkFn("eg") |
18 | 18 |
19 // EntityGroupMeta is the model corresponding to the __entity_group__ model in | 19 // EntityGroupMeta is the model corresponding to the __entity_group__ model in |
20 // appengine. You shouldn't need to use this struct directly, but instead should | 20 // appengine. You shouldn't need to use this struct directly, but instead should |
21 // use GetEntityGroupVersion. | 21 // use GetEntityGroupVersion. |
22 type EntityGroupMeta struct { | 22 type EntityGroupMeta struct { |
23 _kind string `datastore:"-" goon:"kind,__entity_group__"` | 23 _kind string `datastore:"-" goon:"kind,__entity_group__"` |
24 | 24 |
25 ID int64 `datastore:"-" goon:"id"` | 25 ID int64 `datastore:"-" goon:"id"` |
26 Parent *datastore.Key `datastore:"-" goon:"parent"` | 26 Parent *datastore.Key `datastore:"-" goon:"parent"` |
27 | 27 |
28 Version int64 `datastore:"__version__"` | 28 Version int64 `datastore:"__version__"` |
29 } | 29 } |
30 | 30 |
31 // GetEntityGroupVersion returns the entity group version for the entity group | 31 // GetEntityGroupVersion returns the entity group version for the entity group |
32 // containing root. If the entity group doesn't exist, this function will return | 32 // containing root. If the entity group doesn't exist, this function will return |
33 // zero and a nil error. | 33 // zero and a nil error. |
34 func GetEntityGroupVersion(c context.SingleReadWriter, root *datastore.Key) (int 64, error) { | 34 func GetEntityGroupVersion(c context.Context, root *datastore.Key) (int64, error ) { |
35 » ds := wrapper.GetDS(c) | |
35 for root.Parent() != nil { | 36 for root.Parent() != nil { |
36 root = root.Parent() | 37 root = root.Parent() |
37 } | 38 } |
38 egm := &EntityGroupMeta{ID: 1, Parent: root} | 39 egm := &EntityGroupMeta{ID: 1, Parent: root} |
39 » err := c.Get(egm) | 40 » err := ds.Get(egm) |
40 if err != datastore.ErrNoSuchEntity { | 41 if err != datastore.ErrNoSuchEntity { |
41 err = mark(err) | 42 err = mark(err) |
42 } else { | 43 } else { |
43 // this is OK for callers. The version of the entity group is ef fectively 0 | 44 // this is OK for callers. The version of the entity group is ef fectively 0 |
44 // in this case. | 45 // in this case. |
45 err = nil | 46 err = nil |
46 } | 47 } |
47 return egm.Version, err | 48 return egm.Version, err |
48 } | 49 } |
OLD | NEW |