| 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 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 func (tcf *checkFilter) GetMulti(keys []Key, meta MultiMetaGetter, 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.NewLazyMultiError(len(keys)) | 46 lme := errors.NewLazyMultiError(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 k.Incomplete() || !k.Valid(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, meta, 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: PutMulti 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.NewLazyMultiError(len(keys)) | 71 lme := errors.NewLazyMultiError(len(keys)) |
| 72 for i, k := range keys { | 72 for i, k := range keys { |
| 73 » » if KeyIncomplete(k) { | 73 » » if !k.PartialValid(tcf.aid, tcf.ns) { |
| 74 » » » // use NewKey to avoid going all the way down the stack
for this check. | |
| 75 » » » k = NewKey(k.AppID(), k.Namespace(), k.Kind(), "", 1, k.
Parent()) | |
| 76 » » } | |
| 77 » » if !KeyValid(k, false, tcf.aid, tcf.ns) { | |
| 78 lme.Assign(i, ErrInvalidKey) | 74 lme.Assign(i, ErrInvalidKey) |
| 79 continue | 75 continue |
| 80 } | 76 } |
| 81 v := vals[i] | 77 v := vals[i] |
| 82 if v == nil { | 78 if v == nil { |
| 83 lme.Assign(i, errors.New("datastore: PutMulti got nil va
ls entry")) | 79 lme.Assign(i, errors.New("datastore: PutMulti got nil va
ls entry")) |
| 84 } | 80 } |
| 85 } | 81 } |
| 86 if me := lme.Get(); me != nil { | 82 if me := lme.Get(); me != nil { |
| 87 for _, err := range me.(errors.MultiError) { | 83 for _, err := range me.(errors.MultiError) { |
| 88 cb(nil, err) | 84 cb(nil, err) |
| 89 } | 85 } |
| 90 return nil | 86 return nil |
| 91 } | 87 } |
| 92 | 88 |
| 93 return tcf.RawInterface.PutMulti(keys, vals, cb) | 89 return tcf.RawInterface.PutMulti(keys, vals, cb) |
| 94 } | 90 } |
| 95 | 91 |
| 96 func (tcf *checkFilter) DeleteMulti(keys []Key, cb DeleteMultiCB) error { | 92 func (tcf *checkFilter) DeleteMulti(keys []Key, cb DeleteMultiCB) error { |
| 97 if len(keys) == 0 { | 93 if len(keys) == 0 { |
| 98 return nil | 94 return nil |
| 99 } | 95 } |
| 100 if cb == nil { | 96 if cb == nil { |
| 101 return fmt.Errorf("datastore: DeleteMulti callback is nil") | 97 return fmt.Errorf("datastore: DeleteMulti callback is nil") |
| 102 } | 98 } |
| 103 lme := errors.NewLazyMultiError(len(keys)) | 99 lme := errors.NewLazyMultiError(len(keys)) |
| 104 for i, k := range keys { | 100 for i, k := range keys { |
| 105 » » if KeyIncomplete(k) || !KeyValid(k, false, tcf.aid, tcf.ns) { | 101 » » if k.Incomplete() || !k.Valid(false, tcf.aid, tcf.ns) { |
| 106 lme.Assign(i, ErrInvalidKey) | 102 lme.Assign(i, ErrInvalidKey) |
| 107 } | 103 } |
| 108 } | 104 } |
| 109 if me := lme.Get(); me != nil { | 105 if me := lme.Get(); me != nil { |
| 110 for _, err := range me.(errors.MultiError) { | 106 for _, err := range me.(errors.MultiError) { |
| 111 cb(err) | 107 cb(err) |
| 112 } | 108 } |
| 113 return nil | 109 return nil |
| 114 } | 110 } |
| 115 return tcf.RawInterface.DeleteMulti(keys, cb) | 111 return tcf.RawInterface.DeleteMulti(keys, cb) |
| 116 } | 112 } |
| 117 | 113 |
| 118 func applyCheckFilter(c context.Context, i RawInterface) RawInterface { | 114 func applyCheckFilter(c context.Context, i RawInterface) RawInterface { |
| 119 inf := info.Get(c) | 115 inf := info.Get(c) |
| 120 return &checkFilter{i, inf.AppID(), inf.GetNamespace()} | 116 return &checkFilter{i, inf.AppID(), inf.GetNamespace()} |
| 121 } | 117 } |
| OLD | NEW |