-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #585 from ajkannan/fix-query-to-builder
Fix query toBuilder()
- Loading branch information
Showing
6 changed files
with
483 additions
and
144 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/EntityQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
* | ||
* @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); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/KeyQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/ProjectionEntityQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.