1 package com
.google
.appengine
.api
.labs
.datastore
.overlay
;
3 import static com
.google
.common
.base
.Preconditions
.checkNotNull
;
5 import com
.google
.appengine
.api
.datastore
.Cursor
;
6 import com
.google
.appengine
.api
.datastore
.DatastoreService
;
7 import com
.google
.appengine
.api
.datastore
.Entity
;
8 import com
.google
.appengine
.api
.datastore
.Index
;
9 import com
.google
.appengine
.api
.datastore
.QueryResultIterator
;
10 import com
.google
.common
.collect
.ImmutableList
;
12 import java
.util
.List
;
15 * An implementation of {@link QueryResultIterator<Entity>} for use with a namespace-pinned
16 * {@link DatastoreService}.
18 * <p>We run the query as usual, and then transform any returned entities back to the original
21 final class NamespacePinnedQueryResultIteratorImpl
implements QueryResultBatchIterator
<Entity
> {
22 private final NamespacePinnedAsyncDatastoreServiceImpl datastore
;
23 private final QueryResultIterator
<Entity
> iterator
;
26 * Constructs a namespace-pinned {@link QueryResultIterator<Entity>}.
28 * @param datastore the namespace-pinned Datastore
29 * @param iterator the underlying iterator
31 public NamespacePinnedQueryResultIteratorImpl(NamespacePinnedAsyncDatastoreServiceImpl datastore
,
32 QueryResultIterator
<Entity
> iterator
) {
33 this.datastore
= checkNotNull(datastore
);
34 this.iterator
= checkNotNull(iterator
);
38 public boolean hasNext() {
39 return iterator
.hasNext();
43 public Entity
next() {
44 return datastore
.getOriginalNamespaceEntity(iterator
.next());
48 public List
<Entity
> nextList(int maximumElements
) {
49 ImmutableList
.Builder
<Entity
> builder
= ImmutableList
.<Entity
>builder();
50 for (int i
= 0; i
< maximumElements
; i
++) {
54 builder
.add(datastore
.getOriginalNamespaceEntity(next()));
56 return builder
.build();
60 public List
<Index
> getIndexList() {
61 return iterator
.getIndexList();
65 public Cursor
getCursor() {
66 return iterator
.getCursor();
70 public void remove() {