Skip to content

Commit

Permalink
remove changes to structured query's builder and instead use fromPb i…
Browse files Browse the repository at this point in the history
…n GqlQuery's nextQuery
  • Loading branch information
Ajay Kannan committed Oct 21, 2015
1 parent b270c64 commit 6ffe927
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,9 @@ protected void populatePb(com.google.datastore.v1beta3.RunQueryRequest.Builder r
}

@Override
protected StructuredQuery<V> nextQuery(com.google.datastore.v1beta3.RunQueryResponse responsePb) {
return new StructuredQuery.Builder<>(type())
.namespace(namespace())
.mergeFrom(responsePb.getQuery())
.prepareNext(responsePb.getBatch())
.build();
protected Query<V> nextQuery(com.google.datastore.v1beta3.RunQueryResponse responsePb) {
return StructuredQuery.<V>fromPb(type(), namespace(), responsePb.getQuery())
.nextQuery(responsePb);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,23 +669,9 @@ B mergeFrom(com.google.datastore.v1beta3.Query queryPb) {
return self();
}

B prepareNext(com.google.datastore.v1beta3.QueryResultBatch queryResultBatchPb) {
startCursor(new Cursor(queryResultBatchPb.getEndCursor()));
if (offset > 0 && queryResultBatchPb.getSkippedResults() < offset) {
offset(offset - queryResultBatchPb.getSkippedResults());
} else {
offset(0);
if (limit != null) {
limit(limit - queryResultBatchPb.getEntityResultsCount());
}
}
return self();
}

public StructuredQuery<V> build() {
return new StructuredQuery<>(this);
}

}

static final class Builder<V> extends BaseBuilder<V, Builder<V>> {
Expand Down Expand Up @@ -858,8 +844,19 @@ protected void populatePb(com.google.datastore.v1beta3.RunQueryRequest.Builder r
}

@Override
protected StructuredQuery<V> nextQuery(com.google.datastore.v1beta3.RunQueryResponse responsePb) {
return new Builder<>(type()).mergeFrom(toPb()).prepareNext(responsePb.getBatch()).build();
protected Query<V> nextQuery(com.google.datastore.v1beta3.RunQueryResponse responsePb) {
Builder<V> builder = new Builder<>(type());
builder.mergeFrom(toPb());
builder.startCursor(new Cursor(responsePb.getBatch().getEndCursor()));
if (offset > 0 && responsePb.getBatch().getSkippedResults() < offset) {
builder.offset(offset - responsePb.getBatch().getSkippedResults());
} else {
builder.offset(0);
if (limit != null) {
builder.limit(limit - responsePb.getBatch().getEntityResultsCount());
}
}
return builder.build();
}

@Override
Expand Down Expand Up @@ -907,7 +904,9 @@ protected Object fromPb(ResultType<V> resultType, String namespace, byte[] bytes
return fromPb(resultType, namespace, com.google.datastore.v1beta3.Query.parseFrom(bytesPb));
}

private static StructuredQuery<?> fromPb(ResultType<?> resultType, String namespace,
@SuppressWarnings("unchecked")
static <V> StructuredQuery<V> fromPb(
ResultType<?> resultType, String namespace,
com.google.datastore.v1beta3.Query queryPb) {
BaseBuilder<?, ?> builder;
if (resultType.equals(ResultType.ENTITY)) {
Expand All @@ -917,6 +916,6 @@ private static StructuredQuery<?> fromPb(ResultType<?> resultType, String namesp
} else {
builder = new ProjectionEntityQueryBuilder();
}
return builder.namespace(namespace).mergeFrom(queryPb).build();
return (StructuredQuery<V>) builder.namespace(namespace).mergeFrom(queryPb).build();
}
}

0 comments on commit 6ffe927

Please sign in to comment.