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 "bytes" | 8 "bytes" |
9 "errors" | 9 "errors" |
10 "fmt" | 10 "fmt" |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 offset int32 | 231 offset int32 |
232 | 232 |
233 start queryCursor | 233 start queryCursor |
234 end queryCursor | 234 end queryCursor |
235 | 235 |
236 err error | 236 err error |
237 } | 237 } |
238 | 238 |
239 var _ rds.Query = (*queryImpl)(nil) | 239 var _ rds.Query = (*queryImpl)(nil) |
240 | 240 |
241 type queryIterImpl struct { | |
242 idx *queryImpl | |
243 } | |
244 | |
245 var _ rds.Iterator = (*queryIterImpl)(nil) | |
246 | |
247 func (q *queryIterImpl) Cursor() (rds.Cursor, error) { | |
248 if q.idx.err != nil { | |
249 return nil, q.idx.err | |
250 } | |
251 return nil, nil | |
252 } | |
253 | |
254 func (q *queryIterImpl) Next(dst rds.PropertyLoadSaver) (rds.Key, error) { | |
255 if q.idx.err != nil { | |
256 return nil, q.idx.err | |
257 } | |
258 return nil, nil | |
259 } | |
260 | |
261 func (q *queryImpl) normalize() (ret *queryImpl) { | 241 func (q *queryImpl) normalize() (ret *queryImpl) { |
262 // ported from GAE SDK datastore_index.py;Normalize() | 242 // ported from GAE SDK datastore_index.py;Normalize() |
263 ret = q.clone() | 243 ret = q.clone() |
264 | 244 |
265 bs := newMemStore() | 245 bs := newMemStore() |
266 | 246 |
267 eqProperties := bs.MakePrivateCollection(nil) | 247 eqProperties := bs.MakePrivateCollection(nil) |
268 | 248 |
269 ineqProperties := bs.MakePrivateCollection(nil) | 249 ineqProperties := bs.MakePrivateCollection(nil) |
270 | 250 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 | 365 |
386 ineqPropName := "" | 366 ineqPropName := "" |
387 for _, f := range ret.filter { | 367 for _, f := range ret.filter { |
388 if f.field == "__key__" { | 368 if f.field == "__key__" { |
389 k, ok := f.value.(rds.Key) | 369 k, ok := f.value.(rds.Key) |
390 if !ok { | 370 if !ok { |
391 ret.err = errors.New( | 371 ret.err = errors.New( |
392 "gae/memory: __key__ filter value must b
e a Key") | 372 "gae/memory: __key__ filter value must b
e a Key") |
393 return | 373 return |
394 } | 374 } |
395 » » » if !rds.KeyValid(k, ret.ns, false) { | 375 » » » if !rds.KeyValid(k, false, globalAppID, q.ns) { |
396 // See the comment in queryImpl.Ancestor; basica
lly this check | 376 // See the comment in queryImpl.Ancestor; basica
lly this check |
397 // never happens in the real env because the SDK
silently swallows | 377 // never happens in the real env because the SDK
silently swallows |
398 // this condition :/ | 378 // this condition :/ |
399 ret.err = rds.ErrInvalidKey | 379 ret.err = rds.ErrInvalidKey |
400 return | 380 return |
401 } | 381 } |
| 382 if k.Namespace() != ns { |
| 383 ret.err = fmt.Errorf("bad namespace: %q (expecte
d %q)", k.Namespace(), ns) |
| 384 return |
| 385 } |
402 // __key__ filter app is X but query app is X | 386 // __key__ filter app is X but query app is X |
403 // __key__ filter namespace is X but query namespace is
X | 387 // __key__ filter namespace is X but query namespace is
X |
404 } | 388 } |
405 // if f.op == qEqual and f.field in ret.project_fields | 389 // if f.op == qEqual and f.field in ret.project_fields |
406 // "cannot use projection on a proprety with an equality filte
r" | 390 // "cannot use projection on a proprety with an equality filte
r" |
407 | 391 |
408 if f.op.isINEQOp() { | 392 if f.op.isINEQOp() { |
409 if ineqPropName == "" { | 393 if ineqPropName == "" { |
410 ineqPropName = f.field | 394 ineqPropName = f.field |
411 } else if f.field != ineqPropName { | 395 } else if f.field != ineqPropName { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 ret.project = append([]string(nil), q.project...) | 457 ret.project = append([]string(nil), q.project...) |
474 return &ret | 458 return &ret |
475 } | 459 } |
476 | 460 |
477 func (q *queryImpl) Ancestor(k rds.Key) rds.Query { | 461 func (q *queryImpl) Ancestor(k rds.Key) rds.Query { |
478 q = q.clone() | 462 q = q.clone() |
479 q.ancestor = k | 463 q.ancestor = k |
480 if k == nil { | 464 if k == nil { |
481 // SDK has an explicit nil-check | 465 // SDK has an explicit nil-check |
482 q.err = errors.New("datastore: nil query ancestor") | 466 q.err = errors.New("datastore: nil query ancestor") |
483 » } else if !rds.KeyValid(k, q.ns, false) { | 467 » } else if !rds.KeyValid(k, false, globalAppID, q.ns) { |
484 // technically the SDK implementation does a Weird Thing (tm) if
both the | 468 // technically the SDK implementation does a Weird Thing (tm) if
both the |
485 // stringID and intID are set on a key; it only serializes the s
tringID in | 469 // stringID and intID are set on a key; it only serializes the s
tringID in |
486 // the proto. This means that if you set the Ancestor to an inva
lid key, | 470 // the proto. This means that if you set the Ancestor to an inva
lid key, |
487 // you'll never actually hear about it. Instead of doing that in
sanity, we | 471 // you'll never actually hear about it. Instead of doing that in
sanity, we |
488 // just swap to an error here. | 472 // just swap to an error here. |
489 q.err = rds.ErrInvalidKey | 473 q.err = rds.ErrInvalidKey |
| 474 } else if k.Namespace() != q.ns { |
| 475 q.err = fmt.Errorf("bad namespace: %q (expected %q)", k.Namespac
e(), q.ns) |
490 } | 476 } |
491 return q | 477 return q |
492 } | 478 } |
493 | 479 |
494 func (q *queryImpl) Distinct() rds.Query { | 480 func (q *queryImpl) Distinct() rds.Query { |
495 q = q.clone() | 481 q = q.clone() |
496 q.distinct = true | 482 q.distinct = true |
497 return q | 483 return q |
498 } | 484 } |
499 | 485 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 } | 569 } |
584 q.end = curs | 570 q.end = curs |
585 return q | 571 return q |
586 } | 572 } |
587 | 573 |
588 func (q *queryImpl) EventualConsistency() rds.Query { | 574 func (q *queryImpl) EventualConsistency() rds.Query { |
589 q = q.clone() | 575 q = q.clone() |
590 q.eventualConsistency = true | 576 q.eventualConsistency = true |
591 return q | 577 return q |
592 } | 578 } |
OLD | NEW |