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 memory | 5 package memory |
6 | 6 |
7 import ( | 7 import ( |
8 "errors" | 8 "errors" |
9 "fmt" | 9 "fmt" |
10 | 10 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 func (d *dsImpl) DeleteMulti(keys []ds.Key, cb ds.DeleteMultiCB) error { | 61 func (d *dsImpl) DeleteMulti(keys []ds.Key, cb ds.DeleteMultiCB) error { |
62 d.data.delMulti(keys, cb) | 62 d.data.delMulti(keys, cb) |
63 return nil | 63 return nil |
64 } | 64 } |
65 | 65 |
66 func (d *dsImpl) NewQuery(kind string) ds.Query { | 66 func (d *dsImpl) NewQuery(kind string) ds.Query { |
67 return &queryImpl{ns: d.ns, kind: kind} | 67 return &queryImpl{ns: d.ns, kind: kind} |
68 } | 68 } |
69 | 69 |
70 func (d *dsImpl) Run(q ds.Query, cb ds.RawRunCB) error { | 70 func (d *dsImpl) Run(q ds.Query, cb ds.RawRunCB) error { |
| 71 rq := q.(*queryImpl) |
| 72 done, err := rq.valid(d.ns, true) |
| 73 if done || err != nil { |
| 74 return err // will be nil if done |
| 75 } |
71 return nil | 76 return nil |
72 } | 77 } |
73 | 78 |
74 func (d *dsImpl) AddIndexes(idxs ...*ds.IndexDefinition) { | 79 func (d *dsImpl) AddIndexes(idxs ...*ds.IndexDefinition) { |
75 for _, i := range idxs { | 80 for _, i := range idxs { |
76 if !i.Compound() { | 81 if !i.Compound() { |
77 panic(fmt.Errorf("Attempted to add non-compound index: %
s", i)) | 82 panic(fmt.Errorf("Attempted to add non-compound index: %
s", i)) |
78 } | 83 } |
79 } | 84 } |
80 | 85 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 } | 135 } |
131 | 136 |
132 func (d *txnDsImpl) DeleteMulti(keys []ds.Key, cb ds.DeleteMultiCB) error { | 137 func (d *txnDsImpl) DeleteMulti(keys []ds.Key, cb ds.DeleteMultiCB) error { |
133 return d.data.run(func() error { | 138 return d.data.run(func() error { |
134 return d.data.delMulti(keys, cb) | 139 return d.data.delMulti(keys, cb) |
135 }) | 140 }) |
136 } | 141 } |
137 | 142 |
138 func (d *txnDsImpl) Run(q ds.Query, cb ds.RawRunCB) error { | 143 func (d *txnDsImpl) Run(q ds.Query, cb ds.RawRunCB) error { |
139 rq := q.(*queryImpl) | 144 rq := q.(*queryImpl) |
140 » if rq.ancestor == nil { | 145 » done, err := rq.valid(d.ns, true) |
141 » » return errors.New("gae/impl/memory: queries in transactions only
support ancestor queries") | 146 » if done || err != nil { |
| 147 » » return err // will be nil if done |
142 } | 148 } |
143 if rq.eventualConsistency { | 149 if rq.eventualConsistency { |
144 » » rq = rq.clone() | 150 » » rq = rq.checkMutateClone(nil, nil) |
145 rq.eventualConsistency = false | 151 rq.eventualConsistency = false |
146 } | 152 } |
147 // TODO(riannucci): use head instead of snap for indexes | 153 // TODO(riannucci): use head instead of snap for indexes |
148 panic("NOT IMPLEMENTED") | 154 panic("NOT IMPLEMENTED") |
149 } | 155 } |
150 | 156 |
151 func (*txnDsImpl) RunInTransaction(func(c context.Context) error, *ds.Transactio
nOptions) error { | 157 func (*txnDsImpl) RunInTransaction(func(c context.Context) error, *ds.Transactio
nOptions) error { |
152 return errors.New("datastore: nested transactions are not supported") | 158 return errors.New("datastore: nested transactions are not supported") |
153 } | 159 } |
154 | 160 |
155 func (d *txnDsImpl) NewQuery(kind string) ds.Query { | 161 func (d *txnDsImpl) NewQuery(kind string) ds.Query { |
156 return &queryImpl{ns: d.ns, kind: kind} | 162 return &queryImpl{ns: d.ns, kind: kind} |
157 } | 163 } |
158 | 164 |
159 func (*txnDsImpl) Testable() ds.Testable { | 165 func (*txnDsImpl) Testable() ds.Testable { |
160 return nil | 166 return nil |
161 } | 167 } |
OLD | NEW |