Revision created by MOE tool push_codebase.
[gae.git] / java / src / main / com / google / appengine / api / datastore / WrappedQueryResultV4.java
blob5b15d2b6a3d104f8b5f361f4136990343ee84479
1 package com.google.appengine.api.datastore;
3 import com.google.appengine.api.datastore.BaseQueryResultsSource.WrappedQueryResult;
4 import com.google.apphosting.datastore.DatastoreV4;
5 import com.google.apphosting.datastore.DatastoreV4.QueryResultBatch;
6 import com.google.apphosting.datastore.DatastoreV4.QueryResultBatch.MoreResultsType;
7 import com.google.common.collect.ImmutableList;
8 import com.google.common.collect.Lists;
10 import java.util.Collection;
11 import java.util.Collections;
12 import java.util.List;
14 /**
15 * Wrapper for V4 protos with common functions.
17 class WrappedQueryResultV4 implements WrappedQueryResult {
18 private final QueryResultBatch batch;
20 WrappedQueryResultV4(QueryResultBatch batch) {
21 this.batch = batch;
24 @Override
25 public Cursor getEndCursor() {
26 if (batch.hasEndCursor()) {
27 return new Cursor(batch.getEndCursor());
29 return null;
32 @Override
33 public List<Entity> getEntities(Collection<Projection> projections) {
34 List<Entity> entityList = Lists.newArrayListWithCapacity(batch.getEntityResultCount());
35 if (projections.isEmpty()) {
36 for (DatastoreV4.EntityResult entityResult : batch.getEntityResultList()) {
37 entityList.add(DataTypeTranslator.toEntity(entityResult.getEntity()));
39 } else {
40 for (DatastoreV4.EntityResult entityResult : batch.getEntityResultList()) {
41 entityList.add(DataTypeTranslator.toEntity(entityResult.getEntity(), projections));
44 return entityList;
47 @Override
48 public List<Cursor> getResultCursors() {
49 return Collections.<Cursor>nCopies(batch.getEntityResultCount(), null);
52 @Override
53 public Cursor getSkippedResultsCursor() {
54 return null;
57 @Override
58 public boolean hasMoreResults() {
59 return batch.getMoreResults() == MoreResultsType.NOT_FINISHED;
62 @Override
63 public int numSkippedResults() {
64 return batch.getSkippedResults();
67 @Override
68 public List<Index> getIndexInfo(Collection<Index> monitoredIndexBuffer) {
69 return ImmutableList.of();
72 QueryResultBatch getBatch() {
73 return batch;