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

Side by Side Diff: service/datastore/checkfilter.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 "fmt" 8 "fmt"
9 9
10 "github.com/luci/gae/service/info" 10 "github.com/luci/gae/service/info"
11 "github.com/luci/luci-go/common/errors" 11 "github.com/luci/luci-go/common/errors"
12 "golang.org/x/net/context" 12 "golang.org/x/net/context"
13 ) 13 )
14 14
15 type checkFilter struct { 15 type checkFilter struct {
16 RawInterface 16 RawInterface
17 17
18 aid string 18 aid string
19 ns string 19 ns string
20 } 20 }
21 21
22 func (tcf *checkFilter) AllocateIDs(incomplete *Key, n int) (start int64, err er ror) {
23 if n <= 0 {
24 return 0, fmt.Errorf("datastore: invalid `n` parameter in Alloca teIDs: %d", n)
25 }
26 if !incomplete.PartialValid(tcf.aid, tcf.ns) {
27 return 0, ErrInvalidKey
28 }
29 return tcf.RawInterface.AllocateIDs(incomplete, n)
30 }
31
32 func (tcf *checkFilter) RunInTransaction(f func(c context.Context) error, opts * TransactionOptions) error { 22 func (tcf *checkFilter) RunInTransaction(f func(c context.Context) error, opts * TransactionOptions) error {
33 if f == nil { 23 if f == nil {
34 return fmt.Errorf("datastore: RunInTransaction function is nil") 24 return fmt.Errorf("datastore: RunInTransaction function is nil")
35 } 25 }
36 return tcf.RawInterface.RunInTransaction(f, opts) 26 return tcf.RawInterface.RunInTransaction(f, opts)
37 } 27 }
38 28
39 func (tcf *checkFilter) Run(fq *FinalizedQuery, cb RawRunCB) error { 29 func (tcf *checkFilter) Run(fq *FinalizedQuery, cb RawRunCB) error {
40 if fq == nil { 30 if fq == nil {
41 return fmt.Errorf("datastore: Run query is nil") 31 return fmt.Errorf("datastore: Run query is nil")
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 return nil 109 return nil
120 } 110 }
121 return tcf.RawInterface.DeleteMulti(keys, cb) 111 return tcf.RawInterface.DeleteMulti(keys, cb)
122 } 112 }
123 113
124 func applyCheckFilter(c context.Context, i RawInterface) RawInterface { 114 func applyCheckFilter(c context.Context, i RawInterface) RawInterface {
125 inf := info.Get(c) 115 inf := info.Get(c)
126 ns, _ := inf.GetNamespace() 116 ns, _ := inf.GetNamespace()
127 return &checkFilter{i, inf.FullyQualifiedAppID(), ns} 117 return &checkFilter{i, inf.FullyQualifiedAppID(), ns}
128 } 118 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698