Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix query toBuilder() #585

Merged
merged 2 commits into from
Jan 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.gcloud.datastore;

import com.google.api.services.datastore.DatastoreV1;

/**
* An implementation of a Google Cloud Datastore entity query that can be constructed by providing
* all the specific query elements.

This comment was marked as spam.

*
* @see <a href="https://cloud.google.com/appengine/docs/java/datastore/queries">Datastore
* queries</a>
*/
public final class EntityQuery extends StructuredQuery<Entity> {

private static final long serialVersionUID = 2990565454831019471L;

/**
* A {@code EntityQuery} builder for queries that return {@link Entity} results.
*/
public static final class Builder extends StructuredQuery.BuilderImpl<Entity, Builder> {

Builder(EntityQuery query) {
super(query);
}

Builder() {
super(ResultType.ENTITY);
}

@Override
Builder mergeFrom(DatastoreV1.Query queryPb) {
super.mergeFrom(queryPb);
clearProjection();
clearGroupBy();
return this;
}

@Override
public EntityQuery build() {
return new EntityQuery(this);
}
}

EntityQuery(Builder builder) {
super(builder);
}

@Override
public Builder toBuilder() {
return new Builder(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.gcloud.datastore;

import com.google.api.services.datastore.DatastoreV1;

/**
* An implementation of a Google Cloud Datastore key-only query that can be constructed by providing
* all the specific query elements.
*
* @see <a href="https://cloud.google.com/appengine/docs/java/datastore/queries">Datastore
* queries</a>
*/
public final class KeyQuery extends StructuredQuery<Key> {

private static final long serialVersionUID = -746768461459070045L;

/**
* A {@code KeyQuery} builder for queries that return {@link Key} results.
*/
public static final class Builder extends StructuredQuery.BuilderImpl<Key, Builder> {

Builder(KeyQuery query) {
super(query);
}

Builder() {
super(ResultType.KEY);
projection(Projection.property(KEY_PROPERTY_NAME));
}

@Override
Builder mergeFrom(DatastoreV1.Query queryPb) {
super.mergeFrom(queryPb);
projection(Projection.property(KEY_PROPERTY_NAME));
clearGroupBy();
return this;
}

@Override
public KeyQuery build() {
return new KeyQuery(this);
}
}

KeyQuery(Builder builder) {
super(builder);
}

@Override
public Builder toBuilder() {
return new Builder(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.gcloud.datastore;

/**
* An implementation of a Google Cloud Datastore projection entity query that can be constructed by
* providing all the specific query elements.
*
* @see <a href="https://cloud.google.com/appengine/docs/java/datastore/queries">Datastore
* queries</a>
*/
public final class ProjectionEntityQuery extends StructuredQuery<ProjectionEntity> {

private static final long serialVersionUID = 5488451194542425391L;

/**
* A {@code ProjectionEntityQuery} builder for queries that return {@link ProjectionEntity}
* results.
*/
public static final class Builder extends StructuredQuery.BuilderImpl<ProjectionEntity, Builder> {

Builder(ProjectionEntityQuery query) {
super(query);
}

Builder() {
super(ResultType.PROJECTION_ENTITY);
}

/**
* Clears the projection clause.
*/
@Override
public Builder clearProjection() {
super.clearProjection();
return this;
}

/**
* Sets the query's projection clause (clearing any previously specified Projection settings).
*/
@Override
public Builder projection(Projection projection, Projection... others) {
super.projection(projection, others);
return this;
}

/**
* Adds one or more projections to the existing projection clause.
*/
@Override
public Builder addProjection(Projection projection, Projection... others) {
super.addProjection(projection, others);
return this;
}

/**
* Clears the group by clause.
*/
@Override
public Builder clearGroupBy() {
super.clearGroupBy();
return this;
}

/**
* Sets the query's group by clause (clearing any previously specified GroupBy settings).
*/
@Override
public Builder groupBy(String property, String... others) {
super.groupBy(property, others);
return this;
}

/**
* Adds one or more properties to the existing group by clause.
*/
@Override
public Builder addGroupBy(String property, String... others) {
super.addGroupBy(property, others);
return this;
}

@Override
public ProjectionEntityQuery build() {
return new ProjectionEntityQuery(this);
}
}

ProjectionEntityQuery(Builder builder) {
super(builder);
}

@Override
public Builder toBuilder() {
return new Builder(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.collect.Maps;
import com.google.gcloud.datastore.StructuredQuery.EntityQueryBuilder;
import com.google.gcloud.datastore.StructuredQuery.KeyQueryBuilder;
import com.google.gcloud.datastore.StructuredQuery.ProjectionEntityQueryBuilder;
import com.google.protobuf.GeneratedMessage;
import com.google.protobuf.InvalidProtocolBufferException;

Expand Down Expand Up @@ -217,21 +214,21 @@ public static <V> GqlQuery.Builder<V> gqlQueryBuilder(ResultType<V> resultType,
/**
* Returns a new {@link StructuredQuery} builder for full (complete entities) queries.
*/
public static EntityQueryBuilder entityQueryBuilder() {
return new EntityQueryBuilder();
public static EntityQuery.Builder entityQueryBuilder() {
return new EntityQuery.Builder();
}

/**
* Returns a new {@link StructuredQuery} builder for key only queries.
*/
public static KeyQueryBuilder keyQueryBuilder() {
return new KeyQueryBuilder();
public static KeyQuery.Builder keyQueryBuilder() {
return new KeyQuery.Builder();
}

/**
* Returns a new {@link StructuredQuery} builder for projection queries.
*/
public static ProjectionEntityQueryBuilder projectionEntityQueryBuilder() {
return new ProjectionEntityQueryBuilder();
public static ProjectionEntityQuery.Builder projectionEntityQueryBuilder() {
return new ProjectionEntityQuery.Builder();
}
}
Loading