| 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" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 func (tcf *checkFilter) Run(q Query, cb RawRunCB) error { | 29 func (tcf *checkFilter) Run(q Query, cb RawRunCB) error { |
| 30 if q == nil { | 30 if q == nil { |
| 31 return fmt.Errorf("datastore: Run query is nil") | 31 return fmt.Errorf("datastore: Run query is nil") |
| 32 } | 32 } |
| 33 if cb == nil { | 33 if cb == nil { |
| 34 return fmt.Errorf("datastore: Run callback is nil") | 34 return fmt.Errorf("datastore: Run callback is nil") |
| 35 } | 35 } |
| 36 return tcf.RawInterface.Run(q, cb) | 36 return tcf.RawInterface.Run(q, cb) |
| 37 } | 37 } |
| 38 | 38 |
| 39 func (tcf *checkFilter) GetMulti(keys []Key, cb GetMultiCB) error { | 39 func (tcf *checkFilter) GetMulti(keys []Key, meta MultiMetaGetter, cb GetMultiCB
) error { |
| 40 if len(keys) == 0 { | 40 if len(keys) == 0 { |
| 41 return nil | 41 return nil |
| 42 } | 42 } |
| 43 if cb == nil { | 43 if cb == nil { |
| 44 return fmt.Errorf("datastore: GetMulti callback is nil") | 44 return fmt.Errorf("datastore: GetMulti callback is nil") |
| 45 } | 45 } |
| 46 lme := errors.LazyMultiError{Size: len(keys)} | 46 lme := errors.LazyMultiError{Size: len(keys)} |
| 47 for i, k := range keys { | 47 for i, k := range keys { |
| 48 if KeyIncomplete(k) || !KeyValid(k, true, tcf.aid, tcf.ns) { | 48 if KeyIncomplete(k) || !KeyValid(k, true, tcf.aid, tcf.ns) { |
| 49 lme.Assign(i, ErrInvalidKey) | 49 lme.Assign(i, ErrInvalidKey) |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 if me := lme.Get(); me != nil { | 52 if me := lme.Get(); me != nil { |
| 53 for _, err := range me.(errors.MultiError) { | 53 for _, err := range me.(errors.MultiError) { |
| 54 cb(nil, err) | 54 cb(nil, err) |
| 55 } | 55 } |
| 56 return nil | 56 return nil |
| 57 } | 57 } |
| 58 » return tcf.RawInterface.GetMulti(keys, cb) | 58 » return tcf.RawInterface.GetMulti(keys, meta, cb) |
| 59 } | 59 } |
| 60 | 60 |
| 61 func (tcf *checkFilter) PutMulti(keys []Key, vals []PropertyMap, cb PutMultiCB)
error { | 61 func (tcf *checkFilter) PutMulti(keys []Key, vals []PropertyMap, cb PutMultiCB)
error { |
| 62 if len(keys) != len(vals) { | 62 if len(keys) != len(vals) { |
| 63 » » return fmt.Errorf("datastore: GetMulti with mismatched keys/vals
lengths (%d/%d)", len(keys), len(vals)) | 63 » » return fmt.Errorf("datastore: PutMulti with mismatched keys/vals
lengths (%d/%d)", len(keys), len(vals)) |
| 64 } | 64 } |
| 65 if len(keys) == 0 { | 65 if len(keys) == 0 { |
| 66 return nil | 66 return nil |
| 67 } | 67 } |
| 68 if cb == nil { | 68 if cb == nil { |
| 69 return fmt.Errorf("datastore: PutMulti callback is nil") | 69 return fmt.Errorf("datastore: PutMulti callback is nil") |
| 70 } | 70 } |
| 71 lme := errors.LazyMultiError{Size: len(keys)} | 71 lme := errors.LazyMultiError{Size: len(keys)} |
| 72 for i, k := range keys { | 72 for i, k := range keys { |
| 73 if KeyIncomplete(k) { | 73 if KeyIncomplete(k) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 112 } |
| 113 return nil | 113 return nil |
| 114 } | 114 } |
| 115 return tcf.RawInterface.DeleteMulti(keys, cb) | 115 return tcf.RawInterface.DeleteMulti(keys, cb) |
| 116 } | 116 } |
| 117 | 117 |
| 118 func applyCheckFilter(c context.Context, i RawInterface) RawInterface { | 118 func applyCheckFilter(c context.Context, i RawInterface) RawInterface { |
| 119 inf := info.Get(c) | 119 inf := info.Get(c) |
| 120 return &checkFilter{i, inf.AppID(), inf.GetNamespace()} | 120 return &checkFilter{i, inf.AppID(), inf.GetNamespace()} |
| 121 } | 121 } |
| OLD | NEW |