-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as spam.
Sorry, something went wrong.