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

Side by Side Diff: go/src/infra/gae/libs/meta/eg.go

Issue 1240573002: Reland: Refactor current GAE abstraction library to be free of the SDK* (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: expand coverage range to fit 32bit test expectations Created 5 years, 5 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
« no previous file with comments | « go/src/infra/gae/libs/memlock/memlock_test.go ('k') | go/src/infra/gae/libs/meta/eg_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 meta 5 package meta
6 6
7 import ( 7 import (
8 "golang.org/x/net/context" 8 "golang.org/x/net/context"
9 9
10 "appengine/datastore"
11
12 "github.com/luci/luci-go/common/errors" 10 "github.com/luci/luci-go/common/errors"
13 11
14 » "infra/gae/libs/wrapper" 12 » "infra/gae/libs/gae"
15 ) 13 )
16 14
17 var mark = errors.MakeMarkFn("eg") 15 var mark = errors.MakeMarkFn("eg")
18 16
19 // EntityGroupMeta is the model corresponding to the __entity_group__ model in 17 // 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 18 // appengine. You shouldn't need to use this struct directly, but instead should
21 // use GetEntityGroupVersion. 19 // use GetEntityGroupVersion.
22 type EntityGroupMeta struct { 20 type EntityGroupMeta struct {
23 » _kind string `datastore:"-" goon:"kind,__entity_group__"` 21 » Version int64 `gae:"__version__"`
24
25 » ID int64 `datastore:"-" goon:"id"`
26 » Parent *datastore.Key `datastore:"-" goon:"parent"`
27
28 » Version int64 `datastore:"__version__"`
29 } 22 }
30 23
31 // GetEntityGroupVersion returns the entity group version for the entity group 24 // GetEntityGroupVersion returns the entity group version for the entity group
32 // containing root. If the entity group doesn't exist, this function will return 25 // containing root. If the entity group doesn't exist, this function will return
33 // zero and a nil error. 26 // zero and a nil error.
34 func GetEntityGroupVersion(c context.Context, root *datastore.Key) (int64, error ) { 27 func GetEntityGroupVersion(c context.Context, root gae.DSKey) (int64, error) {
35 for root.Parent() != nil { 28 for root.Parent() != nil {
36 root = root.Parent() 29 root = root.Parent()
37 } 30 }
38 » egm := &EntityGroupMeta{ID: 1, Parent: root} 31 » egm := &EntityGroupMeta{}
39 » err := wrapper.GetDS(c).Get(egm) 32 » rds := gae.GetRDS(c)
40 » if err != datastore.ErrNoSuchEntity { 33 » err := rds.Get(rds.NewKey("__entity_group__", "", 1, root), egm)
34 » if err != gae.ErrDSNoSuchEntity {
41 err = mark(err) 35 err = mark(err)
42 } else { 36 } else {
43 // this is OK for callers. The version of the entity group is ef fectively 0 37 // this is OK for callers. The version of the entity group is ef fectively 0
44 // in this case. 38 // in this case.
45 err = nil 39 err = nil
46 } 40 }
47 return egm.Version, err 41 return egm.Version, err
48 } 42 }
OLDNEW
« no previous file with comments | « go/src/infra/gae/libs/memlock/memlock_test.go ('k') | go/src/infra/gae/libs/meta/eg_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698