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

Unified Diff: service/rawdatastore/checkfilter.go

Issue 1259593005: Add 'user friendly' datastore API. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: 100% coverage of new code 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 side-by-side diff with in-line comments
Download patch
Index: service/rawdatastore/checkfilter.go
diff --git a/service/rawdatastore/checkfilter.go b/service/rawdatastore/checkfilter.go
deleted file mode 100644
index bf091358c7b0a21f0b17b99fc2623fea19845c61..0000000000000000000000000000000000000000
--- a/service/rawdatastore/checkfilter.go
+++ /dev/null
@@ -1,123 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package rawdatastore
-
-import (
- "fmt"
-
- "github.com/luci/gae/service/info"
- "github.com/luci/luci-go/common/errors"
- "golang.org/x/net/context"
-)
-
-type checkFilter struct {
- Interface
-
- aid string
- ns string
-}
-
-func (tcf *checkFilter) RunInTransaction(f func(c context.Context) error, opts *TransactionOptions) error {
- if f == nil {
- return nil
- }
- return tcf.Interface.RunInTransaction(f, opts)
-}
-
-func (tcf *checkFilter) Run(q Query, cb RunCB) error {
- if q == nil || cb == nil {
- return nil
- }
- return tcf.Interface.Run(q, cb)
-}
-
-func (tcf *checkFilter) GetMulti(keys []Key, cb GetMultiCB) error {
- if len(keys) == 0 || cb == nil {
- return nil
- }
- lme := errors.LazyMultiError{Size: len(keys)}
- for i, k := range keys {
- if KeyIncomplete(k) || !KeyValid(k, true, tcf.aid, tcf.ns) {
- lme.Assign(i, ErrInvalidKey)
- }
- }
- if me := lme.Get(); me != nil {
- for _, err := range me.(errors.MultiError) {
- cb(nil, err)
- }
- return nil
- }
- return tcf.Interface.GetMulti(keys, cb)
-}
-
-func (tcf *checkFilter) PutMulti(keys []Key, vals []PropertyLoadSaver, cb PutMultiCB) error {
- if len(keys) != len(vals) {
- return fmt.Errorf("rawdatastore: GetMulti with mismatched keys/vals lengths (%d/%d)", len(keys), len(vals))
- }
- if len(keys) == 0 {
- return nil
- }
- lme := errors.LazyMultiError{Size: len(keys)}
- for i, k := range keys {
- if KeyIncomplete(k) {
- k = NewKey(k.AppID(), k.Namespace(), k.Kind(), "", 1, k.Parent())
- }
- if !KeyValid(k, false, tcf.aid, tcf.ns) {
- lme.Assign(i, ErrInvalidKey)
- continue
- }
- v := vals[i]
- if v == nil {
- lme.Assign(i, errors.New("rawdatastore: PutMulti got nil vals entry"))
- } else {
- lme.Assign(i, v.Problem())
- }
- }
- if me := lme.Get(); me != nil {
- for _, err := range me.(errors.MultiError) {
- cb(nil, err)
- }
- return nil
- }
-
- err := error(nil)
- pmVals := make([]PropertyLoadSaver, len(vals))
- for i, val := range vals {
- pmVals[i], err = val.Save(true)
- lme.Assign(i, err)
- }
- if me := lme.Get(); me != nil {
- for _, err := range me.(errors.MultiError) {
- cb(nil, err)
- }
- return nil
- }
-
- return tcf.Interface.PutMulti(keys, pmVals, cb)
-}
-
-func (tcf *checkFilter) DeleteMulti(keys []Key, cb DeleteMultiCB) error {
- if len(keys) == 0 {
- return nil
- }
- lme := errors.LazyMultiError{Size: len(keys)}
- for i, k := range keys {
- if KeyIncomplete(k) || !KeyValid(k, false, tcf.aid, tcf.ns) {
- lme.Assign(i, ErrInvalidKey)
- }
- }
- if me := lme.Get(); me != nil {
- for _, err := range me.(errors.MultiError) {
- cb(err)
- }
- return nil
- }
- return tcf.Interface.DeleteMulti(keys, cb)
-}
-
-func applyCheckFilter(c context.Context, i Interface) Interface {
- inf := info.Get(c)
- return &checkFilter{i, inf.AppID(), inf.GetNamespace()}
-}

Powered by Google App Engine
This is Rietveld 408576698