B clearDistinctOn() { distinctOn.clear(); return self(); }
B mergeFrom(com.google.datastore.v1.Query queryPb) { if (queryPb.getKindCount() > 0) { setKind(queryPb.getKind(0).getName()); setStartCursor(new Cursor(queryPb.getStartCursor())); setEndCursor(new Cursor(queryPb.getEndCursor())); setOffset(queryPb.getOffset()); if (queryPb.hasLimit()) { setLimit(queryPb.getLimit().getValue()); setFilter(currFilter); addOrderBy(OrderBy.fromPb(orderByPb)); addProjection(projectionPb.getProperty().getName()); addDistinctOn(distinctOnPb.getName()); return self();
@SuppressWarnings("unchecked") static <V> StructuredQuery<V> fromPb( ResultType<?> resultType, String namespace, com.google.datastore.v1.Query queryPb) { BuilderImpl<?, ?> builder; if (resultType.equals(ResultType.ENTITY)) { builder = new EntityQuery.Builder(); } else if (resultType.equals(ResultType.KEY)) { builder = new KeyQuery.Builder(); } else { builder = new ProjectionEntityQuery.Builder(); } return (StructuredQuery<V>) builder.setNamespace(namespace).mergeFrom(queryPb).build(); } }
B clearDistinctOn() { distinctOn.clear(); return self(); }
@Override public B setFilter(Filter filter) { this.filter = filter; return self(); }
@Override public B setEndCursor(Cursor endCursor) { this.endCursor = endCursor; return self(); }
@Override public B setNamespace(String namespace) { this.namespace = namespace; return self(); }
/** Adds one or more projections to the existing projection clause. */ @Override public Builder addProjection(String projection, String... others) { super.addProjection(projection, others); return this; }
/** Clears the projection clause. */ @Override public Builder clearProjection() { super.clearProjection(); return this; }
B setProjection(String projection, String... others) { clearProjection(); addProjection(projection, others); return self(); }
B addDistinctOn(String property, String... others) { this.distinctOn.add(property); Collections.addAll(this.distinctOn, others); return self(); }
@Override public B addOrderBy(OrderBy orderBy, OrderBy... others) { this.orderBy.add(orderBy); Collections.addAll(this.orderBy, others); return self(); }
@Override public B setOffset(int offset) { Preconditions.checkArgument(offset >= 0, "offset must not be negative"); this.offset = offset; return self(); }
B clearProjection() { projection.clear(); return self(); }
B setDistinctOn(String property, String... others) { clearDistinctOn(); addDistinctOn(property, others); return self(); }
@Override public B setStartCursor(Cursor startCursor) { this.startCursor = startCursor; return self(); }
/** * Sets the query's distinct on clause (clearing any previously specified distinct on settings). */ @Override public Builder setDistinctOn(String property, String... others) { super.setDistinctOn(property, others); return this; }
@Override Builder mergeFrom(com.google.datastore.v1.Query queryPb) { super.mergeFrom(queryPb); setProjection(KEY_PROPERTY_NAME); clearDistinctOn(); return this; }
B addProjection(String projection, String... others) { this.projection.add(projection); Collections.addAll(this.projection, others); return self(); }
@Override public B setLimit(Integer limit) { Preconditions.checkArgument(limit == null || limit > 0, "limit must be positive"); this.limit = limit; return self(); }