Skip to content

Commit 4eebd70

Browse files
author
Ajay Kannan
committed
fix toBuilder()
1 parent c5bae84 commit 4eebd70

File tree

6 files changed

+464
-143
lines changed

6 files changed

+464
-143
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright 2015 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.gcloud.datastore;
18+
19+
import com.google.api.services.datastore.DatastoreV1;
20+
21+
/**
22+
* An implementation of a Google Cloud Datastore entity query that can be constructed by providing
23+
* all the specific query elements.
24+
*
25+
* @see <a href="https://cloud.google.com/appengine/docs/java/datastore/queries">Datastore
26+
* queries</a>
27+
*/
28+
public final class EntityQuery extends StructuredQuery<Entity> {
29+
30+
private static final long serialVersionUID = 2990565454831019471L;
31+
32+
/**
33+
* A {@code EntityQuery} builder for queries that return Entity results.
34+
*/
35+
public static final class Builder extends StructuredQuery.BuilderImpl<Entity, Builder> {
36+
37+
Builder(EntityQuery query) {
38+
super(query);
39+
}
40+
41+
Builder() {
42+
super(ResultType.ENTITY);
43+
}
44+
45+
@Override
46+
Builder mergeFrom(DatastoreV1.Query queryPb) {
47+
super.mergeFrom(queryPb);
48+
clearProjection();
49+
clearGroupBy();
50+
return this;
51+
}
52+
53+
@Override
54+
public EntityQuery build() {
55+
return new EntityQuery(this);
56+
}
57+
}
58+
59+
EntityQuery(Builder builder) {
60+
super(builder);
61+
}
62+
63+
@Override
64+
public Builder toBuilder() {
65+
return new Builder(this);
66+
}
67+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2015 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.gcloud.datastore;
18+
19+
import com.google.api.services.datastore.DatastoreV1;
20+
21+
/**
22+
* An implementation of a Google Cloud Datastore key-only query that can be constructed by providing
23+
* all the specific query elements.
24+
*
25+
* @see <a href="https://cloud.google.com/appengine/docs/java/datastore/queries">Datastore
26+
* queries</a>
27+
*/
28+
public final class KeyQuery extends StructuredQuery<Key> {
29+
30+
private static final long serialVersionUID = -746768461459070045L;
31+
32+
/**
33+
* A {@code KeyQuery} builder for queries that return Key results.
34+
*/
35+
public static final class Builder extends StructuredQuery.BuilderImpl<Key, Builder> {
36+
37+
Builder(KeyQuery query) {
38+
super(query);
39+
}
40+
41+
Builder() {
42+
super(ResultType.KEY);
43+
projection(Projection.property(KEY_PROPERTY_NAME));
44+
}
45+
46+
@Override
47+
Builder mergeFrom(DatastoreV1.Query queryPb) {
48+
super.mergeFrom(queryPb);
49+
projection(Projection.property(KEY_PROPERTY_NAME));
50+
clearGroupBy();
51+
return this;
52+
}
53+
54+
@Override
55+
public KeyQuery build() {
56+
return new KeyQuery(this);
57+
}
58+
}
59+
60+
KeyQuery(Builder builder) {
61+
super(builder);
62+
}
63+
64+
@Override
65+
public Builder toBuilder() {
66+
return new Builder(this);
67+
}
68+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright 2015 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.gcloud.datastore;
18+
19+
/**
20+
* An implementation of a Google Cloud Datastore projection entity query that can be constructed by
21+
* providing all the specific query elements.
22+
*
23+
* @see <a href="https://cloud.google.com/appengine/docs/java/datastore/queries">Datastore
24+
* queries</a>
25+
*/
26+
public final class ProjectionEntityQuery extends StructuredQuery<ProjectionEntity> {
27+
28+
private static final long serialVersionUID = 5488451194542425391L;
29+
30+
/**
31+
* A {@code ProjectionEntityQuery} builder for queries that return Key results.
32+
*/
33+
public static final class Builder extends StructuredQuery.BuilderImpl<ProjectionEntity, Builder> {
34+
35+
Builder(ProjectionEntityQuery query) {
36+
super(query);
37+
}
38+
39+
Builder() {
40+
super(ResultType.PROJECTION_ENTITY);
41+
}
42+
43+
/**
44+
* Clears the projection clause.
45+
*/
46+
public Builder clearProjection() {
47+
super.clearProjection();
48+
return this;
49+
}
50+
51+
/**
52+
* Sets the query's projection clause (clearing any previously specified Projection settings).
53+
*/
54+
public Builder projection(Projection projection, Projection... others) {
55+
super.projection(projection, others);
56+
return this;
57+
}
58+
59+
/**
60+
* Adds one or more projections to the existing projection clause.
61+
*/
62+
public Builder addProjection(Projection projection, Projection... others) {
63+
super.addProjection(projection, others);
64+
return this;
65+
}
66+
67+
/**
68+
* Clears the group by clause.
69+
*/
70+
public Builder clearGroupBy() {
71+
super.clearGroupBy();
72+
return this;
73+
}
74+
75+
/**
76+
* Sets the query's group by clause (clearing any previously specified GroupBy settings).
77+
*/
78+
public Builder groupBy(String property, String... others) {
79+
super.groupBy(property, others);
80+
return this;
81+
}
82+
83+
/**
84+
* Adds one or more properties to the existing group by clause.
85+
*/
86+
public Builder addGroupBy(String property, String... others) {
87+
super.addGroupBy(property, others);
88+
return this;
89+
}
90+
91+
@Override
92+
public ProjectionEntityQuery build() {
93+
return new ProjectionEntityQuery(this);
94+
}
95+
}
96+
97+
ProjectionEntityQuery(Builder builder) {
98+
super(builder);
99+
}
100+
101+
@Override
102+
public Builder toBuilder() {
103+
return new Builder(this);
104+
}
105+
}

gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Query.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
import com.google.common.base.MoreObjects;
2323
import com.google.common.base.MoreObjects.ToStringHelper;
2424
import com.google.common.collect.Maps;
25-
import com.google.gcloud.datastore.StructuredQuery.EntityQueryBuilder;
26-
import com.google.gcloud.datastore.StructuredQuery.KeyQueryBuilder;
27-
import com.google.gcloud.datastore.StructuredQuery.ProjectionEntityQueryBuilder;
2825
import com.google.protobuf.GeneratedMessage;
2926
import com.google.protobuf.InvalidProtocolBufferException;
3027

@@ -217,21 +214,21 @@ public static <V> GqlQuery.Builder<V> gqlQueryBuilder(ResultType<V> resultType,
217214
/**
218215
* Returns a new {@link StructuredQuery} builder for full (complete entities) queries.
219216
*/
220-
public static EntityQueryBuilder entityQueryBuilder() {
221-
return new EntityQueryBuilder();
217+
public static EntityQuery.Builder entityQueryBuilder() {
218+
return new EntityQuery.Builder();
222219
}
223220

224221
/**
225222
* Returns a new {@link StructuredQuery} builder for key only queries.
226223
*/
227-
public static KeyQueryBuilder keyQueryBuilder() {
228-
return new KeyQueryBuilder();
224+
public static KeyQuery.Builder keyQueryBuilder() {
225+
return new KeyQuery.Builder();
229226
}
230227

231228
/**
232229
* Returns a new {@link StructuredQuery} builder for projection queries.
233230
*/
234-
public static ProjectionEntityQueryBuilder projectionEntityQueryBuilder() {
235-
return new ProjectionEntityQueryBuilder();
231+
public static ProjectionEntityQuery.Builder projectionEntityQueryBuilder() {
232+
return new ProjectionEntityQuery.Builder();
236233
}
237234
}

0 commit comments

Comments
 (0)