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

Side by Side Diff: service/datastore/datastore.go

Issue 2007123002: datastore: Update AllocateIDs to take keys. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/gae@master
Patch Set: 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 "io" 9 "io"
10 "io/ioutil" 10 "io/ioutil"
(...skipping 30 matching lines...) Expand all
41 } 41 }
42 42
43 func (d *datastoreImpl) MakeKey(elems ...interface{}) *Key { 43 func (d *datastoreImpl) MakeKey(elems ...interface{}) *Key {
44 return MakeKey(d.aid, d.ns, elems...) 44 return MakeKey(d.aid, d.ns, elems...)
45 } 45 }
46 46
47 func (d *datastoreImpl) NewKey(kind, stringID string, intID int64, parent *Key) *Key { 47 func (d *datastoreImpl) NewKey(kind, stringID string, intID int64, parent *Key) *Key {
48 return NewKey(d.aid, d.ns, kind, stringID, intID, parent) 48 return NewKey(d.aid, d.ns, kind, stringID, intID, parent)
49 } 49 }
50 50
51 func (d *datastoreImpl) NewIncompleteKeys(count int, kind string, parent *Key) ( keys []*Key) {
52 if count > 0 {
53 keys = make([]*Key, count)
54 for i := range keys {
55 keys[i] = d.NewKey(kind, "", 0, parent)
56 }
57 }
58 return
59 }
60
51 func (d *datastoreImpl) NewKeyToks(toks []KeyTok) *Key { 61 func (d *datastoreImpl) NewKeyToks(toks []KeyTok) *Key {
52 return NewKeyToks(d.aid, d.ns, toks) 62 return NewKeyToks(d.aid, d.ns, toks)
53 } 63 }
54 64
55 // PopulateKey loads key into obj. 65 // PopulateKey loads key into obj.
56 // 66 //
57 // obj is any object that Interface.Get is able to accept. 67 // obj is any object that Interface.Get is able to accept.
58 // 68 //
59 // This method will panic if obj is an invalid datastore model. If the key could 69 // This method will panic if obj is an invalid datastore model. If the key could
60 // not be applied to the object, nothing will happen. 70 // not be applied to the object, nothing will happen.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 if cbTyp.NumOut() > 1 { 124 if cbTyp.NumOut() > 1 {
115 badSig() 125 badSig()
116 } else if cbTyp.NumOut() == 1 && cbTyp.Out(0) != typeOfError { 126 } else if cbTyp.NumOut() == 1 && cbTyp.Out(0) != typeOfError {
117 badSig() 127 badSig()
118 } 128 }
119 hasErr = cbTyp.NumOut() == 1 129 hasErr = cbTyp.NumOut() == 1
120 130
121 return 131 return
122 } 132 }
123 133
134 func (d *datastoreImpl) AllocateIDs(keys ...*Key) ([]*Key, error) {
135 if len(keys) == 0 {
136 return nil, nil
137 }
138
139 // Duplicate the keys slice, then pass to our raw interface.
140 allocKeys := make([]*Key, len(keys))
141 copy(allocKeys, keys)
142
143 if err := d.RawInterface.AllocateIDs(allocKeys); err != nil {
144 return nil, err
145 }
146 return allocKeys, nil
147 }
148
124 func (d *datastoreImpl) Run(q *Query, cbIface interface{}) error { 149 func (d *datastoreImpl) Run(q *Query, cbIface interface{}) error {
125 isKey, hasErr, hasCursorCB, mat := runParseCallback(cbIface) 150 isKey, hasErr, hasCursorCB, mat := runParseCallback(cbIface)
126 151
127 if isKey { 152 if isKey {
128 q = q.KeysOnly(true) 153 q = q.KeysOnly(true)
129 } 154 }
130 fq, err := q.Finalize() 155 fq, err := q.Finalize()
131 if err != nil { 156 if err != nil {
132 return err 157 return err
133 } 158 }
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 currentDir = filepath.Dir(currentDir) 486 currentDir = filepath.Dir(currentDir)
462 } 487 }
463 } 488 }
464 489
465 func filterStop(err error) error { 490 func filterStop(err error) error {
466 if err == Stop { 491 if err == Stop {
467 err = nil 492 err = nil
468 } 493 }
469 return err 494 return err
470 } 495 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698