| 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 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 |
| 22 func (tcf *checkFilter) RunInTransaction(f func(c context.Context) error, opts *
TransactionOptions) error { | 32 func (tcf *checkFilter) RunInTransaction(f func(c context.Context) error, opts *
TransactionOptions) error { |
| 23 if f == nil { | 33 if f == nil { |
| 24 return fmt.Errorf("datastore: RunInTransaction function is nil") | 34 return fmt.Errorf("datastore: RunInTransaction function is nil") |
| 25 } | 35 } |
| 26 return tcf.RawInterface.RunInTransaction(f, opts) | 36 return tcf.RawInterface.RunInTransaction(f, opts) |
| 27 } | 37 } |
| 28 | 38 |
| 29 func (tcf *checkFilter) Run(fq *FinalizedQuery, cb RawRunCB) error { | 39 func (tcf *checkFilter) Run(fq *FinalizedQuery, cb RawRunCB) error { |
| 30 if fq == nil { | 40 if fq == nil { |
| 31 return fmt.Errorf("datastore: Run query is nil") | 41 return fmt.Errorf("datastore: Run query is nil") |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 } | 118 } |
| 109 return nil | 119 return nil |
| 110 } | 120 } |
| 111 return tcf.RawInterface.DeleteMulti(keys, cb) | 121 return tcf.RawInterface.DeleteMulti(keys, cb) |
| 112 } | 122 } |
| 113 | 123 |
| 114 func applyCheckFilter(c context.Context, i RawInterface) RawInterface { | 124 func applyCheckFilter(c context.Context, i RawInterface) RawInterface { |
| 115 inf := info.Get(c) | 125 inf := info.Get(c) |
| 116 return &checkFilter{i, inf.FullyQualifiedAppID(), inf.GetNamespace()} | 126 return &checkFilter{i, inf.FullyQualifiedAppID(), inf.GetNamespace()} |
| 117 } | 127 } |
| OLD | NEW |